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

Side by Side Diff: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp

Issue 2452903004: Part 2.2: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: After rebasing on part2.1 Created 4 years, 1 month 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 // 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 CSPSource* required = new CSPSource( 438 CSPSource* required = new CSPSource(
439 csp.get(), test.b.scheme, test.b.host, test.b.port, test.b.path, 439 csp.get(), test.b.scheme, test.b.host, test.b.port, test.b.path,
440 CSPSource::NoWildcard, CSPSource::NoWildcard); 440 CSPSource::NoWildcard, CSPSource::NoWildcard);
441 441
442 EXPECT_EQ(returned->isSimilar(required), test.isSimilar); 442 EXPECT_EQ(returned->isSimilar(required), test.isSimilar);
443 // Verify the same test with a and b swapped. 443 // Verify the same test with a and b swapped.
444 EXPECT_EQ(required->isSimilar(returned), test.isSimilar); 444 EXPECT_EQ(required->isSimilar(returned), test.isSimilar);
445 } 445 }
446 } 446 }
447 447
448 TEST_F(CSPSourceTest, FirstSubsumesSecond) {
449 struct Source {
450 const char* scheme;
451 const char* host;
452 const char* path;
453 };
454 struct TestCase {
455 const Source returned;
456 String requiredScheme;
457 bool expected;
458 } cases[] = {
459 // Subsumed.
460 {{"http", "example.com", "/"}, "http", true},
461 {{"http", "example.com", "/page.html"}, "http", true},
462 {{"http", "second-example.com", "/"}, "http", true},
463 {{"https", "second-example.com", "/"}, "http", true},
464 {{"http", "second-example.com", "/page.html"}, "http", true},
465 {{"https", "second-example.com", "/page.html"}, "http", true},
466 {{"https", "second-example.com", "/"}, "https", true},
467 {{"https", "second-example.com", "/page.html"}, "https", true},
468 // NOT subsumed.
Mike West 2016/11/10 15:04:54 Scheme-only expressions? Ports?
469 {{"wss", "second-example.com", "/"}, "http", false},
470 {{"http", "non-example.com", "/"}, "http", false},
471 {{"http", "second-example.com", "/"}, "https", false},
472 };
473
474 for (const auto& test : cases) {
475 // Setup default vectors.
476 HeapVector<Member<CSPSource>> required;
477 HeapVector<Member<CSPSource>> returned;
Mike West 2016/11/10 15:04:54 I think |A| and |B| are probably simpler here. |re
478 returned.append(new CSPSource(csp.get(), "http", "example.com", 0, "/",
Mike West 2016/11/10 15:04:55 You're creating these sources every time you go th
479 CSPSource::NoWildcard,
480 CSPSource::NoWildcard));
481 // Empty `required` implies `none` is allowed.
482 EXPECT_FALSE(CSPSource::firstSubsumesSecond(required, returned));
483
484 required.append(new CSPSource(csp.get(), "http", "example.com", 0, "/",
485 CSPSource::NoWildcard,
486 CSPSource::NoWildcard));
487 // Add CSPSources based on the current test.
488 returned.append(new CSPSource(
489 csp.get(), test.returned.scheme, test.returned.host, 0,
490 test.returned.path, CSPSource::NoWildcard, CSPSource::NoWildcard));
491 required.append(
492 new CSPSource(csp.get(), test.requiredScheme, "second-example.com", 0,
493 "/", CSPSource::NoWildcard, CSPSource::NoWildcard));
494 // returned contains: ["http://example.com/", test.returned]
495 // required contains: ["http://example.com/",
496 // test.requiredScheme+"second-example.com/"]
497 EXPECT_EQ(test.expected,
498 CSPSource::firstSubsumesSecond(required, returned));
499
500 // If we add another source to `returned` with a host wildcard,
501 // then the result should definitely be false.
502 returned.append(new CSPSource(csp.get(), "http", "third-example.com", 0,
503 "/", CSPSource::HasWildcard,
504 CSPSource::NoWildcard));
505 EXPECT_FALSE(CSPSource::firstSubsumesSecond(required, returned));
506
507 // If we add another source to `required` with a port wildcard,
508 // it does not make `returned` to be subsumed under `required`.
509 returned.append(new CSPSource(csp.get(), "http", "third-example.com", 0,
510 "/", CSPSource::NoWildcard,
511 CSPSource::HasWildcard));
512 EXPECT_FALSE(CSPSource::firstSubsumesSecond(required, returned));
513
514 // If however we add another source to `required` with both wildcards,
515 // that CSPSource is subsumed, so the answer should be as expected
516 // before.
517 required.append(Member<CSPSource>(
518 new CSPSource(csp.get(), "http", "third-example.com", 0, "/",
519 CSPSource::HasWildcard, CSPSource::HasWildcard)));
520 EXPECT_EQ(test.expected,
521 CSPSource::firstSubsumesSecond(required, returned));
522 }
523 }
524
448 } // namespace blink 525 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698