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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 { 84 {
85 struct TestCase { 85 struct TestCase {
86 const char* protocol; 86 const char* protocol;
87 const char* host; 87 const char* host;
88 const char* origin; 88 const char* origin;
89 OriginAccessEntry::MatchResult expected; 89 OriginAccessEntry::MatchResult expected;
90 } inputs[] = { 90 } inputs[] = {
91 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin }, 91 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin },
92 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin }, 92 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin },
93 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin }, 93 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin },
94 { "http", "www.example.com", "http://example.com/", OriginAccessEntry::D oesNotMatchOrigin },
95 { "http", "www.example.com", "http://www.example.com/", OriginAccessEntr y::MatchesOrigin },
96 { "http", "www.example.com", "http://www.www.example.com/", OriginAccess Entry::MatchesOrigin },
94 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix }, 97 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix },
95 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix }, 98 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix },
96 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix }, 99 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix },
97 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin }, 100 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin },
98 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin }, 101 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin },
99 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin }, 102 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin },
100 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin }, 103 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin },
101 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, 104 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin },
102 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, 105 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin },
103 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin }, 106 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin },
104 }; 107 };
105 108
106 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc). 109 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc).
107 OriginAccessEntryTestPlatform platform; 110 OriginAccessEntryTestPlatform platform;
108 blink::Platform::initialize(&platform); 111 blink::Platform::initialize(&platform);
109 112
110 for (const auto& test : inputs) { 113 for (const auto& test : inputs) {
111 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin); 114 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin);
112 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); 115 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin);
113 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains); 116 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains);
114 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); 117 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest));
115 } 118 }
116 119
117 blink::Platform::shutdown(); 120 blink::Platform::shutdown();
118 } 121 }
119 122
123 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest)
124 {
125 struct TestCase {
126 const char* protocol;
127 const char* host;
128 const char* origin;
129 OriginAccessEntry::MatchResult expected;
130 } inputs[] = {
131 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin },
132 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin },
133 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin },
134 { "http", "www.example.com", "http://example.com/", OriginAccessEntry::M atchesOrigin },
135 { "http", "www.example.com", "http://www.example.com/", OriginAccessEntr y::MatchesOrigin },
136 { "http", "www.example.com", "http://www.www.example.com/", OriginAccess Entry::MatchesOrigin },
137 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix },
138 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix },
139 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix },
140 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin },
141 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin },
142 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin },
143 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin },
144 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin },
145 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin },
146 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin },
147 };
148
149 // Initialize a PSL mock that whitelists any three-letter label as a TLD ('c om', 'org', 'net', etc).
150 OriginAccessEntryTestPlatform platform;
151 blink::Platform::initialize(&platform);
152
153 for (const auto& test : inputs) {
154 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin);
155 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowRegisterableDomains);
156
157 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin << ", Domain: " << entry1.registerable().utf8().data());
158 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest));
159 }
160
161 blink::Platform::shutdown();
162 }
163
120 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) 164 TEST(OriginAccessEntryTest, DisallowSubdomainsTest)
121 { 165 {
122 struct TestCase { 166 struct TestCase {
123 const char* protocol; 167 const char* protocol;
124 const char* host; 168 const char* host;
125 const char* origin; 169 const char* origin;
126 OriginAccessEntry::MatchResult expected; 170 OriginAccessEntry::MatchResult expected;
127 } inputs[] = { 171 } inputs[] = {
128 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin }, 172 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin },
129 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::D oesNotMatchOrigin }, 173 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::D oesNotMatchOrigin },
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 255
212 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains); 256 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains);
213 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); 257 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest));
214 } 258 }
215 259
216 blink::Platform::shutdown(); 260 blink::Platform::shutdown();
217 } 261 }
218 262
219 } // namespace 263 } // namespace
220 264
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698