Bug 1086612 - CSP: Let source expression be the empty set in case no valid source can be parsed - tests (r=sstamm)

This commit is contained in:
Christoph Kerschbaumer 2014-10-21 17:47:21 -07:00
parent fb5f765814
commit 65b2cf1ec1
3 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1086612 - CSP: Let source expression be the empty set in case no valid source can be parsed</title>
</head>
<body>
<div id="testdiv">blocked</div>
<!-- Note, we reuse file_csp_path_matching.js which only updates the testdiv to 'allowed' if loaded !-->
<script src="http://test1.example.com/tests/content/base/test/csp/file_csp_path_matching.js"></script>
</body>
</html>

View File

@ -36,6 +36,7 @@ support-files =
file_CSP_inlinestyle_main.html^headers^
file_CSP_inlinestyle_main_allowed.html
file_CSP_inlinestyle_main_allowed.html^headers^
file_csp_invalid_source_expression.html
file_CSP_main.html
file_CSP_main.html^headers^
file_CSP_main.js
@ -111,6 +112,7 @@ support-files =
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) || toolkit == 'android' # Times out, not sure why (bug 1008445)
[test_CSP_inlinescript.html]
[test_CSP_inlinestyle.html]
[test_csp_invalid_source_expression.html]
[test_bug836922_npolicies.html]
[test_bug886164.html]
[test_csp_redirects.html]

View File

@ -0,0 +1,57 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1086612 - CSP: Let source expression be the empty set in case no valid source can be parsed</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();
/* Description of the test:
* We try to parse a policy:
* script-src bankid:/*
* where the source expression (bankid:/*) is invalid. In that case the source-expression
* should be the empty set ('none'), see: http://www.w3.org/TR/CSP11/#source-list-parsing
* We confirm that the script is blocked by CSP.
*/
const policy = "script-src bankid:/*";
function runTest() {
var src = "file_csp_testserver.sjs";
// append the file that should be served
src += "?file=" + escape("tests/content/base/test/csp/file_csp_invalid_source_expression.html");
// append the CSP that should be used to serve the file
src += "&csp=" + escape(policy);
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, "blocked", "should be 'blocked'!");
}
catch (e) {
ok(false, "ERROR: could not access content!");
}
SimpleTest.finish();
}
runTest();
</script>
</body>
</html>