| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 155 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 156 "default-src 'self' blob:", Manifest::TYPE_EXTENSION)); | 156 "default-src 'self' blob:", Manifest::TYPE_EXTENSION)); |
| 157 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 157 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
| 158 "default-src 'self' blob:http://example.com/XXX", | 158 "default-src 'self' blob:http://example.com/XXX", |
| 159 Manifest::TYPE_EXTENSION)); | 159 Manifest::TYPE_EXTENSION)); |
| 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 |
| 166 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 167 "default-src 'self' https://*.googleapis.com", Manifest::TYPE_EXTENSION)); |
| 168 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 169 "default-src 'self' https://x.googleapis.com", Manifest::TYPE_EXTENSION)); |
| 165 } | 170 } |
| 166 | 171 |
| 167 TEST(ExtensionCSPValidator, IsSandboxed) { | 172 TEST(ExtensionCSPValidator, IsSandboxed) { |
| 168 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed(std::string(), | 173 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed(std::string(), |
| 169 Manifest::TYPE_EXTENSION)); | 174 Manifest::TYPE_EXTENSION)); |
| 170 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("img-src https://google.com", | 175 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("img-src https://google.com", |
| 171 Manifest::TYPE_EXTENSION)); | 176 Manifest::TYPE_EXTENSION)); |
| 172 | 177 |
| 173 // Sandbox directive is required. | 178 // Sandbox directive is required. |
| 174 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 179 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 190 "sandbox allow-top-navigation", Manifest::TYPE_EXTENSION)); | 195 "sandbox allow-top-navigation", Manifest::TYPE_EXTENSION)); |
| 191 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( | 196 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( |
| 192 "sandbox allow-top-navigation", Manifest::TYPE_PLATFORM_APP)); | 197 "sandbox allow-top-navigation", Manifest::TYPE_PLATFORM_APP)); |
| 193 | 198 |
| 194 // Popups are OK. | 199 // Popups are OK. |
| 195 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 200 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| 196 "sandbox allow-popups", Manifest::TYPE_EXTENSION)); | 201 "sandbox allow-popups", Manifest::TYPE_EXTENSION)); |
| 197 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 202 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
| 198 "sandbox allow-popups", Manifest::TYPE_PLATFORM_APP)); | 203 "sandbox allow-popups", Manifest::TYPE_PLATFORM_APP)); |
| 199 } | 204 } |
| OLD | NEW |