| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/common/csp_validator.h" | 5 #include "extensions/common/csp_validator.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 using extensions::csp_validator::ContentSecurityPolicyIsLegal; | 8 using extensions::csp_validator::ContentSecurityPolicyIsLegal; |
| 9 using extensions::csp_validator::ContentSecurityPolicyIsSecure; | 9 using extensions::csp_validator::ContentSecurityPolicyIsSecure; |
| 10 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed; | 10 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 "default-src 'self' google.com", Manifest::TYPE_EXTENSION)); | 91 "default-src 'self' google.com", Manifest::TYPE_EXTENSION)); |
| 92 | 92 |
| 93 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 93 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 94 "default-src 'self' *", Manifest::TYPE_EXTENSION)); | 94 "default-src 'self' *", Manifest::TYPE_EXTENSION)); |
| 95 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 95 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 96 "default-src 'self' *:*", Manifest::TYPE_EXTENSION)); | 96 "default-src 'self' *:*", Manifest::TYPE_EXTENSION)); |
| 97 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 97 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 98 "default-src 'self' *:*/", Manifest::TYPE_EXTENSION)); | 98 "default-src 'self' *:*/", Manifest::TYPE_EXTENSION)); |
| 99 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 99 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 100 "default-src 'self' *:*/path", Manifest::TYPE_EXTENSION)); | 100 "default-src 'self' *:*/path", Manifest::TYPE_EXTENSION)); |
| 101 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 101 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 102 "default-src 'self' https://", Manifest::TYPE_EXTENSION)); | 102 "default-src 'self' https://", Manifest::TYPE_EXTENSION)); |
| 103 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 103 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 104 "default-src 'self' https://*:*", Manifest::TYPE_EXTENSION)); | 104 "default-src 'self' https://*:*", Manifest::TYPE_EXTENSION)); |
| 105 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 105 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 106 "default-src 'self' https://*:*/", Manifest::TYPE_EXTENSION)); | 106 "default-src 'self' https://*:*/", Manifest::TYPE_EXTENSION)); |
| 107 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 107 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 108 "default-src 'self' https://*:*/path", Manifest::TYPE_EXTENSION)); | 108 "default-src 'self' https://*:*/path", Manifest::TYPE_EXTENSION)); |
| 109 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 109 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 110 "default-src 'self' https://*.com", Manifest::TYPE_EXTENSION)); | 110 "default-src 'self' https://*.com", Manifest::TYPE_EXTENSION)); |
| 111 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 111 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 160 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 161 "default-src 'self' filesystem:", Manifest::TYPE_EXTENSION)); | 161 "default-src 'self' filesystem:", Manifest::TYPE_EXTENSION)); |
| 162 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 162 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 163 "default-src 'self' filesystem:http://example.com/XXX", | 163 "default-src 'self' filesystem:http://example.com/XXX", |
| 164 Manifest::TYPE_EXTENSION)); | 164 Manifest::TYPE_EXTENSION)); |
| 165 | 165 |
| 166 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 166 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 167 "default-src 'self' https://*.googleapis.com", Manifest::TYPE_EXTENSION)); | 167 "default-src 'self' https://*.googleapis.com", Manifest::TYPE_EXTENSION)); |
| 168 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 168 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 169 "default-src 'self' https://x.googleapis.com", Manifest::TYPE_EXTENSION)); | 169 "default-src 'self' https://x.googleapis.com", Manifest::TYPE_EXTENSION)); |
| 170 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | |
| 171 "default-src 'self' chrome-extension://", Manifest::TYPE_EXTENSION)); | |
| 172 } | 170 } |
| 173 | 171 |
| 174 TEST(ExtensionCSPValidator, IsSandboxed) { | 172 TEST(ExtensionCSPValidator, IsSandboxed) { |
| 175 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed(std::string(), | 173 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed(std::string(), |
| 176 Manifest::TYPE_EXTENSION)); | 174 Manifest::TYPE_EXTENSION)); |
| 177 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("img-src https://google.com", | 175 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("img-src https://google.com", |
| 178 Manifest::TYPE_EXTENSION)); | 176 Manifest::TYPE_EXTENSION)); |
| 179 | 177 |
| 180 // Sandbox directive is required. | 178 // Sandbox directive is required. |
| 181 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 179 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 197 "sandbox allow-top-navigation", Manifest::TYPE_EXTENSION)); | 195 "sandbox allow-top-navigation", Manifest::TYPE_EXTENSION)); |
| 198 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( | 196 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( |
| 199 "sandbox allow-top-navigation", Manifest::TYPE_PLATFORM_APP)); | 197 "sandbox allow-top-navigation", Manifest::TYPE_PLATFORM_APP)); |
| 200 | 198 |
| 201 // Popups are OK. | 199 // Popups are OK. |
| 202 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 200 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| 203 "sandbox allow-popups", Manifest::TYPE_EXTENSION)); | 201 "sandbox allow-popups", Manifest::TYPE_EXTENSION)); |
| 204 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 202 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| 205 "sandbox allow-popups", Manifest::TYPE_PLATFORM_APP)); | 203 "sandbox allow-popups", Manifest::TYPE_PLATFORM_APP)); |
| 206 } | 204 } |
| OLD | NEW |