tor-browser

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

browser_getSecurityInfo.js (1467B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const MOZILLA_PKIX_ERROR_BASE = Ci.nsINSSErrorsService.MOZILLA_PKIX_ERROR_BASE;
      5 const MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT = MOZILLA_PKIX_ERROR_BASE + 14;
      6 
      7 add_task(async function test() {
      8  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
      9    let loaded = BrowserTestUtils.waitForErrorPage(browser);
     10    BrowserTestUtils.startLoadingURIString(
     11      browser,
     12      "https://self-signed.example.com"
     13    );
     14    await loaded;
     15    let securityInfo = gBrowser.securityUI.secInfo;
     16    ok(!securityInfo, "Found no security info");
     17 
     18    loaded = BrowserTestUtils.browserLoaded(browser);
     19    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     20    BrowserTestUtils.startLoadingURIString(browser, "http://example.com");
     21    await loaded;
     22    securityInfo = gBrowser.securityUI.secInfo;
     23    ok(!securityInfo, "Found no security info");
     24 
     25    loaded = BrowserTestUtils.browserLoaded(browser);
     26    BrowserTestUtils.startLoadingURIString(browser, "https://example.com");
     27    await loaded;
     28    securityInfo = gBrowser.securityUI.secInfo;
     29    ok(securityInfo, "Found some security info");
     30    ok(securityInfo.succeededCertChain, "Has a succeeded cert chain");
     31    is(securityInfo.errorCode, 0, "Has no error code");
     32    is(
     33      securityInfo.serverCert.commonName,
     34      "example.com",
     35      "Has the correct certificate"
     36    );
     37  });
     38 });