tor-browser

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

browser_aboutCertError_notYetValid.js (3269B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BAD_CERT_PAGE = "https://expired.example.com";
      7 const NOT_YET_VALID_CERT_PATH =
      8  "../../../../../security/manager/ssl/tests/mochitest/browser/ca.pem";
      9 
     10 function pemToBase64(pem) {
     11  return pem
     12    .replace(/-----BEGIN CERTIFICATE-----/, "")
     13    .replace(/-----END CERTIFICATE-----/, "")
     14    .replace(/\s+/g, "");
     15 }
     16 
     17 add_setup(async function () {
     18  await SpecialPowers.pushPrefEnv({
     19    set: [
     20      ["test.wait300msAfterTabSwitch", true],
     21      ["security.certerrors.felt-privacy-v1", true],
     22    ],
     23  });
     24 });
     25 
     26 add_task(async function testNotYetValidCert() {
     27  const pem = await IOUtils.readUTF8(getTestFilePath(NOT_YET_VALID_CERT_PATH));
     28  const certBase64 = pemToBase64(pem);
     29  const tab = await openErrorPage(BAD_CERT_PAGE);
     30  const browser = tab.linkedBrowser;
     31 
     32  await SpecialPowers.spawn(browser, [certBase64], async cert => {
     33    const mockErrorInfo = {
     34      errorCodeString: "MOZILLA_PKIX_ERROR_NOT_YET_VALID_CERTIFICATE",
     35      errorIsOverridable: false,
     36      channelStatus: 0,
     37      overridableErrorCategory: "expired-or-not-yet-valid",
     38      validNotBefore: Date.now() + 1000 * 1000,
     39      validNotAfter: Date.now() + 1000 * 2000,
     40      certValidityRangeNotBefore: Date.now() + 1000 * 1000,
     41      certValidityRangeNotAfter: Date.now() + 1000 * 2000,
     42      issuerCommonName: "Test CA",
     43      errorMessage: "The server presented a certificate that is not yet valid.",
     44      hasHSTS: false,
     45      hasHPKP: false,
     46      certChainStrings: [cert],
     47    };
     48 
     49    content.document.getFailedCertSecurityInfo = () => mockErrorInfo;
     50 
     51    const netErrorCard =
     52      content.document.querySelector("net-error-card").wrappedJSObject;
     53    const info = Cu.cloneInto(mockErrorInfo, netErrorCard);
     54    netErrorCard.errorInfo = info;
     55    await netErrorCard.getUpdateComplete();
     56 
     57    netErrorCard.advancedButton.scrollIntoView();
     58    EventUtils.synthesizeMouseAtCenter(
     59      netErrorCard.advancedButton,
     60      {},
     61      content
     62    );
     63 
     64    await ContentTaskUtils.waitForCondition(
     65      () => ContentTaskUtils.isVisible(netErrorCard.advancedContainer),
     66      "Advanced container is visible"
     67    );
     68 
     69    Assert.ok(
     70      netErrorCard.advancedShowing,
     71      "Advanced details are shown for not-yet-valid certificates."
     72    );
     73    Assert.ok(
     74      netErrorCard.exceptionButton,
     75      "Proceed button should be shown for not-yet-valid certificates."
     76    );
     77    Assert.equal(
     78      netErrorCard.certErrorIntro.dataset.l10nId,
     79      "fp-certerror-intro",
     80      "Using the 'certificate error' intro."
     81    );
     82    Assert.equal(
     83      netErrorCard.whyDangerous.dataset.l10nId,
     84      "fp-certerror-pkix-not-yet-valid-why-dangerous-body",
     85      "Using the 'not yet valid' variant of the 'Why Dangerous' copy."
     86    );
     87    Assert.equal(
     88      netErrorCard.whatCanYouDo.dataset.l10nId,
     89      "fp-certerror-pkix-not-yet-valid-what-can-you-do-body",
     90      "Using the 'not yet valid' variant of the 'What can you do' copy."
     91    );
     92    Assert.equal(
     93      netErrorCard.learnMoreLink.getAttribute("support-page"),
     94      "time-errors",
     95      "'Learn more' link points to the time-related errors support page."
     96    );
     97  });
     98 
     99  await BrowserTestUtils.removeTab(tab);
    100 });