summaryrefslogtreecommitdiffstats
path: root/dom/security/test/https-first/test_downgrade_request_upgrade_request.html
blob: b659636acec4fba271644105f9a992c67c55b0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE HTML>
<html>
<head>
<title> Bug 1706126: Test https-first, downgrade first request and then upgrade redirection to subdomain</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";
/*
 * Description of the test:
 * First we request http://redirect-example.com which HTTPS-First upgrades to https://redirect-example.com.
 * The request https://redirect-example.com doesn't receive an answer (timeout), so we send a background
 * request.
 * The background request receives an answer. So the request https://redirect-example.com gets downgraded
 * to http://redirect-example.com by the exempt flag.
 * The request http://redirect-example.com gets redirected to http://wwww.redirect-example.com. At that stage
 * HTTPS-First should clear the exempt flag and upgrade the redirection to https://wwww.redirect-example.com.
 *
 */

SimpleTest.waitForExplicitFinish();

const REQUEST_URL =
  "http://redirect-example.com/tests/dom/security/test/https-first/file_downgrade_request_upgrade_request.sjs";

let testWin;
window.addEventListener("message", receiveMessage);

// Receive message and verify that it is from an https site.
async function receiveMessage(event) {
  let data = event.data;
  ok(data.result === "upgraded", "Redirected successful to 'https' for subdomain ");
  is(data.scheme,"https:", "scheme is 'https' for subdomain");
  testWin.close();
  window.removeEventListener("message", receiveMessage);
  SimpleTest.finish();
}

async function runTest() {
  testWin = window.open(REQUEST_URL, "_blank");
}

SpecialPowers.pushPrefEnv({ set: [
    ["dom.security.https_first", true]
  ]}, runTest);

</script>
</body>
</html>