tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_downgrade_request_upgrade_request.html (1913B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title> Bug 1706126: Test https-first, downgrade first request and then upgrade redirection to subdomain</title>
      5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 
     10 <script class="testbody" type="text/javascript">
     11 "use strict";
     12 /*
     13 * Description of the test:
     14 * First we request http://redirect-example.com which HTTPS-First upgrades to https://redirect-example.com.
     15 * The request https://redirect-example.com doesn't receive an answer (timeout), so we send a background
     16 * request.
     17 * The background request receives an answer. So the request https://redirect-example.com gets downgraded
     18 * to http://redirect-example.com by the exempt flag on the loadinfo.
     19 * The request http://redirect-example.com gets redirected to http://wwww.redirect-example.com. At that stage
     20 * HTTPS-First should clear the exempt flag and upgrade the redirection to https://wwww.redirect-example.com.
     21 *
     22 */
     23 
     24 SimpleTest.waitForExplicitFinish();
     25 
     26 const REQUEST_URL =
     27  "http://redirect-example.com/tests/dom/security/test/https-first/file_downgrade_request_upgrade_request.sjs";
     28 
     29 let testWin;
     30 window.addEventListener("message", receiveMessage);
     31 
     32 // Receive message and verify that it is from an https site.
     33 async function receiveMessage(event) {
     34  let data = event.data;
     35  ok(data.result === "upgraded", "Redirected successful to 'https' for subdomain ");
     36  is(data.scheme,"https:", "scheme is 'https' for subdomain");
     37  testWin.close();
     38  window.removeEventListener("message", receiveMessage);
     39  await SpecialPowers.removePermission(
     40    "https-only-load-insecure",
     41    REQUEST_URL
     42  );
     43  SimpleTest.finish();
     44 }
     45 
     46 async function runTest() {
     47  testWin = window.open(REQUEST_URL, "_blank");
     48 }
     49 
     50 SpecialPowers.pushPrefEnv({ set: [
     51    ["dom.security.https_first", true]
     52  ]}, runTest);
     53 
     54 </script>
     55 </body>
     56 </html>