tor-browser

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

browser_upgrade_exemption.js (1877B)


      1 "use strict";
      2 
      3 const PAGE_WITHOUT_SCHEME = "://example.com";
      4 
      5 add_task(async function () {
      6  // Load a insecure page with HTTPS-Only and HTTPS-First disabled
      7  await runTest({
      8    loadScheme: "http",
      9    expectScheme: "http",
     10  });
     11 
     12  // Load a secure page with HTTPS-Only and HTTPS-First disabled
     13  await runTest({
     14    loadScheme: "https",
     15    expectScheme: "https",
     16  });
     17 
     18  // Load a exempted insecure page with HTTPS-Only and HTTPS-First disabled
     19  await runTest({
     20    exempt: true,
     21    loadScheme: "http",
     22    expectScheme: "http",
     23  });
     24 
     25  await SpecialPowers.pushPrefEnv({
     26    set: [["dom.security.https_only_mode", true]],
     27  });
     28 
     29  // Load a insecure page with HTTPS-Only enabled
     30  await runTest({
     31    loadScheme: "http",
     32    expectScheme: "https",
     33  });
     34 
     35  // Load a exempted insecure page with HTTPS-Only enabled
     36  await runTest({
     37    exempt: true,
     38    loadScheme: "http",
     39    expectScheme: "http",
     40  });
     41 
     42  await SpecialPowers.flushPrefEnv();
     43  await SpecialPowers.pushPrefEnv({
     44    set: [["dom.security.https_first", true]],
     45  });
     46 
     47  // Load a insecure page with HTTPS-First enabled
     48  await runTest({
     49    loadScheme: "http",
     50    expectScheme: "https",
     51  });
     52 
     53  // Load a exempted insecure page with HTTPS-First enabled
     54  await runTest({
     55    exempt: true,
     56    loadScheme: "http",
     57    expectScheme: "http",
     58  });
     59 });
     60 
     61 async function runTest(options) {
     62  const { exempt = false, loadScheme, expectScheme } = options;
     63  const page = loadScheme + PAGE_WITHOUT_SCHEME;
     64 
     65  if (exempt) {
     66    await SpecialPowers.pushPermissions([
     67      {
     68        type: "https-only-load-insecure",
     69        allow: true,
     70        context: page,
     71      },
     72    ]);
     73  }
     74 
     75  await BrowserTestUtils.withNewTab(page, async function (browser) {
     76    is(browser.currentURI.scheme, expectScheme, "Unexpected scheme");
     77    await SpecialPowers.popPermissions();
     78    await SpecialPowers.popPrefEnv();
     79  });
     80 }