gecko/content/base/test/csp/test_csp_report.html

114 lines
3.8 KiB
HTML
Raw Normal View History

2010-05-27 09:12:32 -07:00
<!DOCTYPE HTML>
<html>
Bug 915824 - Move CSP tests from content/base/test into content/base/test/csp directory. r=geekboy --HG-- rename : content/base/test/file_bug548193.sjs => content/base/test/csp/file_csp_report.sjs rename : content/base/test/file_bug717511.html => content/base/test/csp/file_multi_policy_injection_bypass.html rename : content/base/test/file_bug717511.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass.html^headers^ rename : content/base/test/file_bug717511_2.html => content/base/test/csp/file_multi_policy_injection_bypass_2.html rename : content/base/test/file_bug717511_2.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass_2.html^headers^ rename : content/base/test/file_bug558431.html => content/base/test/csp/file_policyuri_async_fetch.html rename : content/base/test/file_bug558431.html^headers^ => content/base/test/csp/file_policyuri_async_fetch.html^headers^ rename : content/base/test/file_bug650386_content.sjs => content/base/test/csp/file_redirect_content.sjs rename : content/base/test/file_bug650386_report.sjs => content/base/test/csp/file_redirect_report.sjs rename : content/base/test/file_bug702439.html => content/base/test/csp/file_subframe_run_js_if_allowed.html rename : content/base/test/test_bug702439.html^headers^ => content/base/test/csp/file_subframe_run_js_if_allowed.html^headers^ rename : content/base/test/test_bug650386_redirect_301.html => content/base/test/csp/test_301_redirect.html rename : content/base/test/test_bug650386_redirect_302.html => content/base/test/csp/test_302_redirect.html rename : content/base/test/test_bug650386_redirect_303.html => content/base/test/csp/test_303_redirect.html rename : content/base/test/test_bug650386_redirect_307.html => content/base/test/csp/test_307_redirect.html rename : content/base/test/test_bug548193.html => content/base/test/csp/test_csp_report.html rename : content/base/test/test_bug717511.html => content/base/test/csp/test_multi_policy_injection_bypass.html rename : content/base/test/test_bug558431.html => content/base/test/csp/test_policyuri_async_fetch.html rename : content/base/test/test_bug702439.html => content/base/test/csp/test_subframe_run_js_if_allowed.html
2014-02-18 06:47:53 -08:00
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=548193
-->
2010-05-27 09:12:32 -07:00
<head>
Bug 915824 - Move CSP tests from content/base/test into content/base/test/csp directory. r=geekboy --HG-- rename : content/base/test/file_bug548193.sjs => content/base/test/csp/file_csp_report.sjs rename : content/base/test/file_bug717511.html => content/base/test/csp/file_multi_policy_injection_bypass.html rename : content/base/test/file_bug717511.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass.html^headers^ rename : content/base/test/file_bug717511_2.html => content/base/test/csp/file_multi_policy_injection_bypass_2.html rename : content/base/test/file_bug717511_2.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass_2.html^headers^ rename : content/base/test/file_bug558431.html => content/base/test/csp/file_policyuri_async_fetch.html rename : content/base/test/file_bug558431.html^headers^ => content/base/test/csp/file_policyuri_async_fetch.html^headers^ rename : content/base/test/file_bug650386_content.sjs => content/base/test/csp/file_redirect_content.sjs rename : content/base/test/file_bug650386_report.sjs => content/base/test/csp/file_redirect_report.sjs rename : content/base/test/file_bug702439.html => content/base/test/csp/file_subframe_run_js_if_allowed.html rename : content/base/test/test_bug702439.html^headers^ => content/base/test/csp/file_subframe_run_js_if_allowed.html^headers^ rename : content/base/test/test_bug650386_redirect_301.html => content/base/test/csp/test_301_redirect.html rename : content/base/test/test_bug650386_redirect_302.html => content/base/test/csp/test_302_redirect.html rename : content/base/test/test_bug650386_redirect_303.html => content/base/test/csp/test_303_redirect.html rename : content/base/test/test_bug650386_redirect_307.html => content/base/test/csp/test_307_redirect.html rename : content/base/test/test_bug548193.html => content/base/test/csp/test_csp_report.html rename : content/base/test/test_bug717511.html => content/base/test/csp/test_multi_policy_injection_bypass.html rename : content/base/test/test_bug558431.html => content/base/test/csp/test_policyuri_async_fetch.html rename : content/base/test/test_bug702439.html => content/base/test/csp/test_subframe_run_js_if_allowed.html
2014-02-18 06:47:53 -08:00
<title>Test for Bug 548193</title>
2010-05-27 09:12:32 -07:00
<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>
<script class="testbody" type="text/javascript">
// This is used to watch requests go out so we can see if the report is
// sent correctly
function examiner() {
SpecialPowers.addObserver(this, "http-on-opening-request", false);
2010-05-27 09:12:32 -07:00
}
examiner.prototype = {
observe: function(subject, topic, data) {
// subject should be an nsURI
if (!SpecialPowers.can_QI(subject))
2010-05-27 09:12:32 -07:00
return;
const reportURI = "http://mochi.test:8888/csp-report.cgi";
if (topic === "http-on-opening-request") {
var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIHttpChannel"), "URI.asciiSpec");
if (asciiSpec !== reportURI) return;
2010-05-27 09:12:32 -07:00
// Verify that the report was properly formatted.
// We'll parse the report text as JSON and verify that the properties
// have expected values.
var reportText = "{}";
try {
var uploadStream = SpecialPowers.wrap(SpecialPowers.do_QueryInterface(subject, "nsIUploadChannel")).uploadStream;
2010-05-27 09:12:32 -07:00
if (uploadStream) {
// get the bytes from the request body
var binstream = SpecialPowers.Cc["@mozilla.org/binaryinputstream;1"]
.createInstance(SpecialPowers.Ci.nsIBinaryInputStream);
2010-05-27 09:12:32 -07:00
binstream.setInputStream(uploadStream);
var segments = [];
for (var count = uploadStream.available(); count; count = uploadStream.available()) {
var data = binstream.readBytes(count);
segments.push(data);
}
2010-05-27 09:12:32 -07:00
var reportText = segments.join("");
// rewind stream as we are supposed to - there will be an assertion later if we don't.
SpecialPowers.do_QueryInterface(uploadStream, "nsISeekableStream").seek(SpecialPowers.Ci.nsISeekableStream.NS_SEEK_SET, 0);
2010-05-27 09:12:32 -07:00
}
}
catch(e) {}
var reportObj = JSON.parse(reportText);
// test for the proper values in the report object
window.checkResults(reportObj);
// finish up
window.examiner.remove();
SimpleTest.finish();
}
},
// remove the listener
remove: function() {
SpecialPowers.removeObserver(this, "http-on-opening-request");
2010-05-27 09:12:32 -07:00
}
}
// content file that triggers a violation report
Bug 915824 - Move CSP tests from content/base/test into content/base/test/csp directory. r=geekboy --HG-- rename : content/base/test/file_bug548193.sjs => content/base/test/csp/file_csp_report.sjs rename : content/base/test/file_bug717511.html => content/base/test/csp/file_multi_policy_injection_bypass.html rename : content/base/test/file_bug717511.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass.html^headers^ rename : content/base/test/file_bug717511_2.html => content/base/test/csp/file_multi_policy_injection_bypass_2.html rename : content/base/test/file_bug717511_2.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass_2.html^headers^ rename : content/base/test/file_bug558431.html => content/base/test/csp/file_policyuri_async_fetch.html rename : content/base/test/file_bug558431.html^headers^ => content/base/test/csp/file_policyuri_async_fetch.html^headers^ rename : content/base/test/file_bug650386_content.sjs => content/base/test/csp/file_redirect_content.sjs rename : content/base/test/file_bug650386_report.sjs => content/base/test/csp/file_redirect_report.sjs rename : content/base/test/file_bug702439.html => content/base/test/csp/file_subframe_run_js_if_allowed.html rename : content/base/test/test_bug702439.html^headers^ => content/base/test/csp/file_subframe_run_js_if_allowed.html^headers^ rename : content/base/test/test_bug650386_redirect_301.html => content/base/test/csp/test_301_redirect.html rename : content/base/test/test_bug650386_redirect_302.html => content/base/test/csp/test_302_redirect.html rename : content/base/test/test_bug650386_redirect_303.html => content/base/test/csp/test_303_redirect.html rename : content/base/test/test_bug650386_redirect_307.html => content/base/test/csp/test_307_redirect.html rename : content/base/test/test_bug548193.html => content/base/test/csp/test_csp_report.html rename : content/base/test/test_bug717511.html => content/base/test/csp/test_multi_policy_injection_bypass.html rename : content/base/test/test_bug558431.html => content/base/test/csp/test_policyuri_async_fetch.html rename : content/base/test/test_bug702439.html => content/base/test/csp/test_subframe_run_js_if_allowed.html
2014-02-18 06:47:53 -08:00
var testFile = "file_csp_report.sjs";
2010-05-27 09:12:32 -07:00
window.checkResults = function(reportObj) {
var cspReport = reportObj["csp-report"];
// correct violating request
is(cspReport["document-uri"],
Bug 915824 - Move CSP tests from content/base/test into content/base/test/csp directory. r=geekboy --HG-- rename : content/base/test/file_bug548193.sjs => content/base/test/csp/file_csp_report.sjs rename : content/base/test/file_bug717511.html => content/base/test/csp/file_multi_policy_injection_bypass.html rename : content/base/test/file_bug717511.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass.html^headers^ rename : content/base/test/file_bug717511_2.html => content/base/test/csp/file_multi_policy_injection_bypass_2.html rename : content/base/test/file_bug717511_2.html^headers^ => content/base/test/csp/file_multi_policy_injection_bypass_2.html^headers^ rename : content/base/test/file_bug558431.html => content/base/test/csp/file_policyuri_async_fetch.html rename : content/base/test/file_bug558431.html^headers^ => content/base/test/csp/file_policyuri_async_fetch.html^headers^ rename : content/base/test/file_bug650386_content.sjs => content/base/test/csp/file_redirect_content.sjs rename : content/base/test/file_bug650386_report.sjs => content/base/test/csp/file_redirect_report.sjs rename : content/base/test/file_bug702439.html => content/base/test/csp/file_subframe_run_js_if_allowed.html rename : content/base/test/test_bug702439.html^headers^ => content/base/test/csp/file_subframe_run_js_if_allowed.html^headers^ rename : content/base/test/test_bug650386_redirect_301.html => content/base/test/csp/test_301_redirect.html rename : content/base/test/test_bug650386_redirect_302.html => content/base/test/csp/test_302_redirect.html rename : content/base/test/test_bug650386_redirect_303.html => content/base/test/csp/test_303_redirect.html rename : content/base/test/test_bug650386_redirect_307.html => content/base/test/csp/test_307_redirect.html rename : content/base/test/test_bug548193.html => content/base/test/csp/test_csp_report.html rename : content/base/test/test_bug717511.html => content/base/test/csp/test_multi_policy_injection_bypass.html rename : content/base/test/test_bug558431.html => content/base/test/csp/test_policyuri_async_fetch.html rename : content/base/test/test_bug702439.html => content/base/test/csp/test_subframe_run_js_if_allowed.html
2014-02-18 06:47:53 -08:00
"http://mochi.test:8888/tests/content/base/test/csp/" + testFile,
2010-05-27 09:12:32 -07:00
"Incorrect violating request");
// correct blocked-uri
is(cspReport["blocked-uri"],
"http://example.org/tests/content/base/test/file_CSP.sjs?testid=img_bad&type=img/png",
"Incorrect blocked uri");
// correct violated-directive
is(cspReport["violated-directive"], "default-src http://mochi.test:8888",
2010-05-27 09:12:32 -07:00
"Incorrect violated directive");
// not practical to test request-headers as header names and values will
// change with the trunk
}
window.examiner = new examiner();
SimpleTest.waitForExplicitFinish();
// load the resource which will generate a CSP violation report
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 = testFile;
});
2010-05-27 09:12:32 -07:00
</script>
</pre>
</body>
</html>