summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/test_dual_header.html
blob: 6d3a35fd01e4ec54d7de6fb6e110825ec342d9be (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
60
61
62
63
64
65
66
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1036399 - Multiple CSP policies should be combined towards an intersection</title>
  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
  <p id="display"></p>
  <div id="content" style="visibility: hidden">
    <iframe style="width:100%;" id="testframe"></iframe>
  </div>

<script class="testbody" type="text/javascript">

/* Description of the test:
 * We have two tests where each tests serves a page using two CSP policies:
 *   a) * default-src 'self'
 *      * default-src 'self' 'unsafe-inline'
 *
 *   b) * default-src 'self' 'unsafe-inline'
 *      * default-src 'self' 'unsafe-inline'
 *
 * We make sure the inline script is *blocked* for test (a) but *allowed* for test (b).
 * Multiple CSPs should be combined towards an intersection and it shouldn't be possible
 * to open up (loosen) a CSP policy.
 */

const TESTS = [
  { query: "tight", result: "blocked" },
  { query: "loose", result: "allowed" }
];
var testCounter = -1;

function ckeckResult() {
  try {
    document.getElementById("testframe").removeEventListener('load', ckeckResult, false);
    var testframe = document.getElementById("testframe");
    var divcontent = testframe.contentWindow.document.getElementById('testdiv').innerHTML;
    is(divcontent, curTest.result, "should be 'blocked'!");
  }
  catch (e) {
    ok(false, "error: could not access content in div container!");
  }
  loadNextTest();
}

function loadNextTest() {
  testCounter++;
  if (testCounter >= TESTS.length) {
    SimpleTest.finish();
    return;
  }
  curTest = TESTS[testCounter];
  var src = "file_dual_header_testserver.sjs?" + curTest.query;
  document.getElementById("testframe").addEventListener("load", ckeckResult, false);
  document.getElementById("testframe").src = src;
}

SimpleTest.waitForExplicitFinish();
loadNextTest();

</script>
</body>
</html>