tor-browser

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

test_downgrade_bad_responses.html (1931B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>Bug 1709552 : HTTPS-First: Add downgrade tests for bad responses to https request </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 * We perform five tests where we expect https-first to detect
     15 * that the target site only supports http
     16 * Test 1: 400 Response
     17 * Test 2: 401 Response
     18 * Test 3: 403 Response
     19 * Test 4: 416 Response
     20 * Test 5: 418 Response
     21 * Test 6: Timeout
     22 */
     23 
     24 SimpleTest.waitForExplicitFinish();
     25 
     26 const REQUEST_URL =
     27  "http://example.com/tests/dom/security/test/https-first/file_downgrade_bad_responses.sjs";
     28 
     29 const redirectQueries = ["?test1a", "?test2a","?test3a", "?test4a", "?test5a", "?test6a"];
     30 let currentTest = 0;
     31 let testWin;
     32 let currentQuery;
     33 window.addEventListener("message", receiveMessage);
     34 
     35 // Receive message and verify that it is from an http site.
     36 // When the message is 'downgraded' then it was send by an http site
     37 // and the redirection worked.
     38 async function receiveMessage(event) {
     39  let data = event.data;
     40  currentQuery = redirectQueries[currentTest];
     41  ok(data.result === "downgraded", "Redirected successful to 'http' for " + currentQuery);
     42  ok(data.scheme === "http", "scheme is 'http' for " + currentQuery );
     43  testWin.close();
     44  await SpecialPowers.removePermission(
     45    "https-only-load-insecure",
     46    REQUEST_URL
     47  );
     48  if (++currentTest < redirectQueries.length) {
     49    runTest();
     50    return;
     51  }
     52  window.removeEventListener("message", receiveMessage);
     53  SimpleTest.finish();
     54 }
     55 
     56 async function runTest() {
     57  currentQuery = redirectQueries[currentTest];
     58  testWin = window.open(REQUEST_URL + currentQuery, "_blank");
     59 }
     60 
     61 SpecialPowers.pushPrefEnv({ set: [
     62    ["dom.security.https_first", true]
     63  ]}, runTest);
     64 
     65 </script>
     66 </body>
     67 </html>