summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/embedded-enforcement/subsumption_algorithm-nonces.html
blob: 33551be57d660fa3f5868ef1e875724b49da448d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title>Embedded Enforcement: Subsumption Algorithm - Nonces.</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="support/testharness-helper.sub.js"></script>
</head>
<body>
  <script>
    var tests = [
      { "name": "Exact nonce subsumes.",
        "required_csp": "style-src 'nonce-abc'",
        "returned_csp_1": "style-src 'nonce-abc'",
        "expected": IframeLoad.EXPECT_LOAD },
      { "name": "Any nonce subsumes.",
        "required_csp": "style-src 'nonce-abc'",
        "returned_csp_1": "style-src 'nonce-xyz'",
        "expected": IframeLoad.EXPECT_LOAD },
      { "name": "A nonce has to be returned if required by the embedder.",
        "required_csp": "style-src 'nonce-abc'",
        "returned_csp_1": "style-src http://example1.com/foo",
        "expected": IframeLoad.EXPECT_BLOCK },
      { "name": "Multiples nonces returned subsume.",
        "required_csp": "style-src 'nonce-abc'",
        "returned_csp_1": "style-src 'nonce-xyz' 'nonce-abc'",
        "expected": IframeLoad.EXPECT_LOAD },
      // nonce intersection
      { "name": "Nonce intersection is still done on exact match - non-matching nonces.",
        "required_csp": "style-src 'none'",
        "returned_csp_1": "style-src 'nonce-def'",
        "returned_csp_2": "style-src 'nonce-xyz'",
        "expected": IframeLoad.EXPECT_LOAD },
      { "name": "Nonce intersection is still done on exact match - matching nonces.",
        "required_csp": "style-src 'none'",
        "returned_csp_1": "style-src 'nonce-def'",
        "returned_csp_2": "style-src 'nonce-def' 'nonce-xyz'",
        "expected": IframeLoad.EXPECT_BLOCK },
      // other expressions still have to work
      { "name": "Other expressions still have to be subsumed - positive test.",
        "required_csp": "style-src http://example1.com/foo/ 'nonce-abc'",
        "returned_csp_1": "style-src http://example1.com/foo/ 'nonce-xyz'",
        "expected": IframeLoad.EXPECT_LOAD },
      { "name": "Other expressions still have to be subsumed - negative test",
        "required_csp": "style-src http://example1.com/foo/ 'nonce-abc'",
        "returned_csp_1": "style-src http://not-example1.com/foo/ 'nonce-xyz'",
        "expected": IframeLoad.EXPECT_BLOCK },
    ];
    tests.forEach(test => {
      async_test(t =>  {
        var url = generateUrlWithPolicies(Host.CROSS_ORIGIN, test.returned_csp_1);
        if (test.returned_csp_2)
          url.searchParams.append("policy2", test.returned_csp_2);
        assert_iframe_with_csp(t, url, test.required_csp, test.expected, test.name, null);
      }, test.name);
    });
  </script>
</body>
</html>