| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 "config.h" | 31 #include "config.h" |
| 32 #include "platform/weborigin/SecurityOrigin.h" | |
| 33 #include "platform/weborigin/SecurityPolicy.h" | 32 #include "platform/weborigin/SecurityPolicy.h" |
| 34 | 33 |
| 35 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
| 35 #include "platform/weborigin/SecurityOrigin.h" |
| 36 #include <gtest/gtest.h> | 36 #include <gtest/gtest.h> |
| 37 | 37 |
| 38 using blink::KURL; | 38 namespace blink { |
| 39 using blink::SecurityOrigin; | |
| 40 using blink::SecurityPolicy; | |
| 41 | |
| 42 namespace { | |
| 43 | 39 |
| 44 TEST(SecurityPolicyTest, ReferrerIsAlwaysAWebURL) | 40 TEST(SecurityPolicyTest, ReferrerIsAlwaysAWebURL) |
| 45 { | 41 { |
| 46 EXPECT_TRUE(String() == SecurityPolicy::generateReferrer(blink::ReferrerPoli
cyAlways, KURL(blink::ParsedURLString, "http://example.com/"), String::fromUTF8(
"chrome://somepage/")).referrer); | 42 EXPECT_TRUE(String() == SecurityPolicy::generateReferrer(ReferrerPolicyAlway
s, KURL(ParsedURLString, "http://example.com/"), String::fromUTF8("chrome://some
page/")).referrer); |
| 47 } | 43 } |
| 48 | 44 |
| 49 TEST(SecurityPolicyTest, GenerateReferrer) | 45 TEST(SecurityPolicyTest, GenerateReferrer) |
| 50 { | 46 { |
| 51 struct TestCase { | 47 struct TestCase { |
| 52 blink::ReferrerPolicy policy; | 48 ReferrerPolicy policy; |
| 53 const char* referrer; | 49 const char* referrer; |
| 54 const char* destination; | 50 const char* destination; |
| 55 const char* expected; | 51 const char* expected; |
| 56 }; | 52 }; |
| 57 | 53 |
| 58 const char insecureURLA[] = "http://a.test/path/to/file.html"; | 54 const char insecureURLA[] = "http://a.test/path/to/file.html"; |
| 59 const char insecureURLB[] = "http://b.test/path/to/file.html"; | 55 const char insecureURLB[] = "http://b.test/path/to/file.html"; |
| 60 const char insecureOriginA[] = "http://a.test/"; | 56 const char insecureOriginA[] = "http://a.test/"; |
| 61 | 57 |
| 62 const char secureURLA[] = "https://a.test/path/to/file.html"; | 58 const char secureURLA[] = "https://a.test/path/to/file.html"; |
| 63 const char secureURLB[] = "https://b.test/path/to/file.html"; | 59 const char secureURLB[] = "https://b.test/path/to/file.html"; |
| 64 const char secureOriginA[] = "https://a.test/"; | 60 const char secureOriginA[] = "https://a.test/"; |
| 65 | 61 |
| 66 const char blobURL[] = "blob:http%3A//a.test/b3aae9c8-7f90-440d-8d7c-43aa20d
72fde"; | 62 const char blobURL[] = "blob:http%3A//a.test/b3aae9c8-7f90-440d-8d7c-43aa20d
72fde"; |
| 67 const char filesystemURL[] = "filesystem:http%3A//a.test/path/t/file.html"; | 63 const char filesystemURL[] = "filesystem:http%3A//a.test/path/t/file.html"; |
| 68 | 64 |
| 69 TestCase inputs[] = { | 65 TestCase inputs[] = { |
| 70 // HTTP -> HTTP: Same Origin | 66 // HTTP -> HTTP: Same Origin |
| 71 { blink::ReferrerPolicyAlways, insecureURLA, insecureURLA, insecureURLA
}, | 67 { ReferrerPolicyAlways, insecureURLA, insecureURLA, insecureURLA }, |
| 72 { blink::ReferrerPolicyDefault, insecureURLA, insecureURLA, insecureURLA
}, | 68 { ReferrerPolicyDefault, insecureURLA, insecureURLA, insecureURLA }, |
| 73 { blink::ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, insecureUR
LA, insecureURLA }, | 69 { ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, insecureURLA, ins
ecureURLA }, |
| 74 { blink::ReferrerPolicyNever, insecureURLA, insecureURLA, 0 }, | 70 { ReferrerPolicyNever, insecureURLA, insecureURLA, 0 }, |
| 75 { blink::ReferrerPolicyOrigin, insecureURLA, insecureURLA, insecureOrigi
nA }, | 71 { ReferrerPolicyOrigin, insecureURLA, insecureURLA, insecureOriginA }, |
| 76 { blink::ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, insecureURLA
, insecureURLA }, | 72 { ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, insecureURLA, insec
ureURLA }, |
| 77 | 73 |
| 78 // HTTP -> HTTP: Cross Origin | 74 // HTTP -> HTTP: Cross Origin |
| 79 { blink::ReferrerPolicyAlways, insecureURLA, insecureURLB, insecureURLA
}, | 75 { ReferrerPolicyAlways, insecureURLA, insecureURLB, insecureURLA }, |
| 80 { blink::ReferrerPolicyDefault, insecureURLA, insecureURLB, insecureURLA
}, | 76 { ReferrerPolicyDefault, insecureURLA, insecureURLB, insecureURLA }, |
| 81 { blink::ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, insecureUR
LB, insecureURLA }, | 77 { ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, insecureURLB, ins
ecureURLA }, |
| 82 { blink::ReferrerPolicyNever, insecureURLA, insecureURLB, 0 }, | 78 { ReferrerPolicyNever, insecureURLA, insecureURLB, 0 }, |
| 83 { blink::ReferrerPolicyOrigin, insecureURLA, insecureURLB, insecureOrigi
nA }, | 79 { ReferrerPolicyOrigin, insecureURLA, insecureURLB, insecureOriginA }, |
| 84 { blink::ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, insecureURLB
, insecureOriginA }, | 80 { ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, insecureURLB, insec
ureOriginA }, |
| 85 | 81 |
| 86 // HTTPS -> HTTPS: Same Origin | 82 // HTTPS -> HTTPS: Same Origin |
| 87 { blink::ReferrerPolicyAlways, secureURLA, secureURLA, secureURLA }, | 83 { ReferrerPolicyAlways, secureURLA, secureURLA, secureURLA }, |
| 88 { blink::ReferrerPolicyDefault, secureURLA, secureURLA, secureURLA }, | 84 { ReferrerPolicyDefault, secureURLA, secureURLA, secureURLA }, |
| 89 { blink::ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, secureURLA,
secureURLA }, | 85 { ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, secureURLA, secureU
RLA }, |
| 90 { blink::ReferrerPolicyNever, secureURLA, secureURLA, 0 }, | 86 { ReferrerPolicyNever, secureURLA, secureURLA, 0 }, |
| 91 { blink::ReferrerPolicyOrigin, secureURLA, secureURLA, secureOriginA }, | 87 { ReferrerPolicyOrigin, secureURLA, secureURLA, secureOriginA }, |
| 92 { blink::ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLA, se
cureURLA }, | 88 { ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLA, secureURL
A }, |
| 93 | 89 |
| 94 // HTTPS -> HTTPS: Cross Origin | 90 // HTTPS -> HTTPS: Cross Origin |
| 95 { blink::ReferrerPolicyAlways, secureURLA, secureURLB, secureURLA }, | 91 { ReferrerPolicyAlways, secureURLA, secureURLB, secureURLA }, |
| 96 { blink::ReferrerPolicyDefault, secureURLA, secureURLB, secureURLA }, | 92 { ReferrerPolicyDefault, secureURLA, secureURLB, secureURLA }, |
| 97 { blink::ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, secureURLB,
secureURLA }, | 93 { ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, secureURLB, secureU
RLA }, |
| 98 { blink::ReferrerPolicyNever, secureURLA, secureURLB, 0 }, | 94 { ReferrerPolicyNever, secureURLA, secureURLB, 0 }, |
| 99 { blink::ReferrerPolicyOrigin, secureURLA, secureURLB, secureOriginA }, | 95 { ReferrerPolicyOrigin, secureURLA, secureURLB, secureOriginA }, |
| 100 { blink::ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLB, se
cureOriginA }, | 96 { ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLB, secureOri
ginA }, |
| 101 | 97 |
| 102 // HTTP -> HTTPS | 98 // HTTP -> HTTPS |
| 103 { blink::ReferrerPolicyAlways, insecureURLA, secureURLB, insecureURLA }, | 99 { ReferrerPolicyAlways, insecureURLA, secureURLB, insecureURLA }, |
| 104 { blink::ReferrerPolicyDefault, insecureURLA, secureURLB, insecureURLA }
, | 100 { ReferrerPolicyDefault, insecureURLA, secureURLB, insecureURLA }, |
| 105 { blink::ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, secureURLB
, insecureURLA }, | 101 { ReferrerPolicyNoReferrerWhenDowngrade, insecureURLA, secureURLB, insec
ureURLA }, |
| 106 { blink::ReferrerPolicyNever, insecureURLA, secureURLB, 0 }, | 102 { ReferrerPolicyNever, insecureURLA, secureURLB, 0 }, |
| 107 { blink::ReferrerPolicyOrigin, insecureURLA, secureURLB, insecureOriginA
}, | 103 { ReferrerPolicyOrigin, insecureURLA, secureURLB, insecureOriginA }, |
| 108 { blink::ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, secureURLB,
insecureOriginA }, | 104 { ReferrerPolicyOriginWhenCrossOrigin, insecureURLA, secureURLB, insecur
eOriginA }, |
| 109 | 105 |
| 110 // HTTPS -> HTTP | 106 // HTTPS -> HTTP |
| 111 { blink::ReferrerPolicyAlways, secureURLA, insecureURLB, secureURLA }, | 107 { ReferrerPolicyAlways, secureURLA, insecureURLB, secureURLA }, |
| 112 { blink::ReferrerPolicyDefault, secureURLA, insecureURLB, 0 }, | 108 { ReferrerPolicyDefault, secureURLA, insecureURLB, 0 }, |
| 113 { blink::ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, insecureURLB
, 0 }, | 109 { ReferrerPolicyNoReferrerWhenDowngrade, secureURLA, insecureURLB, 0 }, |
| 114 { blink::ReferrerPolicyNever, secureURLA, insecureURLB, 0 }, | 110 { ReferrerPolicyNever, secureURLA, insecureURLB, 0 }, |
| 115 { blink::ReferrerPolicyOrigin, secureURLA, insecureURLB, secureOriginA }
, | 111 { ReferrerPolicyOrigin, secureURLA, insecureURLB, secureOriginA }, |
| 116 { blink::ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLB, se
cureOriginA }, | 112 { ReferrerPolicyOriginWhenCrossOrigin, secureURLA, secureURLB, secureOri
ginA }, |
| 117 | 113 |
| 118 // blob and filesystem URL handling | 114 // blob and filesystem URL handling |
| 119 { blink::ReferrerPolicyAlways, insecureURLA, blobURL, 0 }, | 115 { ReferrerPolicyAlways, insecureURLA, blobURL, 0 }, |
| 120 { blink::ReferrerPolicyAlways, blobURL, insecureURLA, 0 }, | 116 { ReferrerPolicyAlways, blobURL, insecureURLA, 0 }, |
| 121 { blink::ReferrerPolicyAlways, insecureURLA, filesystemURL, 0 }, | 117 { ReferrerPolicyAlways, insecureURLA, filesystemURL, 0 }, |
| 122 { blink::ReferrerPolicyAlways, filesystemURL, insecureURLA, 0 }, | 118 { ReferrerPolicyAlways, filesystemURL, insecureURLA, 0 }, |
| 123 }; | 119 }; |
| 124 | 120 |
| 125 for (TestCase test : inputs) { | 121 for (TestCase test : inputs) { |
| 126 KURL destination(blink::ParsedURLString, test.destination); | 122 KURL destination(ParsedURLString, test.destination); |
| 127 blink::Referrer result = SecurityPolicy::generateReferrer(test.policy, d
estination, String::fromUTF8(test.referrer)); | 123 Referrer result = SecurityPolicy::generateReferrer(test.policy, destinat
ion, String::fromUTF8(test.referrer)); |
| 128 if (test.expected) { | 124 if (test.expected) { |
| 129 EXPECT_EQ(String::fromUTF8(test.expected), result.referrer) | 125 EXPECT_EQ(String::fromUTF8(test.expected), result.referrer) |
| 130 << "'" << test.referrer << "' to '" << test.destination | 126 << "'" << test.referrer << "' to '" << test.destination |
| 131 << "' should have been '" << test.expected << "': was '" | 127 << "' should have been '" << test.expected << "': was '" |
| 132 << result.referrer.utf8().data() << "'."; | 128 << result.referrer.utf8().data() << "'."; |
| 133 } else { | 129 } else { |
| 134 EXPECT_TRUE(result.referrer.isEmpty()) | 130 EXPECT_TRUE(result.referrer.isEmpty()) |
| 135 << "'" << test.referrer << "' to '" << test.destination | 131 << "'" << test.referrer << "' to '" << test.destination |
| 136 << "' should have been empty: was '" << result.referrer.utf8().d
ata() << "'."; | 132 << "' should have been empty: was '" << result.referrer.utf8().d
ata() << "'."; |
| 137 } | 133 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 RefPtr<SecurityOrigin> origin2 = SecurityOrigin::createFromString(test.a
notherUrlInOrigin); | 181 RefPtr<SecurityOrigin> origin2 = SecurityOrigin::createFromString(test.a
notherUrlInOrigin); |
| 186 | 182 |
| 187 EXPECT_FALSE(origin1->isPotentiallyTrustworthy(errorMessage)); | 183 EXPECT_FALSE(origin1->isPotentiallyTrustworthy(errorMessage)); |
| 188 EXPECT_FALSE(origin2->isPotentiallyTrustworthy(errorMessage)); | 184 EXPECT_FALSE(origin2->isPotentiallyTrustworthy(errorMessage)); |
| 189 SecurityPolicy::addOriginTrustworthyWhiteList(origin1); | 185 SecurityPolicy::addOriginTrustworthyWhiteList(origin1); |
| 190 EXPECT_TRUE(origin1->isPotentiallyTrustworthy(errorMessage)); | 186 EXPECT_TRUE(origin1->isPotentiallyTrustworthy(errorMessage)); |
| 191 EXPECT_TRUE(origin2->isPotentiallyTrustworthy(errorMessage)); | 187 EXPECT_TRUE(origin2->isPotentiallyTrustworthy(errorMessage)); |
| 192 } | 188 } |
| 193 } | 189 } |
| 194 | 190 |
| 195 } // namespace | 191 } // namespace blink |
| OLD | NEW |