mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-06-09 18:09:16 +00:00
82 lines
2.3 KiB
HTML
82 lines
2.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Bug 1045897 - Test CSP base-uri directive</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 load a page in an iframe (served over http://example.com) that tries to set the 'base'
|
|
* to (http://mochi.test). We load that page using different policies and verify that
|
|
* setting the base-uri is correctly blocked by CSP.
|
|
*/
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var testPolicies = [
|
|
"base-uri http://example.com",
|
|
"base-uri https:",
|
|
"base-uri 'none'",
|
|
];
|
|
|
|
// initializing to -1 so we start at index 0 when we start the test
|
|
var counter = -1;
|
|
|
|
function examiner() {
|
|
SpecialPowers.addObserver(this, "csp-on-violate-policy", false);
|
|
}
|
|
examiner.prototype = {
|
|
observe: function(subject, topic, data) {
|
|
if (topic === "csp-on-violate-policy") {
|
|
var spec = SpecialPowers.getPrivilegedProps(
|
|
SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec");
|
|
|
|
if (spec === "http://mochi.test/") {
|
|
// 'data' holds the violated directive
|
|
is(data, testPolicies[counter], "Disallowed setting the base-uri in test " + counter + "!");
|
|
loadNextTest();
|
|
}
|
|
}
|
|
},
|
|
remove: function() {
|
|
SpecialPowers.removeObserver(this, "csp-on-violate-policy");
|
|
}
|
|
}
|
|
window.BaseURIExaminer = new examiner();
|
|
|
|
function finishTest() {
|
|
window.BaseURIExaminer.remove();
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
function loadNextTest() {
|
|
counter++;
|
|
if (counter == testPolicies.length) {
|
|
finishTest();
|
|
return;
|
|
}
|
|
var src = "http://example.com/tests/dom/base/test/csp/file_csp_testserver.sjs";
|
|
// append the file that should be served
|
|
src += "?file=" + escape("tests/dom/base/test/csp/file_base-uri.html");
|
|
// append the CSP that should be used to serve the file
|
|
src += "&csp=" + escape(testPolicies[counter]);
|
|
document.getElementById("testframe").src = src;
|
|
}
|
|
|
|
// start running the tests
|
|
loadNextTest();
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|