2010-01-22 21:38:21 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for Content Security Policy Connections</title>
|
|
|
|
<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="display: none">
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<iframe style="width:200px;height:200px;" id='cspframe'></iframe>
|
2013-01-09 18:57:05 +00:00
|
|
|
<iframe style="width:200px;height:200px;" id='cspframe2'></iframe>
|
2010-01-22 21:38:21 +00:00
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
var path = "/tests/content/base/test/";
|
|
|
|
|
|
|
|
// These are test results: -1 means it hasn't run,
|
|
|
|
// true/false is the pass/fail result.
|
|
|
|
window.tests = {
|
|
|
|
img_good: -1,
|
|
|
|
img_bad: -1,
|
|
|
|
style_good: -1,
|
|
|
|
style_bad: -1,
|
|
|
|
frame_good: -1,
|
|
|
|
frame_bad: -1,
|
|
|
|
script_good: -1,
|
|
|
|
script_bad: -1,
|
|
|
|
xhr_good: -1,
|
|
|
|
xhr_bad: -1,
|
|
|
|
media_good: -1,
|
|
|
|
media_bad: -1,
|
|
|
|
font_good: -1,
|
|
|
|
font_bad: -1,
|
|
|
|
object_good: -1,
|
|
|
|
object_bad: -1,
|
2013-01-09 18:57:05 +00:00
|
|
|
img_spec_compliant_good: -1,
|
|
|
|
img_spec_compliant_bad: -1,
|
|
|
|
style_spec_compliant_good: -1,
|
|
|
|
style_spec_compliant_bad: -1,
|
|
|
|
frame_spec_compliant_good: -1,
|
|
|
|
frame_spec_compliant_bad: -1,
|
|
|
|
script_spec_compliant_good: -1,
|
|
|
|
script_spec_compliant_bad: -1,
|
|
|
|
xhr_spec_compliant_good: -1,
|
|
|
|
xhr_spec_compliant_bad: -1,
|
|
|
|
media_spec_compliant_good: -1,
|
|
|
|
media_spec_compliant_bad: -1,
|
|
|
|
font_spec_compliant_good: -1,
|
|
|
|
font_spec_compliant_bad: -1,
|
|
|
|
object_spec_compliant_good: -1,
|
|
|
|
object_spec_compliant_bad: -1,
|
2010-01-22 21:38:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This is used to watch the blocked data bounce off CSP and allowed data
|
|
|
|
// get sent out to the wire.
|
|
|
|
function examiner() {
|
2013-05-01 23:16:45 +00:00
|
|
|
SpecialPowers.addObserver(this, "csp-on-violate-policy", false);
|
|
|
|
SpecialPowers.addObserver(this, "http-on-modify-request", false);
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
examiner.prototype = {
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
// subject should be an nsURI, and should be either allowed or blocked.
|
2013-05-01 23:16:45 +00:00
|
|
|
if (!SpecialPowers.can_QI(subject))
|
2010-01-22 21:38:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
var testpat = new RegExp("testid=([a-z0-9_]+)");
|
|
|
|
|
|
|
|
//_good things better be allowed!
|
|
|
|
//_bad things better be stopped!
|
|
|
|
|
|
|
|
if (topic === "http-on-modify-request") {
|
|
|
|
//these things were allowed by CSP
|
2013-05-01 23:16:45 +00:00
|
|
|
var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIHttpChannel"), "URI.asciiSpec");
|
|
|
|
if (!testpat.test(asciiSpec)) return;
|
|
|
|
var testid = testpat.exec(asciiSpec)[1];
|
2013-01-09 18:57:05 +00:00
|
|
|
|
2010-01-22 21:38:21 +00:00
|
|
|
window.testResult(testid,
|
|
|
|
/_good/.test(testid),
|
2013-05-01 23:16:45 +00:00
|
|
|
asciiSpec + " allowed by csp");
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(topic === "csp-on-violate-policy") {
|
|
|
|
//these were blocked... record that they were blocked
|
2013-05-01 23:16:45 +00:00
|
|
|
var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec");
|
|
|
|
if (!testpat.test(asciiSpec)) return;
|
|
|
|
var testid = testpat.exec(asciiSpec)[1];
|
2010-01-22 21:38:21 +00:00
|
|
|
window.testResult(testid,
|
|
|
|
/_bad/.test(testid),
|
2013-05-01 23:16:45 +00:00
|
|
|
asciiSpec + " blocked by \"" + data + "\"");
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// must eventually call this to remove the listener,
|
|
|
|
// or mochitests might get borked.
|
|
|
|
remove: function() {
|
2013-05-01 23:16:45 +00:00
|
|
|
SpecialPowers.removeObserver(this, "csp-on-violate-policy");
|
|
|
|
SpecialPowers.removeObserver(this, "http-on-modify-request");
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.examiner = new examiner();
|
|
|
|
|
|
|
|
window.testResult = function(testname, result, msg) {
|
|
|
|
//test already complete.... forget it... remember the first result.
|
|
|
|
if (window.tests[testname] != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window.tests[testname] = result;
|
|
|
|
is(result, true, testname + ' test: ' + msg);
|
|
|
|
|
|
|
|
// if any test is incomplete, keep waiting
|
|
|
|
for (var v in window.tests)
|
|
|
|
if(tests[v] == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// ... otherwise, finish
|
|
|
|
window.examiner.remove();
|
2010-07-03 01:15:13 +00:00
|
|
|
SimpleTest.finish();
|
2010-01-22 21:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2013-01-09 18:57:04 +00:00
|
|
|
SpecialPowers.pushPrefEnv(
|
|
|
|
{'set':[["security.csp.speccompliant", true]]},
|
|
|
|
function() {
|
|
|
|
// save this for last so that our listeners are registered.
|
|
|
|
// ... this loads the testbed of good and bad requests.
|
|
|
|
document.getElementById('cspframe').src = 'file_CSP_main.html';
|
|
|
|
document.getElementById('cspframe2').src = 'file_CSP_main_spec_compliant.html';
|
|
|
|
});
|
2010-01-22 21:38:21 +00:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|