OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/csp_validator.h" | 5 #include "chrome/common/extensions/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 69 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
70 "default-src 'self' http:")); | 70 "default-src 'self' http:")); |
71 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 71 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
72 "default-src 'self' https://*")); | 72 "default-src 'self' https://*")); |
73 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 73 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
74 "default-src 'self' *")); | 74 "default-src 'self' *")); |
75 EXPECT_FALSE(ContentSecurityPolicyIsSecure( | 75 EXPECT_FALSE(ContentSecurityPolicyIsSecure( |
76 "default-src 'self' google.com")); | 76 "default-src 'self' google.com")); |
77 EXPECT_TRUE(ContentSecurityPolicyIsSecure( | 77 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
78 "default-src 'self' https://*.google.com")); | 78 "default-src 'self' https://*.google.com")); |
| 79 |
| 80 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 81 "default-src 'self' http://127.0.0.1")); |
| 82 EXPECT_TRUE(ContentSecurityPolicyIsSecure( |
| 83 "default-src 'self' http://localhost")); |
79 } | 84 } |
80 | 85 |
81 TEST(ExtensionCSPValidator, IsSandboxed) { | 86 TEST(ExtensionCSPValidator, IsSandboxed) { |
82 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("", Extension::TYPE_EXTENSION)); | 87 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed("", Extension::TYPE_EXTENSION)); |
83 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( | 88 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( |
84 "img-src https://google.com", Extension::TYPE_EXTENSION)); | 89 "img-src https://google.com", Extension::TYPE_EXTENSION)); |
85 | 90 |
86 // Sandbox directive is required. | 91 // Sandbox directive is required. |
87 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 92 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
88 "sandbox", Extension::TYPE_EXTENSION)); | 93 "sandbox", Extension::TYPE_EXTENSION)); |
(...skipping 12 matching lines...) Expand all Loading... |
101 // Extensions allow navigation and popups, platform apps don't. | 106 // Extensions allow navigation and popups, platform apps don't. |
102 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 107 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
103 "sandbox allow-top-navigation", Extension::TYPE_EXTENSION)); | 108 "sandbox allow-top-navigation", Extension::TYPE_EXTENSION)); |
104 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( | 109 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( |
105 "sandbox allow-top-navigation", Extension::TYPE_PLATFORM_APP)); | 110 "sandbox allow-top-navigation", Extension::TYPE_PLATFORM_APP)); |
106 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( | 111 EXPECT_TRUE(ContentSecurityPolicyIsSandboxed( |
107 "sandbox allow-popups", Extension::TYPE_EXTENSION)); | 112 "sandbox allow-popups", Extension::TYPE_EXTENSION)); |
108 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( | 113 EXPECT_FALSE(ContentSecurityPolicyIsSandboxed( |
109 "sandbox allow-popups", Extension::TYPE_PLATFORM_APP)); | 114 "sandbox allow-popups", Extension::TYPE_PLATFORM_APP)); |
110 } | 115 } |
OLD | NEW |