2015-08-13 06:19:16 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<!-- Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script type="application/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>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<script type="application/javascript">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
window.hasCORSLoaded = false;
|
|
|
|
window.hasNonCORSLoaded = false;
|
|
|
|
|
|
|
|
function good_nonsriLoaded() {
|
|
|
|
ok(true, "Non-eligible non-SRI resource was loaded correctly.");
|
|
|
|
}
|
|
|
|
function bad_nonsriBlocked() {
|
|
|
|
ok(false, "Non-eligible non-SRI resources should be loaded!");
|
|
|
|
}
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
function good_nonCORSInvalidBlocked() {
|
|
|
|
ok(true, "A non-CORS resource with invalid metadata was correctly blocked.");
|
2015-08-13 06:19:16 +03:00
|
|
|
}
|
2015-09-09 10:11:38 +03:00
|
|
|
function bad_nonCORSInvalidLoaded() {
|
|
|
|
ok(false, "Non-CORS resources with invalid metadata should be blocked!");
|
2015-08-13 06:19:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
window.onerrorCalled = false;
|
|
|
|
window.onloadCalled = false;
|
|
|
|
|
|
|
|
function bad_onloadCalled() {
|
|
|
|
window.onloadCalled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function good_onerrorCalled() {
|
|
|
|
window.onerrorCalled = true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
function good_incorrect301Blocked() {
|
|
|
|
ok(true, "A non-CORS load with incorrect hash redirected to a different origin was blocked correctly.");
|
2015-08-25 23:38:39 +03:00
|
|
|
}
|
2015-09-09 10:11:38 +03:00
|
|
|
function bad_incorrect301Loaded() {
|
|
|
|
ok(false, "Non-CORS loads with incorrect hashes redirecting to a different origin should be blocked!");
|
2015-08-25 23:38:39 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
function good_correct301Blocked() {
|
|
|
|
ok(true, "A non-CORS load with correct hash redirected to a different origin was blocked correctly.");
|
2015-08-25 23:38:39 +03:00
|
|
|
}
|
2015-09-09 10:11:38 +03:00
|
|
|
function bad_correct301Loaded() {
|
|
|
|
ok(false, "Non-CORS loads with correct hashes redirecting to a different origin should be blocked!");
|
2015-08-25 23:38:39 +03:00
|
|
|
}
|
|
|
|
|
2015-08-13 06:19:16 +03:00
|
|
|
window.onload = function() {
|
|
|
|
SimpleTest.finish()
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- cors-enabled. should be loaded -->
|
|
|
|
<script src="http://example.com/tests/dom/security/test/sri/script_crossdomain1.js"
|
|
|
|
crossorigin=""
|
|
|
|
integrity="sha512-9Tv2DL1fHvmPQa1RviwKleE/jq72jgxj8XGLyWn3H6Xp/qbtfK/jZINoPFAv2mf0Nn1TxhZYMFULAbzJNGkl4Q=="></script>
|
|
|
|
|
|
|
|
<!-- not cors-enabled. should be blocked -->
|
|
|
|
<script src="http://example.com/tests/dom/security/test/sri/script_crossdomain2.js"
|
|
|
|
crossorigin="anonymous"
|
|
|
|
integrity="sha256-ntgU2U1xv7HfK1XWMTSWz6vJkyVtGzMrIAxQkux1I94="
|
|
|
|
onload="bad_onloadCalled()"
|
|
|
|
onerror="good_onerrorCalled()"></script>
|
|
|
|
|
|
|
|
<!-- non-cors but not actually using SRI. should trigger onload -->
|
|
|
|
<script src="http://example.com/tests/dom/security/test/sri/script_crossdomain3.js"
|
|
|
|
integrity=" "
|
|
|
|
onload="good_nonsriLoaded()"
|
|
|
|
onerror="bad_nonsriBlocked()"></script>
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
<!-- non-cors with invalid metadata -->
|
2015-08-13 06:19:16 +03:00
|
|
|
<script src="http://example.com/tests/dom/security/test/sri/script_crossdomain4.js"
|
|
|
|
integrity="sha256-bogus"
|
2015-09-09 10:11:38 +03:00
|
|
|
onload="bad_nonCORSInvalidLoaded()"
|
|
|
|
onerror="good_nonCORSInvalidBlocked()"></script>
|
2015-08-13 06:19:16 +03:00
|
|
|
|
2015-08-25 23:38:39 +03:00
|
|
|
<!-- non-cors that's same-origin initially but redirected to another origin -->
|
|
|
|
<script src="script_301.js"
|
|
|
|
integrity="sha384-invalid"
|
2015-09-09 10:11:38 +03:00
|
|
|
onerror="good_incorrect301Blocked()"
|
|
|
|
onload="bad_incorrect301Loaded()"></script>
|
2015-08-25 23:38:39 +03:00
|
|
|
|
|
|
|
<!-- non-cors that's same-origin initially but redirected to another origin -->
|
|
|
|
<script src="script_301.js"
|
|
|
|
integrity="sha384-1NpiDI6decClMaTWSCAfUjTdx1BiOffsCPgH4lW5hCLwmHk0VyV/g6B9Sw2kD2K3"
|
2015-09-09 10:11:38 +03:00
|
|
|
onerror="good_correct301Blocked()"
|
|
|
|
onload="bad_correct301Loaded()"></script>
|
2015-08-25 23:38:39 +03:00
|
|
|
|
2015-08-13 06:19:16 +03:00
|
|
|
<script>
|
|
|
|
ok(window.hasCORSLoaded, "CORS-enabled resource with a correct hash");
|
|
|
|
ok(!window.hasNonCORSLoaded, "Correct hash, but non-CORS, should be blocked");
|
|
|
|
ok(!window.onloadCalled, "Failed loads should not call onload when they're cross-domain");
|
|
|
|
ok(window.onerrorCalled, "Failed loads should call onerror when they're cross-domain");
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|