tor-browser

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

browser_aboutNetError_invalid_cert_noUserFix.js (3315B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_setup(async function () {
      7  await SpecialPowers.pushPrefEnv({
      8    set: [["test.wait300msAfterTabSwitch", true]],
      9  });
     10 });
     11 
     12 const BAD_CERT = "https://expired.example.com/";
     13 
     14 add_task(async function checkNoUserFixCertErrors() {
     15  await setSecurityCertErrorsFeltPrivacyToTrue();
     16  const tab = await openErrorPage(BAD_CERT);
     17  const browser = tab.linkedBrowser;
     18 
     19  await SpecialPowers.spawn(browser, [], async function () {
     20    const noUserFixErrors = [
     21      "SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION",
     22      "MOZILLA_PKIX_ERROR_INVALID_INTEGER_ENCODING",
     23      "MOZILLA_PKIX_ERROR_ISSUER_NO_LONGER_TRUSTED",
     24      "MOZILLA_PKIX_ERROR_KEY_PINNING_FAILURE",
     25      "MOZILLA_PKIX_ERROR_SIGNATURE_ALGORITHM_MISMATCH",
     26      "SEC_ERROR_BAD_DER",
     27      "SEC_ERROR_BAD_SIGNATURE",
     28      "SEC_ERROR_CERT_NOT_IN_NAME_SPACE",
     29      "SEC_ERROR_EXTENSION_VALUE_INVALID",
     30      "SEC_ERROR_INADEQUATE_CERT_TYPE",
     31      "SEC_ERROR_INADEQUATE_KEY_USAGE",
     32      "SEC_ERROR_INVALID_KEY",
     33      "SEC_ERROR_PATH_LEN_CONSTRAINT_INVALID",
     34      "SEC_ERROR_UNSUPPORTED_EC_POINT_FORM",
     35      "SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE",
     36      "SEC_ERROR_UNSUPPORTED_KEYALG",
     37      "SEC_ERROR_UNTRUSTED_CERT",
     38    ];
     39 
     40    content.document.getFailedCertSecurityInfo = () => ({
     41      errorCodeString: "",
     42    });
     43 
     44    const netErrorCard =
     45      content.document.querySelector("net-error-card").wrappedJSObject;
     46 
     47    for (const errorCode of noUserFixErrors) {
     48      const mockErrorInfo = {
     49        errorCodeString: errorCode,
     50        errorIsOverridable: false,
     51      };
     52      const info = Cu.cloneInto(mockErrorInfo, netErrorCard);
     53      netErrorCard.errorInfo = info;
     54      netErrorCard.advancedShowing = false;
     55      netErrorCard.hideExceptionButton = netErrorCard.shouldHideExceptionButton(
     56        info.errorCodeString
     57      );
     58      netErrorCard.showCustomNetErrorCard = false;
     59      netErrorCard.requestUpdate();
     60      await netErrorCard.getUpdateComplete();
     61 
     62      const advancedButton = netErrorCard.advancedButton;
     63      advancedButton.scrollIntoView(true);
     64      EventUtils.synthesizeMouseAtCenter(advancedButton, {}, content);
     65 
     66      await ContentTaskUtils.waitForCondition(
     67        () => netErrorCard.advancedContainer,
     68        `Advanced section should be rendered for ${errorCode}.`
     69      );
     70      await ContentTaskUtils.waitForCondition(
     71        () => netErrorCard.whyDangerous,
     72        `The 'Why Dangerous' copy should be rendered for ${errorCode}.`
     73      );
     74      const l10nId = netErrorCard.getNSSErrorWhyDangerousL10nId(
     75        netErrorCard.whyDangerous.dataset.l10nId
     76      );
     77 
     78      Assert.ok(
     79        netErrorCard.advancedShowing,
     80        `Advanced details are shown for ${errorCode}.`
     81      );
     82      Assert.ok(
     83        !netErrorCard.exceptionButton,
     84        `Proceed button should not be shown for ${errorCode}.`
     85      );
     86      Assert.notEqual(
     87        netErrorCard.whyDangerous.innerHTML.trim(),
     88        "",
     89        `Advanced string exists for ${errorCode}.`
     90      );
     91      Assert.equal(
     92        netErrorCard.whyDangerous.dataset.l10nId,
     93        l10nId,
     94        `Using the correct copy for ${errorCode}.`
     95      );
     96    }
     97  });
     98 
     99  BrowserTestUtils.removeTab(tab);
    100  await SpecialPowers.popPrefEnv();
    101 });