Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: Source/platform/weborigin/OriginAccessEntryTest.cpp

Issue 1163583005: Add "registerable domain" support to OriginAccessEntry. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/weborigin/OriginAccessEntryTest.cpp
diff --git a/Source/platform/weborigin/OriginAccessEntryTest.cpp b/Source/platform/weborigin/OriginAccessEntryTest.cpp
index 71fa779fec0e4f83124624097fc4171fef22bfd9..28da85fb04866c9f3fd467463894ee5fb3cf2b20 100644
--- a/Source/platform/weborigin/OriginAccessEntryTest.cpp
+++ b/Source/platform/weborigin/OriginAccessEntryTest.cpp
@@ -91,6 +91,9 @@ TEST(OriginAccessEntryTest, AllowSubdomainsTest)
{ "http", "example.com", "http://example.com/", OriginAccessEntry::MatchesOrigin },
{ "http", "example.com", "http://www.example.com/", OriginAccessEntry::MatchesOrigin },
{ "http", "example.com", "http://www.www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "www.example.com", "http://example.com/", OriginAccessEntry::DoesNotMatchOrigin },
+ { "http", "www.example.com", "http://www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "www.example.com", "http://www.www.example.com/", OriginAccessEntry::MatchesOrigin },
{ "http", "com", "http://example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
{ "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
{ "http", "com", "http://www.www.example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
@@ -117,6 +120,47 @@ TEST(OriginAccessEntryTest, AllowSubdomainsTest)
blink::Platform::shutdown();
}
+TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest)
+{
+ struct TestCase {
+ const char* protocol;
+ const char* host;
+ const char* origin;
+ OriginAccessEntry::MatchResult expected;
+ } inputs[] = {
+ { "http", "example.com", "http://example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "example.com", "http://www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "example.com", "http://www.www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "www.example.com", "http://example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "www.example.com", "http://www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "www.example.com", "http://www.www.example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
+ { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
+ { "http", "com", "http://www.www.example.com/", OriginAccessEntry::MatchesOriginButIsPublicSuffix },
+ { "https", "example.com", "http://example.com/", OriginAccessEntry::DoesNotMatchOrigin },
+ { "https", "example.com", "http://www.example.com/", OriginAccessEntry::DoesNotMatchOrigin },
+ { "https", "example.com", "http://www.www.example.com/", OriginAccessEntry::DoesNotMatchOrigin },
+ { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOrigin },
+ { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin },
+ { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin },
+ { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOrigin },
+ };
+
+ // Initialize a PSL mock that whitelists any three-letter label as a TLD ('com', 'org', 'net', etc).
+ OriginAccessEntryTestPlatform platform;
+ blink::Platform::initialize(&platform);
+
+ for (const auto& test : inputs) {
+ RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(test.origin);
+ OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::AllowRegisterableDomains);
+
+ SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin << ", Domain: " << entry1.registerable().utf8().data());
+ EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest));
+ }
+
+ blink::Platform::shutdown();
+}
+
TEST(OriginAccessEntryTest, DisallowSubdomainsTest)
{
struct TestCase {

Powered by Google App Engine
This is Rietveld 408576698