Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: http3 OR http2
- This test failed 2 times in the preceding 30 days. quicksearch this test
- Manifest: dom/security/test/https-first/mochitest.toml
<!DOCTYPE HTML>
<html>
<!--
Test multiple redirects using https-first and ensure the entire redirect chain is using https
-->
<head>
<title>HTTPS-First-Mode - Test for multiple redirections</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
const testCase = [
{name: "test last redirect HTTP", result: "scheme-https", query: "test1" },
// expect to reach an https website.
{name: "test last redirect HTTPS", result: "scheme-https", query: "test2"},
// we expect that to reach an https site
{name: "test last redirect HSTS", result: "scheme-https", query: "test3"},
// reset: reset hsts header for example.com
{name: "reset HSTS header", result: "scheme-https", query: "reset"},
// Everything should be upgraded and accessed only via HTTPS!
{name: "test last redirect other HTTP origin gets upgraded", result: "scheme-https", query: "test4" },
// had a downgrade in the redirect chain. We load the http version
{name: "test downgrade HTTP", result: "scheme-http", query: "test5" },
]
let currentTest = 0;
let testWin;
window.addEventListener("message", receiveMessage);
// receive message from loaded site verifying the scheme of
// the loaded document.
async function receiveMessage(event) {
let test = testCase[currentTest];
is(event.data.result,
test.result,
"redirect results in " + test.name
);
testWin.close();
await SpecialPowers.removePermission(
"https-only-load-insecure",
);
if (++currentTest < testCase.length) {
startTest();
return;
}
window.removeEventListener("message", receiveMessage);
SimpleTest.finish();
}
async function startTest() {
const test = testCase[currentTest];
// Load an http:// window which gets upgraded to https://
let uri =
`http://example.com/tests/dom/security/test/https-first/file_multiple_redirection.sjs?${test.query}`;
testWin = window.open(uri);
}
// Set preference and start test
SpecialPowers.pushPrefEnv({ set: [
["dom.security.https_first", true],
]}, startTest);
</script>
</body>
</html>