tor-browser

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

browser_identityPopup_qwacs.js (5962B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /* Test that the QWACs indicator appears as appropriate in the site identity
      5 * drop-down. */
      6 
      7 add_setup(async function () {
      8  await SpecialPowers.pushPrefEnv({
      9    set: [["security.qwacs.enable_test_trust_anchors", true]],
     10  });
     11 });
     12 
     13 add_task(async function test_1_qwac() {
     14  await BrowserTestUtils.withNewTab(
     15    "https://1-qwac.example.com",
     16    async function () {
     17      let promisePanelOpen = BrowserTestUtils.waitForEvent(
     18        window,
     19        "popupshown",
     20        true,
     21        event => event.target == gIdentityHandler._identityPopup
     22      );
     23 
     24      gIdentityHandler._identityIconBox.click();
     25      await promisePanelOpen;
     26 
     27      // Wait for the QWAC status to be determined.
     28      await gIdentityHandler._qwacStatusPromise;
     29 
     30      let securityView = document.getElementById("identity-popup-securityView");
     31      let shown = BrowserTestUtils.waitForEvent(securityView, "ViewShown");
     32      document.getElementById("identity-popup-security-button").click();
     33      await shown;
     34 
     35      let qualifiedText = document.getElementById(
     36        "identity-popup-content-etsi"
     37      );
     38      ok(
     39        BrowserTestUtils.isVisible(qualifiedText),
     40        "etsi qualified text visible"
     41      );
     42 
     43      let issuedToLabel = document.getElementById(
     44        "identity-popup-content-owner-label"
     45      );
     46      ok(
     47        BrowserTestUtils.isVisible(issuedToLabel),
     48        "'Certificate issued to:' label visible"
     49      );
     50 
     51      let qwacOrganization = document.getElementById(
     52        "identity-popup-content-owner"
     53      );
     54      ok(
     55        BrowserTestUtils.isVisible(qwacOrganization),
     56        "QWAC organization text visible"
     57      );
     58      is(
     59        qwacOrganization.textContent,
     60        "Test 1-QWAC Organization",
     61        "QWAC organization text as expected"
     62      );
     63 
     64      let qwacLocation = document.getElementById(
     65        "identity-popup-content-supplemental"
     66      );
     67      ok(
     68        BrowserTestUtils.isVisible(qwacLocation),
     69        "QWAC location text visible"
     70      );
     71      is(
     72        qwacLocation.textContent,
     73        "1-QWAC Test Locality\nEX",
     74        "QWAC location text as expected"
     75      );
     76    }
     77  );
     78 });
     79 
     80 add_task(async function test_2_qwac() {
     81  let boundBy2QwacUri =
     82    getRootDirectory(gTestPath).replace(
     83      "chrome://mochitests/content",
     84      "https://bound-by-2-qwac.example.com"
     85    ) + "2-qwac.html";
     86 
     87  await BrowserTestUtils.withNewTab(boundBy2QwacUri, async function () {
     88    let promisePanelOpen = BrowserTestUtils.waitForEvent(
     89      window,
     90      "popupshown",
     91      true,
     92      event => event.target == gIdentityHandler._identityPopup
     93    );
     94 
     95    gIdentityHandler._identityIconBox.click();
     96    await promisePanelOpen;
     97 
     98    // Wait for the QWAC status to be determined.
     99    await gIdentityHandler._qwacStatusPromise;
    100 
    101    let securityView = document.getElementById("identity-popup-securityView");
    102    let shown = BrowserTestUtils.waitForEvent(securityView, "ViewShown");
    103    document.getElementById("identity-popup-security-button").click();
    104    await shown;
    105 
    106    let qualifiedText = document.getElementById("identity-popup-content-etsi");
    107    ok(
    108      BrowserTestUtils.isVisible(qualifiedText),
    109      "etsi qualified text visible"
    110    );
    111 
    112    let issuedToLabel = document.getElementById(
    113      "identity-popup-content-owner-label"
    114    );
    115    ok(
    116      BrowserTestUtils.isVisible(issuedToLabel),
    117      "'Certificate issued to:' label visible"
    118    );
    119 
    120    let qwacOrganization = document.getElementById(
    121      "identity-popup-content-owner"
    122    );
    123    ok(
    124      BrowserTestUtils.isVisible(qwacOrganization),
    125      "QWAC organization text visible"
    126    );
    127    is(
    128      qwacOrganization.textContent,
    129      "Test 2-QWAC Organization",
    130      "QWAC organization text as expected"
    131    );
    132 
    133    let qwacLocation = document.getElementById(
    134      "identity-popup-content-supplemental"
    135    );
    136    ok(BrowserTestUtils.isVisible(qwacLocation), "QWAC location text visible");
    137    is(
    138      qwacLocation.textContent,
    139      "2-QWAC Test Locality\nEX",
    140      "QWAC location text as expected"
    141    );
    142  });
    143 });
    144 
    145 // Also check that there are conditions where this isn't shown.
    146 add_task(async function test_non_qwac() {
    147  let uris = [
    148    "https://example.com",
    149    "https://example.com",
    150    "data:,Hello%2C World!",
    151  ];
    152  for (let uri of uris) {
    153    await BrowserTestUtils.withNewTab(uri, async function () {
    154      let promisePanelOpen = BrowserTestUtils.waitForEvent(
    155        window,
    156        "popupshown",
    157        true,
    158        event => event.target == gIdentityHandler._identityPopup
    159      );
    160 
    161      gIdentityHandler._identityIconBox.click();
    162      await promisePanelOpen;
    163 
    164      // Wait for the QWAC status to be determined.
    165      await gIdentityHandler._qwacStatusPromise;
    166 
    167      let securityView = document.getElementById("identity-popup-securityView");
    168      let shown = BrowserTestUtils.waitForEvent(securityView, "ViewShown");
    169      document.getElementById("identity-popup-security-button").click();
    170      await shown;
    171 
    172      let qualifiedText = document.getElementById(
    173        "identity-popup-content-etsi"
    174      );
    175      ok(
    176        !BrowserTestUtils.isVisible(qualifiedText),
    177        "etsi qualified text not visible"
    178      );
    179 
    180      let issuedToLabel = document.getElementById(
    181        "identity-popup-content-owner-label"
    182      );
    183      ok(
    184        !BrowserTestUtils.isVisible(issuedToLabel),
    185        "'Certificate issued to:' label not visible"
    186      );
    187 
    188      let qwacOrganization = document.getElementById(
    189        "identity-popup-content-owner"
    190      );
    191      ok(
    192        !BrowserTestUtils.isVisible(qwacOrganization),
    193        "QWAC organization text not visible"
    194      );
    195 
    196      let qwacLocation = document.getElementById(
    197        "identity-popup-content-supplemental"
    198      );
    199      ok(
    200        !BrowserTestUtils.isVisible(qwacLocation),
    201        "QWAC location text not visible"
    202      );
    203    });
    204  }
    205 });