File: test_csp_regexp_parsing.html

package info (click to toggle)
iceweasel 31.8.0esr-1~deb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,373,164 kB
  • sloc: cpp: 3,717,015; ansic: 1,797,386; python: 206,412; java: 180,622; asm: 133,557; xml: 89,501; sh: 72,014; perl: 22,087; makefile: 21,970; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (106 lines) | stat: -rw-r--r-- 3,819 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 916054 - URLs with path are ignored by FF's CSP parser</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">

SimpleTest.waitForExplicitFinish();

var policies = [
  ["allowed", "*"],
  ["allowed", "test1.example.com"],
  ["allowed", "test1.example.com/"],
  ["allowed", "test1.example.com/path-1"],
  ["allowed", "test1.example.com/path-1/"],
  ["allowed", "test1.example.com/path-1/path_2/"],
  ["allowed", "test1.example.com/path-1/path_2/file.js"],
  ["allowed", "test1.example.com/path-1/path_2/file_1.js"],
  ["allowed", "test1.example.com/path-1/path_2/file-2.js"],
  ["allowed", "test1.example.com/path-1/path_2/f.js"],
  ["allowed", "test1.example.com/path-1/path_2/f.oo.js"],
  ["allowed", "*.example.com"],
  ["allowed", "*.example.com/"],
  ["allowed", "*.example.com/path-1"],
  ["allowed", "*.example.com/path-1/"],
  ["allowed", "*.example.com/path-1/path_2/"],
  ["allowed", "*.example.com/path-1/path_2/file.js"],
  ["allowed", "*.example.com/path-1/path_2/file_1.js"],
  ["allowed", "*.example.com/path-1/path_2/file-2.js"],
  ["allowed", "*.example.com/path-1/path_2/f.js"],
  ["allowed", "*.example.com/path-1/path_2/f.oo.js"],
  ["allowed", "test1.example.com:80"],
  ["allowed", "test1.example.com:80/"],
  ["allowed", "test1.example.com:80/path-1"],
  ["allowed", "test1.example.com:80/path-1/"],
  ["allowed", "test1.example.com:80/path-1/path_2"],
  ["allowed", "test1.example.com:80/path-1/path_2/"],
  ["allowed", "test1.example.com:80/path-1/path_2/file.js"],
  ["allowed", "test1.example.com:80/path-1/path_2/f.ile.js"],
  ["allowed", "test1.example.com:*"],
  ["allowed", "test1.example.com:*/"],
  ["allowed", "test1.example.com:*/path-1"],
  ["allowed", "test1.example.com:*/path-1/"],
  ["allowed", "test1.example.com:*/path-1/path_2"],
  ["allowed", "test1.example.com:*/path-1/path_2/"],
  ["allowed", "test1.example.com:*/path-1/path_2/file.js"],
  ["allowed", "test1.example.com:*/path-1/path_2/f.ile.js"],
  // the following tests should fail
  ["blocked", "test1.example.com:88path-1/"],
  ["blocked", "test1.example.com:80.js"],
  ["blocked", "test1.example.com:*.js"],
  ["blocked", "test1.example.com:*."]
]

var counter = 0;
var policy;

function loadNextTest() {
  if (counter == policies.length) {
    SimpleTest.finish();
  }
  else {
    policy = policies[counter++];
    var src = "file_csp_testserver.sjs";
    // append the file that should be served
    src += "?file=" + escape("tests/content/base/test/csp/file_csp_regexp_parsing.html");
    // append the CSP that should be used to serve the file
    src += "&csp=" + escape("default-src 'none'; script-src " + policy[1]);

    document.getElementById("testframe").addEventListener("load", test, false);
    document.getElementById("testframe").src = src;
  }
}

function test() {
  try {
    document.getElementById("testframe").removeEventListener('load', test, false);
    var testframe = document.getElementById("testframe");
    var divcontent = testframe.contentWindow.document.getElementById('testdiv').innerHTML;
    is(divcontent, policy[0], "should be " + policy[0] + " in test " + (counter - 1) + "!");
  }
  catch (e) {
    ok(false, "ERROR: could not access content in test " + (counter - 1) + "!");
  }
  loadNextTest();
}

SpecialPowers.pushPrefEnv(
  {'set':[["security.csp.speccompliant", true]]},
  function () {
    loadNextTest();
  }
);

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