summaryrefslogtreecommitdiffstats
path: root/dom/security/test/https-first/test_redirect_upgrade.html
blob: 6cccf6af671538c2ab07120f4dbcc0bf12d8dbc6 (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
53
54
55
56
57
58
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1706351
Test that 302 redirect requests get upgraded to https:// with HTTPS-First Mode enabled
-->

<head>
  <title>HTTPS-FirstMode - Redirect Upgrade</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>

<body>
  <h1>HTTPS-First Mode</h1>
  <p>Upgrade Test for insecure redirects.</p>
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1706351">Bug 1706351</a>

  <script class="testbody" type="text/javascript">
  "use strict";

  const redirectCodes = ["301", "302","303","307"];
  let currentTest = 0;
  let testWin;
  window.addEventListener("message", receiveMessage);

  // Receive message and verify that it is from an https site.
  // When the message is 'secure' then it was send by an https site.
  async function receiveMessage(event) {
    let data = event.data;
    let currentRedirectCode = redirectCodes[currentTest];
    ok(data.result === "secure", "Received 'https' for " + currentRedirectCode);
    testWin.close();
    if (++currentTest < redirectCodes.length) {
      startTest();
      return;
    }
    window.removeEventListener("message", receiveMessage);
    SimpleTest.finish();
  }

  async function startTest() {
    const currentCode = redirectCodes[currentTest];
    // Make a request to a site (eg. https://file_redirect.sjs?301), which will redirect to http://file_redirect.sjs?check.
    // The response will either be secure-ok, if the request has been upgraded to https:// or secure-error if it didn't.
    testWin = window.open(`https://example.com/tests/dom/security/test/https-first/file_redirect.sjs?${currentCode}`);
  }

  // Set preference and start test
  SpecialPowers.pushPrefEnv({ set: [
    ["dom.security.https_first", true],
    ["security.mixed_content.block_active_content", false],
    ["security.mixed_content.block_display_content", false],
  ]}, startTest);
  SimpleTest.waitForExplicitFinish();
  </script>
</body>
</html>