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