| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 void setPublicSuffix(const blink::WebString& suffix) { | 62 void setPublicSuffix(const blink::WebString& suffix) { |
| 63 m_suffixList.setPublicSuffix(suffix); | 63 m_suffixList.setPublicSuffix(suffix); |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 OriginAccessEntryTestSuffixList m_suffixList; | 67 OriginAccessEntryTestSuffixList m_suffixList; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST(OriginAccessEntryTest, PublicSuffixListTest) { | 70 TEST(OriginAccessEntryTest, PublicSuffixListTest) { |
| 71 OriginAccessEntryTestPlatform platform; | 71 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 72 platform.setPublicSuffix("com"); | 72 platform->setPublicSuffix("com"); |
| 73 | 73 |
| 74 RefPtr<SecurityOrigin> origin = | 74 RefPtr<SecurityOrigin> origin = |
| 75 SecurityOrigin::createFromString("http://www.google.com"); | 75 SecurityOrigin::createFromString("http://www.google.com"); |
| 76 OriginAccessEntry entry1("http", "google.com", | 76 OriginAccessEntry entry1("http", "google.com", |
| 77 OriginAccessEntry::AllowSubdomains); | 77 OriginAccessEntry::AllowSubdomains); |
| 78 OriginAccessEntry entry2("http", "hamster.com", | 78 OriginAccessEntry entry2("http", "hamster.com", |
| 79 OriginAccessEntry::AllowSubdomains); | 79 OriginAccessEntry::AllowSubdomains); |
| 80 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains); | 80 OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains); |
| 81 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); | 81 EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); |
| 82 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, | 82 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 OriginAccessEntry::DoesNotMatchOrigin, | 128 OriginAccessEntry::DoesNotMatchOrigin, |
| 129 OriginAccessEntry::DoesNotMatchOrigin}, | 129 OriginAccessEntry::DoesNotMatchOrigin}, |
| 130 {"http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin, | 130 {"http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin, |
| 131 OriginAccessEntry::MatchesOrigin}, | 131 OriginAccessEntry::MatchesOrigin}, |
| 132 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin, | 132 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin, |
| 133 OriginAccessEntry::MatchesOrigin}, | 133 OriginAccessEntry::MatchesOrigin}, |
| 134 {"https", "", "http://beispiel.de/", | 134 {"https", "", "http://beispiel.de/", |
| 135 OriginAccessEntry::DoesNotMatchOrigin, OriginAccessEntry::MatchesOrigin}, | 135 OriginAccessEntry::DoesNotMatchOrigin, OriginAccessEntry::MatchesOrigin}, |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 OriginAccessEntryTestPlatform platform; | 138 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 139 platform.setPublicSuffix("com"); | 139 platform->setPublicSuffix("com"); |
| 140 | 140 |
| 141 for (const auto& test : inputs) { | 141 for (const auto& test : inputs) { |
| 142 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 142 SCOPED_TRACE(testing::Message() << "Host: " << test.host |
| 143 << ", Origin: " << test.origin); | 143 << ", Origin: " << test.origin); |
| 144 RefPtr<SecurityOrigin> originToTest = | 144 RefPtr<SecurityOrigin> originToTest = |
| 145 SecurityOrigin::createFromString(test.origin); | 145 SecurityOrigin::createFromString(test.origin); |
| 146 OriginAccessEntry entry1(test.protocol, test.host, | 146 OriginAccessEntry entry1(test.protocol, test.host, |
| 147 OriginAccessEntry::AllowSubdomains); | 147 OriginAccessEntry::AllowSubdomains); |
| 148 EXPECT_EQ(test.expectedOrigin, entry1.matchesOrigin(*originToTest)); | 148 EXPECT_EQ(test.expectedOrigin, entry1.matchesOrigin(*originToTest)); |
| 149 EXPECT_EQ(test.expectedDomain, entry1.matchesDomain(*originToTest)); | 149 EXPECT_EQ(test.expectedDomain, entry1.matchesDomain(*originToTest)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 {"https", "example.com", "http://www.www.example.com/", | 182 {"https", "example.com", "http://www.www.example.com/", |
| 183 OriginAccessEntry::DoesNotMatchOrigin}, | 183 OriginAccessEntry::DoesNotMatchOrigin}, |
| 184 {"http", "example.com", "http://beispiel.de/", | 184 {"http", "example.com", "http://beispiel.de/", |
| 185 OriginAccessEntry::DoesNotMatchOrigin}, | 185 OriginAccessEntry::DoesNotMatchOrigin}, |
| 186 {"http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin}, | 186 {"http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin}, |
| 187 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin}, | 187 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin}, |
| 188 {"https", "", "http://beispiel.de/", | 188 {"https", "", "http://beispiel.de/", |
| 189 OriginAccessEntry::DoesNotMatchOrigin}, | 189 OriginAccessEntry::DoesNotMatchOrigin}, |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 OriginAccessEntryTestPlatform platform; | 192 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 193 platform.setPublicSuffix("com"); | 193 platform->setPublicSuffix("com"); |
| 194 | 194 |
| 195 for (const auto& test : inputs) { | 195 for (const auto& test : inputs) { |
| 196 RefPtr<SecurityOrigin> originToTest = | 196 RefPtr<SecurityOrigin> originToTest = |
| 197 SecurityOrigin::createFromString(test.origin); | 197 SecurityOrigin::createFromString(test.origin); |
| 198 OriginAccessEntry entry1(test.protocol, test.host, | 198 OriginAccessEntry entry1(test.protocol, test.host, |
| 199 OriginAccessEntry::AllowRegisterableDomains); | 199 OriginAccessEntry::AllowRegisterableDomains); |
| 200 | 200 |
| 201 SCOPED_TRACE(testing::Message() | 201 SCOPED_TRACE(testing::Message() |
| 202 << "Host: " << test.host << ", Origin: " << test.origin | 202 << "Host: " << test.host << ", Origin: " << test.origin |
| 203 << ", Domain: " << entry1.registerable().utf8().data()); | 203 << ", Domain: " << entry1.registerable().utf8().data()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 OriginAccessEntry::DoesNotMatchOrigin}, | 238 OriginAccessEntry::DoesNotMatchOrigin}, |
| 239 {"http", "example.appspot.com", "http://beispiel.de/", | 239 {"http", "example.appspot.com", "http://beispiel.de/", |
| 240 OriginAccessEntry::DoesNotMatchOrigin}, | 240 OriginAccessEntry::DoesNotMatchOrigin}, |
| 241 {"http", "", "http://example.appspot.com/", | 241 {"http", "", "http://example.appspot.com/", |
| 242 OriginAccessEntry::MatchesOrigin}, | 242 OriginAccessEntry::MatchesOrigin}, |
| 243 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin}, | 243 {"http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin}, |
| 244 {"https", "", "http://beispiel.de/", | 244 {"https", "", "http://beispiel.de/", |
| 245 OriginAccessEntry::DoesNotMatchOrigin}, | 245 OriginAccessEntry::DoesNotMatchOrigin}, |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 OriginAccessEntryTestPlatform platform; | 248 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 249 platform.setPublicSuffix("appspot.com"); | 249 platform->setPublicSuffix("appspot.com"); |
| 250 | 250 |
| 251 for (const auto& test : inputs) { | 251 for (const auto& test : inputs) { |
| 252 RefPtr<SecurityOrigin> originToTest = | 252 RefPtr<SecurityOrigin> originToTest = |
| 253 SecurityOrigin::createFromString(test.origin); | 253 SecurityOrigin::createFromString(test.origin); |
| 254 OriginAccessEntry entry1(test.protocol, test.host, | 254 OriginAccessEntry entry1(test.protocol, test.host, |
| 255 OriginAccessEntry::AllowRegisterableDomains); | 255 OriginAccessEntry::AllowRegisterableDomains); |
| 256 | 256 |
| 257 SCOPED_TRACE(testing::Message() | 257 SCOPED_TRACE(testing::Message() |
| 258 << "Host: " << test.host << ", Origin: " << test.origin | 258 << "Host: " << test.host << ", Origin: " << test.origin |
| 259 << ", Domain: " << entry1.registerable().utf8().data()); | 259 << ", Domain: " << entry1.registerable().utf8().data()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 289 {"http", "example.com", "http://beispiel.de/", | 289 {"http", "example.com", "http://beispiel.de/", |
| 290 OriginAccessEntry::DoesNotMatchOrigin}, | 290 OriginAccessEntry::DoesNotMatchOrigin}, |
| 291 {"http", "", "http://example.com/", | 291 {"http", "", "http://example.com/", |
| 292 OriginAccessEntry::DoesNotMatchOrigin}, | 292 OriginAccessEntry::DoesNotMatchOrigin}, |
| 293 {"http", "", "http://beispiel.de/", | 293 {"http", "", "http://beispiel.de/", |
| 294 OriginAccessEntry::DoesNotMatchOrigin}, | 294 OriginAccessEntry::DoesNotMatchOrigin}, |
| 295 {"https", "", "http://beispiel.de/", | 295 {"https", "", "http://beispiel.de/", |
| 296 OriginAccessEntry::DoesNotMatchOrigin}, | 296 OriginAccessEntry::DoesNotMatchOrigin}, |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 OriginAccessEntryTestPlatform platform; | 299 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 300 platform.setPublicSuffix("com"); | 300 platform->setPublicSuffix("com"); |
| 301 | 301 |
| 302 for (const auto& test : inputs) { | 302 for (const auto& test : inputs) { |
| 303 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 303 SCOPED_TRACE(testing::Message() << "Host: " << test.host |
| 304 << ", Origin: " << test.origin); | 304 << ", Origin: " << test.origin); |
| 305 RefPtr<SecurityOrigin> originToTest = | 305 RefPtr<SecurityOrigin> originToTest = |
| 306 SecurityOrigin::createFromString(test.origin); | 306 SecurityOrigin::createFromString(test.origin); |
| 307 OriginAccessEntry entry1(test.protocol, test.host, | 307 OriginAccessEntry entry1(test.protocol, test.host, |
| 308 OriginAccessEntry::DisallowSubdomains); | 308 OriginAccessEntry::DisallowSubdomains); |
| 309 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 309 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 | 312 |
| 313 TEST(OriginAccessEntryTest, IPAddressTest) { | 313 TEST(OriginAccessEntryTest, IPAddressTest) { |
| 314 struct TestCase { | 314 struct TestCase { |
| 315 const char* protocol; | 315 const char* protocol; |
| 316 const char* host; | 316 const char* host; |
| 317 bool isIPAddress; | 317 bool isIPAddress; |
| 318 } inputs[] = { | 318 } inputs[] = { |
| 319 {"http", "1.1.1.1", true}, | 319 {"http", "1.1.1.1", true}, |
| 320 {"http", "1.1.1.1.1", false}, | 320 {"http", "1.1.1.1.1", false}, |
| 321 {"http", "example.com", false}, | 321 {"http", "example.com", false}, |
| 322 {"http", "hostname.that.ends.with.a.number1", false}, | 322 {"http", "hostname.that.ends.with.a.number1", false}, |
| 323 {"http", "2001:db8::1", false}, | 323 {"http", "2001:db8::1", false}, |
| 324 {"http", "[2001:db8::1]", true}, | 324 {"http", "[2001:db8::1]", true}, |
| 325 {"http", "2001:db8::a", false}, | 325 {"http", "2001:db8::a", false}, |
| 326 {"http", "[2001:db8::a]", true}, | 326 {"http", "[2001:db8::a]", true}, |
| 327 {"http", "", false}, | 327 {"http", "", false}, |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 OriginAccessEntryTestPlatform platform; | 330 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 331 platform.setPublicSuffix("com"); | 331 platform->setPublicSuffix("com"); |
| 332 | 332 |
| 333 for (const auto& test : inputs) { | 333 for (const auto& test : inputs) { |
| 334 SCOPED_TRACE(testing::Message() << "Host: " << test.host); | 334 SCOPED_TRACE(testing::Message() << "Host: " << test.host); |
| 335 OriginAccessEntry entry(test.protocol, test.host, | 335 OriginAccessEntry entry(test.protocol, test.host, |
| 336 OriginAccessEntry::DisallowSubdomains); | 336 OriginAccessEntry::DisallowSubdomains); |
| 337 EXPECT_EQ(test.isIPAddress, entry.hostIsIPAddress()) << test.host; | 337 EXPECT_EQ(test.isIPAddress, entry.hostIsIPAddress()) << test.host; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 TEST(OriginAccessEntryTest, IPAddressMatchingTest) { | 341 TEST(OriginAccessEntryTest, IPAddressMatchingTest) { |
| 342 struct TestCase { | 342 struct TestCase { |
| 343 const char* protocol; | 343 const char* protocol; |
| 344 const char* host; | 344 const char* host; |
| 345 const char* origin; | 345 const char* origin; |
| 346 OriginAccessEntry::MatchResult expected; | 346 OriginAccessEntry::MatchResult expected; |
| 347 } inputs[] = { | 347 } inputs[] = { |
| 348 {"http", "192.0.0.123", "http://192.0.0.123/", | 348 {"http", "192.0.0.123", "http://192.0.0.123/", |
| 349 OriginAccessEntry::MatchesOrigin}, | 349 OriginAccessEntry::MatchesOrigin}, |
| 350 {"http", "0.0.123", "http://192.0.0.123/", | 350 {"http", "0.0.123", "http://192.0.0.123/", |
| 351 OriginAccessEntry::DoesNotMatchOrigin}, | 351 OriginAccessEntry::DoesNotMatchOrigin}, |
| 352 {"http", "0.123", "http://192.0.0.123/", | 352 {"http", "0.123", "http://192.0.0.123/", |
| 353 OriginAccessEntry::DoesNotMatchOrigin}, | 353 OriginAccessEntry::DoesNotMatchOrigin}, |
| 354 {"http", "1.123", "http://192.0.0.123/", | 354 {"http", "1.123", "http://192.0.0.123/", |
| 355 OriginAccessEntry::DoesNotMatchOrigin}, | 355 OriginAccessEntry::DoesNotMatchOrigin}, |
| 356 }; | 356 }; |
| 357 | 357 |
| 358 OriginAccessEntryTestPlatform platform; | 358 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
| 359 platform.setPublicSuffix("com"); | 359 platform->setPublicSuffix("com"); |
| 360 | 360 |
| 361 for (const auto& test : inputs) { | 361 for (const auto& test : inputs) { |
| 362 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 362 SCOPED_TRACE(testing::Message() << "Host: " << test.host |
| 363 << ", Origin: " << test.origin); | 363 << ", Origin: " << test.origin); |
| 364 RefPtr<SecurityOrigin> originToTest = | 364 RefPtr<SecurityOrigin> originToTest = |
| 365 SecurityOrigin::createFromString(test.origin); | 365 SecurityOrigin::createFromString(test.origin); |
| 366 OriginAccessEntry entry1(test.protocol, test.host, | 366 OriginAccessEntry entry1(test.protocol, test.host, |
| 367 OriginAccessEntry::AllowSubdomains); | 367 OriginAccessEntry::AllowSubdomains); |
| 368 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 368 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
| 369 | 369 |
| 370 OriginAccessEntry entry2(test.protocol, test.host, | 370 OriginAccessEntry entry2(test.protocol, test.host, |
| 371 OriginAccessEntry::DisallowSubdomains); | 371 OriginAccessEntry::DisallowSubdomains); |
| 372 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); | 372 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace blink | 376 } // namespace blink |
| OLD | NEW |