File: test_break_endless_upgrade_downgrade_loop.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (92 lines) | stat: -rw-r--r-- 3,527 bytes parent folder | download | duplicates (11)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1715253
Test that same origin redirect does not cause endless loop with https-first enabled
-->

<head>
  <title>HTTPS-First-Mode - Break endless upgrade downgrade redirect loop</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>

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

  SimpleTest.waitForExplicitFinish();

  let testQueries = [
    // Those are clear downgrades. Need to load http site
    { query: "downgrade_redirect_meta", result: "http" },
    { query: "downgrade_redirect_js", result: "http" },
    { query: "downgrade_redirect_http=301", result: "http" },
    { query: "downgrade_redirect_http=302", result: "http" },
    { query: "downgrade_redirect_http=303", result: "http" },
    { query: "downgrade_redirect_http=307", result: "http" },
    // from here it isn't required to downgrade. Could be upgraded again
    { query: "redirect_meta", result: "https" },
    { query: "redirect_js", result: "https" },
    { query: "redirect_http=301", result: "https" },
    { query: "redirect_http=302", result: "https" },
    { query: "redirect_http=303", result: "https" },
    { query: "redirect_http=307", result: "https" },
  ];
  let currentTest = 0;
  // do each test two time. One time starting with https:// one time with http://
  let currentTestStartWithHttps = false;
  let testWin;
  window.addEventListener("message", receiveMessage);

  // receive message from loaded site verifying the scheme of
  // the loaded document.
  async function receiveMessage(event) {
    let currentTestParams = testQueries[Math.floor(currentTest / 2)];
    let expectedURI;
    if(currentTestParams.result == "https") {
      expectedURI = "https://example.com/tests/dom/security/test/https-first/file_downgrade_with_different_path.sjs?" + currentTestParams.query;
    } else {
      expectedURI = "http://example.com/tests/dom/security/test/https-first/file_break_endless_upgrade_downgrade_loop.sjs?" + currentTestParams.query;
    }
    is(`scheme-${currentTestParams.result}-${expectedURI}`,
       event.data.result,
       `${currentTest}: redirect results in '${currentTestParams.result}' for ${expectedURI}`
    );
    testWin.close();
    await SpecialPowers.removePermission(
      "https-only-load-insecure",
      "http://example.com"
    );
    // each test gets run starting with http:// and https://. Therefore *2 
    if (++currentTest < 2 * testQueries.length) {
      // start next case
      startTest();
      return;
    }
    // cleanup
    window.removeEventListener("message", receiveMessage);
    SimpleTest.finish();
  }

  async function startTest() {
    const currentTestParams = testQueries[Math.floor(currentTest / 2)];
    const scheme = currentTest % 2 == 0 ? "https" : "http";
    // Load an http:// window which gets upgraded to https://
    let uri =
      `${scheme}://example.com/tests/dom/security/test/https-first/file_break_endless_upgrade_downgrade_loop.sjs?${currentTestParams.query}`;
    testWin = window.open(uri);
  }

  // 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);
  </script>
</body>
</html>