OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/weborigin/SecurityOrigin.h" | 31 #include "platform/weborigin/SecurityOrigin.h" |
32 | 32 |
33 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
34 #include "platform/blob/BlobURL.h" | 34 #include "platform/blob/BlobURL.h" |
35 #include "platform/weborigin/KURL.h" | 35 #include "platform/weborigin/KURL.h" |
| 36 #include "platform/weborigin/SchemeRegistry.h" |
36 #include "platform/weborigin/SecurityPolicy.h" | 37 #include "platform/weborigin/SecurityPolicy.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
38 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
39 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 const int MaxAllowedPort = 65535; | 44 const int MaxAllowedPort = 65535; |
44 | 45 |
45 class SecurityOriginTest : public ::testing::Test { }; | 46 class SecurityOriginTest : public ::testing::Test { }; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 for (size_t i = 0; i < WTF_ARRAY_LENGTH(inputs); ++i) { | 157 for (size_t i = 0; i < WTF_ARRAY_LENGTH(inputs); ++i) { |
157 SCOPED_TRACE(i); | 158 SCOPED_TRACE(i); |
158 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(inputs[
i].url); | 159 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(inputs[
i].url); |
159 String errorMessage; | 160 String errorMessage; |
160 EXPECT_EQ(inputs[i].accessGranted, origin->isPotentiallyTrustworthy()); | 161 EXPECT_EQ(inputs[i].accessGranted, origin->isPotentiallyTrustworthy()); |
161 } | 162 } |
162 | 163 |
163 // Unique origins are not considered secure. | 164 // Unique origins are not considered secure. |
164 RefPtr<SecurityOrigin> uniqueOrigin = SecurityOrigin::createUnique(); | 165 RefPtr<SecurityOrigin> uniqueOrigin = SecurityOrigin::createUnique(); |
165 EXPECT_FALSE(uniqueOrigin->isPotentiallyTrustworthy()); | 166 EXPECT_FALSE(uniqueOrigin->isPotentiallyTrustworthy()); |
| 167 |
| 168 // ... unless they are specially marked as such. |
| 169 uniqueOrigin->setIsPotentiallyTrustworthySandboxedOrigin(); |
| 170 EXPECT_TRUE(uniqueOrigin->isPotentiallyTrustworthy()); |
| 171 } |
| 172 |
| 173 TEST_F(SecurityOriginTest, BypassSecureContextCheck) |
| 174 { |
| 175 RefPtr<SecurityOrigin> origin1 = SecurityOrigin::createFromString("http://ww
w.example.test"); |
| 176 EXPECT_FALSE(origin1->bypassSecureContextCheck()); |
| 177 SchemeRegistry::registerURLSchemeBypassingSecureContextCheck("special-scheme
"); |
| 178 RefPtr<SecurityOrigin> origin2 = SecurityOrigin::createFromString("special-s
cheme://example.test"); |
| 179 EXPECT_TRUE(origin2->bypassSecureContextCheck()); |
| 180 |
| 181 RefPtr<SecurityOrigin> uniqueOrigin1 = SecurityOrigin::createUnique(); |
| 182 EXPECT_FALSE(uniqueOrigin1->bypassSecureContextCheck()); |
| 183 RefPtr<SecurityOrigin> uniqueOrigin2 = SecurityOrigin::createUnique(true /*
potentially trustworthy */, true /* bypass secure context check */); |
| 184 EXPECT_TRUE(uniqueOrigin2->bypassSecureContextCheck()); |
166 } | 185 } |
167 | 186 |
168 TEST_F(SecurityOriginTest, IsSecure) | 187 TEST_F(SecurityOriginTest, IsSecure) |
169 { | 188 { |
170 struct TestCase { | 189 struct TestCase { |
171 bool isSecure; | 190 bool isSecure; |
172 const char* url; | 191 const char* url; |
173 } inputs[] = { | 192 } inputs[] = { |
174 { false, "blob:ftp://evil:99/578223a1-8c13-17b3-84d5-eca045ae384a" }, | 193 { false, "blob:ftp://evil:99/578223a1-8c13-17b3-84d5-eca045ae384a" }, |
175 { false, "blob:http://example.com/578223a1-8c13-17b3-84d5-eca045ae384a"
}, | 194 { false, "blob:http://example.com/578223a1-8c13-17b3-84d5-eca045ae384a"
}, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 427 |
409 KURL blobUrl = BlobURL::createPublicURL(origin.get()); | 428 KURL blobUrl = BlobURL::createPublicURL(origin.get()); |
410 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl); | 429 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl); |
411 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique()); | 430 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique()); |
412 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString()); | 431 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString()); |
413 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString()); | 432 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString()); |
414 } | 433 } |
415 } | 434 } |
416 | 435 |
417 } // namespace blink | 436 } // namespace blink |
OLD | NEW |