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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 OriginAccessEntry::kMatchesOrigin}, | 136 OriginAccessEntry::kMatchesOrigin}, |
137 {"https", "", "http://beispiel.de/", | 137 {"https", "", "http://beispiel.de/", |
138 OriginAccessEntry::kDoesNotMatchOrigin, | 138 OriginAccessEntry::kDoesNotMatchOrigin, |
139 OriginAccessEntry::kMatchesOrigin}, | 139 OriginAccessEntry::kMatchesOrigin}, |
140 }; | 140 }; |
141 | 141 |
142 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 142 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
143 platform->SetPublicSuffix("com"); | 143 platform->SetPublicSuffix("com"); |
144 | 144 |
145 for (const auto& test : inputs) { | 145 for (const auto& test : inputs) { |
146 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 146 SCOPED_TRACE(::testing::Message() |
147 << ", Origin: " << test.origin); | 147 << "Host: " << test.host << ", Origin: " << test.origin); |
148 RefPtr<SecurityOrigin> origin_to_test = | 148 RefPtr<SecurityOrigin> origin_to_test = |
149 SecurityOrigin::CreateFromString(test.origin); | 149 SecurityOrigin::CreateFromString(test.origin); |
150 OriginAccessEntry entry1(test.protocol, test.host, | 150 OriginAccessEntry entry1(test.protocol, test.host, |
151 OriginAccessEntry::kAllowSubdomains); | 151 OriginAccessEntry::kAllowSubdomains); |
152 EXPECT_EQ(test.expected_origin, entry1.MatchesOrigin(*origin_to_test)); | 152 EXPECT_EQ(test.expected_origin, entry1.MatchesOrigin(*origin_to_test)); |
153 EXPECT_EQ(test.expected_domain, entry1.MatchesDomain(*origin_to_test)); | 153 EXPECT_EQ(test.expected_domain, entry1.MatchesDomain(*origin_to_test)); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest) { | 157 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 196 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
197 platform->SetPublicSuffix("com"); | 197 platform->SetPublicSuffix("com"); |
198 | 198 |
199 for (const auto& test : inputs) { | 199 for (const auto& test : inputs) { |
200 RefPtr<SecurityOrigin> origin_to_test = | 200 RefPtr<SecurityOrigin> origin_to_test = |
201 SecurityOrigin::CreateFromString(test.origin); | 201 SecurityOrigin::CreateFromString(test.origin); |
202 OriginAccessEntry entry1(test.protocol, test.host, | 202 OriginAccessEntry entry1(test.protocol, test.host, |
203 OriginAccessEntry::kAllowRegisterableDomains); | 203 OriginAccessEntry::kAllowRegisterableDomains); |
204 | 204 |
205 SCOPED_TRACE(testing::Message() | 205 SCOPED_TRACE(::testing::Message() |
206 << "Host: " << test.host << ", Origin: " << test.origin | 206 << "Host: " << test.host << ", Origin: " << test.origin |
207 << ", Domain: " << entry1.Registerable().Utf8().data()); | 207 << ", Domain: " << entry1.Registerable().Utf8().data()); |
208 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); | 208 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTestWithDottedSuffix) { | 212 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTestWithDottedSuffix) { |
213 struct TestCase { | 213 struct TestCase { |
214 const char* protocol; | 214 const char* protocol; |
215 const char* host; | 215 const char* host; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 252 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
253 platform->SetPublicSuffix("appspot.com"); | 253 platform->SetPublicSuffix("appspot.com"); |
254 | 254 |
255 for (const auto& test : inputs) { | 255 for (const auto& test : inputs) { |
256 RefPtr<SecurityOrigin> origin_to_test = | 256 RefPtr<SecurityOrigin> origin_to_test = |
257 SecurityOrigin::CreateFromString(test.origin); | 257 SecurityOrigin::CreateFromString(test.origin); |
258 OriginAccessEntry entry1(test.protocol, test.host, | 258 OriginAccessEntry entry1(test.protocol, test.host, |
259 OriginAccessEntry::kAllowRegisterableDomains); | 259 OriginAccessEntry::kAllowRegisterableDomains); |
260 | 260 |
261 SCOPED_TRACE(testing::Message() | 261 SCOPED_TRACE(::testing::Message() |
262 << "Host: " << test.host << ", Origin: " << test.origin | 262 << "Host: " << test.host << ", Origin: " << test.origin |
263 << ", Domain: " << entry1.Registerable().Utf8().data()); | 263 << ", Domain: " << entry1.Registerable().Utf8().data()); |
264 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); | 264 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) { | 268 TEST(OriginAccessEntryTest, DisallowSubdomainsTest) { |
269 struct TestCase { | 269 struct TestCase { |
270 const char* protocol; | 270 const char* protocol; |
271 const char* host; | 271 const char* host; |
(...skipping 25 matching lines...) Expand all Loading... |
297 {"http", "", "http://beispiel.de/", | 297 {"http", "", "http://beispiel.de/", |
298 OriginAccessEntry::kDoesNotMatchOrigin}, | 298 OriginAccessEntry::kDoesNotMatchOrigin}, |
299 {"https", "", "http://beispiel.de/", | 299 {"https", "", "http://beispiel.de/", |
300 OriginAccessEntry::kDoesNotMatchOrigin}, | 300 OriginAccessEntry::kDoesNotMatchOrigin}, |
301 }; | 301 }; |
302 | 302 |
303 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 303 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
304 platform->SetPublicSuffix("com"); | 304 platform->SetPublicSuffix("com"); |
305 | 305 |
306 for (const auto& test : inputs) { | 306 for (const auto& test : inputs) { |
307 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 307 SCOPED_TRACE(::testing::Message() |
308 << ", Origin: " << test.origin); | 308 << "Host: " << test.host << ", Origin: " << test.origin); |
309 RefPtr<SecurityOrigin> origin_to_test = | 309 RefPtr<SecurityOrigin> origin_to_test = |
310 SecurityOrigin::CreateFromString(test.origin); | 310 SecurityOrigin::CreateFromString(test.origin); |
311 OriginAccessEntry entry1(test.protocol, test.host, | 311 OriginAccessEntry entry1(test.protocol, test.host, |
312 OriginAccessEntry::kDisallowSubdomains); | 312 OriginAccessEntry::kDisallowSubdomains); |
313 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); | 313 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 TEST(OriginAccessEntryTest, IPAddressTest) { | 317 TEST(OriginAccessEntryTest, IPAddressTest) { |
318 struct TestCase { | 318 struct TestCase { |
319 const char* protocol; | 319 const char* protocol; |
320 const char* host; | 320 const char* host; |
321 bool is_ip_address; | 321 bool is_ip_address; |
322 } inputs[] = { | 322 } inputs[] = { |
323 {"http", "1.1.1.1", true}, | 323 {"http", "1.1.1.1", true}, |
324 {"http", "1.1.1.1.1", false}, | 324 {"http", "1.1.1.1.1", false}, |
325 {"http", "example.com", false}, | 325 {"http", "example.com", false}, |
326 {"http", "hostname.that.ends.with.a.number1", false}, | 326 {"http", "hostname.that.ends.with.a.number1", false}, |
327 {"http", "2001:db8::1", false}, | 327 {"http", "2001:db8::1", false}, |
328 {"http", "[2001:db8::1]", true}, | 328 {"http", "[2001:db8::1]", true}, |
329 {"http", "2001:db8::a", false}, | 329 {"http", "2001:db8::a", false}, |
330 {"http", "[2001:db8::a]", true}, | 330 {"http", "[2001:db8::a]", true}, |
331 {"http", "", false}, | 331 {"http", "", false}, |
332 }; | 332 }; |
333 | 333 |
334 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 334 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
335 platform->SetPublicSuffix("com"); | 335 platform->SetPublicSuffix("com"); |
336 | 336 |
337 for (const auto& test : inputs) { | 337 for (const auto& test : inputs) { |
338 SCOPED_TRACE(testing::Message() << "Host: " << test.host); | 338 SCOPED_TRACE(::testing::Message() << "Host: " << test.host); |
339 OriginAccessEntry entry(test.protocol, test.host, | 339 OriginAccessEntry entry(test.protocol, test.host, |
340 OriginAccessEntry::kDisallowSubdomains); | 340 OriginAccessEntry::kDisallowSubdomains); |
341 EXPECT_EQ(test.is_ip_address, entry.HostIsIPAddress()) << test.host; | 341 EXPECT_EQ(test.is_ip_address, entry.HostIsIPAddress()) << test.host; |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 TEST(OriginAccessEntryTest, IPAddressMatchingTest) { | 345 TEST(OriginAccessEntryTest, IPAddressMatchingTest) { |
346 struct TestCase { | 346 struct TestCase { |
347 const char* protocol; | 347 const char* protocol; |
348 const char* host; | 348 const char* host; |
349 const char* origin; | 349 const char* origin; |
350 OriginAccessEntry::MatchResult expected; | 350 OriginAccessEntry::MatchResult expected; |
351 } inputs[] = { | 351 } inputs[] = { |
352 {"http", "192.0.0.123", "http://192.0.0.123/", | 352 {"http", "192.0.0.123", "http://192.0.0.123/", |
353 OriginAccessEntry::kMatchesOrigin}, | 353 OriginAccessEntry::kMatchesOrigin}, |
354 {"http", "0.0.123", "http://192.0.0.123/", | 354 {"http", "0.0.123", "http://192.0.0.123/", |
355 OriginAccessEntry::kDoesNotMatchOrigin}, | 355 OriginAccessEntry::kDoesNotMatchOrigin}, |
356 {"http", "0.123", "http://192.0.0.123/", | 356 {"http", "0.123", "http://192.0.0.123/", |
357 OriginAccessEntry::kDoesNotMatchOrigin}, | 357 OriginAccessEntry::kDoesNotMatchOrigin}, |
358 {"http", "1.123", "http://192.0.0.123/", | 358 {"http", "1.123", "http://192.0.0.123/", |
359 OriginAccessEntry::kDoesNotMatchOrigin}, | 359 OriginAccessEntry::kDoesNotMatchOrigin}, |
360 }; | 360 }; |
361 | 361 |
362 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; | 362 ScopedTestingPlatformSupport<OriginAccessEntryTestPlatform> platform; |
363 platform->SetPublicSuffix("com"); | 363 platform->SetPublicSuffix("com"); |
364 | 364 |
365 for (const auto& test : inputs) { | 365 for (const auto& test : inputs) { |
366 SCOPED_TRACE(testing::Message() << "Host: " << test.host | 366 SCOPED_TRACE(::testing::Message() |
367 << ", Origin: " << test.origin); | 367 << "Host: " << test.host << ", Origin: " << test.origin); |
368 RefPtr<SecurityOrigin> origin_to_test = | 368 RefPtr<SecurityOrigin> origin_to_test = |
369 SecurityOrigin::CreateFromString(test.origin); | 369 SecurityOrigin::CreateFromString(test.origin); |
370 OriginAccessEntry entry1(test.protocol, test.host, | 370 OriginAccessEntry entry1(test.protocol, test.host, |
371 OriginAccessEntry::kAllowSubdomains); | 371 OriginAccessEntry::kAllowSubdomains); |
372 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); | 372 EXPECT_EQ(test.expected, entry1.MatchesOrigin(*origin_to_test)); |
373 | 373 |
374 OriginAccessEntry entry2(test.protocol, test.host, | 374 OriginAccessEntry entry2(test.protocol, test.host, |
375 OriginAccessEntry::kDisallowSubdomains); | 375 OriginAccessEntry::kDisallowSubdomains); |
376 EXPECT_EQ(test.expected, entry2.MatchesOrigin(*origin_to_test)); | 376 EXPECT_EQ(test.expected, entry2.MatchesOrigin(*origin_to_test)); |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 } // namespace blink | 380 } // namespace blink |
OLD | NEW |