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