OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/csp/CSPSource.h" | 5 #include "core/frame/csp/CSPSource.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/csp/ContentSecurityPolicy.h" | 8 #include "core/frame/csp/ContentSecurityPolicy.h" |
9 #include "platform/network/ResourceRequest.h" | 9 #include "platform/network/ResourceRequest.h" |
10 #include "platform/weborigin/KURL.h" | 10 #include "platform/weborigin/KURL.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 CSPSource* returned = | 337 CSPSource* returned = |
338 new CSPSource(csp.get(), test.aScheme, "example.com", 0, "/", | 338 new CSPSource(csp.get(), test.aScheme, "example.com", 0, "/", |
339 CSPSource::NoWildcard, CSPSource::NoWildcard); | 339 CSPSource::NoWildcard, CSPSource::NoWildcard); |
340 CSPSource* required = | 340 CSPSource* required = |
341 new CSPSource(csp.get(), test.bScheme, "example.com", 0, "/", | 341 new CSPSource(csp.get(), test.bScheme, "example.com", 0, "/", |
342 CSPSource::NoWildcard, CSPSource::NoWildcard); | 342 CSPSource::NoWildcard, CSPSource::NoWildcard); |
343 EXPECT_EQ(required->subsumes(returned), test.expected); | 343 EXPECT_EQ(required->subsumes(returned), test.expected); |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
| 347 TEST_F(CSPSourceTest, IsSimilar) { |
| 348 struct Source { |
| 349 const char* scheme; |
| 350 const char* host; |
| 351 const char* path; |
| 352 const int port; |
| 353 }; |
| 354 struct TestCase { |
| 355 const Source a; |
| 356 const Source b; |
| 357 bool isSimilar; |
| 358 } cases[] = { |
| 359 // Similar |
| 360 {{"http", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true}, |
| 361 // Schemes |
| 362 {{"https", "example.com", "/", 0}, |
| 363 {"https", "example.com", "/", 0}, |
| 364 true}, |
| 365 {{"https", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true}, |
| 366 {{"ws", "example.com", "/", 0}, {"wss", "example.com", "/", 0}, true}, |
| 367 // Ports |
| 368 {{"http", "example.com", "/", 90}, |
| 369 {"http", "example.com", "/", 90}, |
| 370 true}, |
| 371 {{"wss", "example.com", "/", 0}, |
| 372 {"wss", "example.com", "/", 0}, |
| 373 true}, // use default port |
| 374 {{"http", "example.com", "/", 80}, {"http", "example.com", "/", 0}, true}, |
| 375 // Paths |
| 376 {{"http", "example.com", "/", 0}, |
| 377 {"http", "example.com", "/1.html", 0}, |
| 378 true}, |
| 379 {{"http", "example.com", "/", 0}, {"http", "example.com", "", 0}, true}, |
| 380 {{"http", "example.com", "/", 0}, |
| 381 {"http", "example.com", "/a/b/", 0}, |
| 382 true}, |
| 383 {{"http", "example.com", "/a/", 0}, |
| 384 {"http", "example.com", "/a/", 0}, |
| 385 true}, |
| 386 {{"http", "example.com", "/a/", 0}, |
| 387 {"http", "example.com", "/a/b/", 0}, |
| 388 true}, |
| 389 {{"http", "example.com", "/a/", 0}, |
| 390 {"http", "example.com", "/a/b/1.html", 0}, |
| 391 true}, |
| 392 {{"http", "example.com", "/1.html", 0}, |
| 393 {"http", "example.com", "/1.html", 0}, |
| 394 true}, |
| 395 // Mixed |
| 396 {{"http", "example.com", "/1.html", 90}, |
| 397 {"http", "example.com", "/", 90}, |
| 398 true}, |
| 399 {{"https", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true}, |
| 400 {{"http", "example.com", "/a/", 90}, |
| 401 {"https", "example.com", "", 90}, |
| 402 true}, |
| 403 {{"wss", "example.com", "/a/", 90}, |
| 404 {"ws", "example.com", "/a/b/", 90}, |
| 405 true}, |
| 406 {{"https", "example.com", "/a/", 90}, |
| 407 {"https", "example.com", "/a/b/", 90}, |
| 408 true}, |
| 409 // Not Similar |
| 410 {{"http", "example.com", "/a/", 0}, |
| 411 {"https", "example.com", "", 90}, |
| 412 false}, |
| 413 {{"https", "example.com", "/", 0}, |
| 414 {"https", "example.com", "/", 90}, |
| 415 false}, |
| 416 {{"http", "example.com", "/", 0}, {"http", "another.com", "/", 0}, false}, |
| 417 {{"wss", "example.com", "/", 0}, {"http", "example.com", "/", 0}, false}, |
| 418 {{"wss", "example.com", "/", 0}, {"about", "example.com", "/", 0}, false}, |
| 419 {{"http", "example.com", "/", 0}, |
| 420 {"about", "example.com", "/", 0}, |
| 421 false}, |
| 422 {{"http", "example.com", "/1.html", 0}, |
| 423 {"http", "example.com", "/2.html", 0}, |
| 424 false}, |
| 425 {{"http", "example.com", "/a/1.html", 0}, |
| 426 {"http", "example.com", "/a/b/", 0}, |
| 427 false}, |
| 428 {{"http", "example.com", "/", 443}, |
| 429 {"about", "example.com", "/", 800}, |
| 430 false}, |
| 431 }; |
| 432 |
| 433 for (const auto& test : cases) { |
| 434 CSPSource* returned = new CSPSource( |
| 435 csp.get(), test.a.scheme, test.a.host, test.a.port, test.a.path, |
| 436 CSPSource::NoWildcard, CSPSource::NoWildcard); |
| 437 |
| 438 CSPSource* required = new CSPSource( |
| 439 csp.get(), test.b.scheme, test.b.host, test.b.port, test.b.path, |
| 440 CSPSource::NoWildcard, CSPSource::NoWildcard); |
| 441 |
| 442 EXPECT_EQ(returned->isSimilar(required), test.isSimilar); |
| 443 // Verify the same test with a and b swapped. |
| 444 EXPECT_EQ(required->isSimilar(returned), test.isSimilar); |
| 445 } |
| 446 } |
| 447 |
347 } // namespace blink | 448 } // namespace blink |
OLD | NEW |