summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/about/browser_aboutCertError_noSubjectAltName.js
blob: 1a2add1c9673b407290e6bb1bdbf95f2cf8111dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const BROWSER_NAME = document
  .getElementById("bundle_brand")
  .getString("brandShortName");
const UNKNOWN_ISSUER = "https://no-subject-alt-name.example.com:443";

const checkAdvancedAndGetTechnicalInfoText = async () => {
  let doc = content.document;

  let advancedButton = doc.getElementById("advancedButton");
  ok(advancedButton, "advancedButton found");
  is(
    advancedButton.hasAttribute("disabled"),
    false,
    "advancedButton should be clickable"
  );
  advancedButton.click();

  let badCertAdvancedPanel = doc.getElementById("badCertAdvancedPanel");
  ok(badCertAdvancedPanel, "badCertAdvancedPanel found");

  let badCertTechnicalInfo = doc.getElementById("badCertTechnicalInfo");
  ok(badCertTechnicalInfo, "badCertTechnicalInfo found");

  // Wait until fluent sets the errorCode inner text.
  await ContentTaskUtils.waitForCondition(() => {
    let errorCode = doc.getElementById("errorCode");
    return errorCode.textContent == "SSL_ERROR_BAD_CERT_DOMAIN";
  }, "correct error code has been set inside the advanced button panel");

  let viewCertificate = doc.getElementById("viewCertificate");
  ok(viewCertificate, "viewCertificate found");

  return badCertTechnicalInfo.innerHTML;
};

const checkCorrectMessages = message => {
  let isCorrectMessage = message.includes(
    "Websites prove their identity via certificates. " +
      BROWSER_NAME +
      " does not trust this site because it uses a certificate that is" +
      " not valid for no-subject-alt-name.example.com"
  );
  is(isCorrectMessage, true, "That message should appear");
  let isWrongMessage = message.includes("The certificate is only valid for ");
  is(isWrongMessage, false, "That message shouldn't appear");
};

add_task(async function checkUntrustedCertError() {
  info(
    `Loading ${UNKNOWN_ISSUER} which does not have a subject specified in the certificate`
  );
  let tab = await openErrorPage(UNKNOWN_ISSUER);
  let browser = tab.linkedBrowser;
  info("Clicking the exceptionDialogButton in advanced panel");
  let badCertTechnicalInfoText = await SpecialPowers.spawn(
    browser,
    [],
    checkAdvancedAndGetTechnicalInfoText
  );
  checkCorrectMessages(badCertTechnicalInfoText, browser);
  BrowserTestUtils.removeTab(gBrowser.selectedTab);
});