1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/publicdomain/zero/1.0/
5 // Tests that the UI for editing the trust of a CA certificate correctly
6 // reflects trust in the cert DB, and correctly updates trust in the cert DB
9 var gCertDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
14 * The cert we're editing the trust of.
21 * Opens the cert trust editing dialog.
24 * A promise that resolves when the dialog has finished loading with
25 * the window of the opened dialog.
27 function openEditCertTrustDialog() {
28 let win = window.openDialog(
29 "chrome://pippki/content/editcacert.xhtml",
34 return new Promise(resolve => {
38 executeSoon(() => resolve(win));
45 add_setup(async function () {
46 // Initially trust ca.pem for SSL but not e-mail.
47 gCert = await readCertificate("ca.pem", "CT,,");
49 gCertDB.isCertTrusted(
51 Ci.nsIX509Cert.CA_CERT,
52 Ci.nsIX509CertDB.TRUSTED_SSL
54 "Sanity check: ca.pem should be trusted for SSL"
57 !gCertDB.isCertTrusted(
59 Ci.nsIX509Cert.CA_CERT,
60 Ci.nsIX509CertDB.TRUSTED_EMAIL
62 "Sanity check: ca.pem should not be trusted for e-mail"
66 // Tests the following:
67 // 1. The checkboxes correctly reflect the trust set in setup().
68 // 2. Accepting the dialog after flipping some of the checkboxes results in the
69 // correct trust being set in the cert DB.
70 add_task(async function testAcceptDialog() {
71 let win = await openEditCertTrustDialog();
73 let sslCheckbox = win.document.getElementById("trustSSL");
74 let emailCheckbox = win.document.getElementById("trustEmail");
75 Assert.ok(sslCheckbox.checked, "Cert should be trusted for SSL in UI");
77 !emailCheckbox.checked,
78 "Cert should not be trusted for e-mail in UI"
81 sslCheckbox.checked = false;
82 emailCheckbox.checked = true;
84 info("Accepting dialog");
85 win.document.getElementById("editCaCert").acceptDialog();
86 await BrowserTestUtils.windowClosed(win);
89 !gCertDB.isCertTrusted(
91 Ci.nsIX509Cert.CA_CERT,
92 Ci.nsIX509CertDB.TRUSTED_SSL
94 "Cert should no longer be trusted for SSL"
97 gCertDB.isCertTrusted(
99 Ci.nsIX509Cert.CA_CERT,
100 Ci.nsIX509CertDB.TRUSTED_EMAIL
102 "Cert should now be trusted for e-mail"
106 // Tests the following:
107 // 1. The checkboxes correctly reflect the trust set in testAcceptDialog().
108 // 2. Canceling the dialog even after flipping the checkboxes doesn't result in
109 // a change of trust in the cert DB.
110 add_task(async function testCancelDialog() {
111 let win = await openEditCertTrustDialog();
113 let sslCheckbox = win.document.getElementById("trustSSL");
114 let emailCheckbox = win.document.getElementById("trustEmail");
115 Assert.ok(!sslCheckbox.checked, "Cert should not be trusted for SSL in UI");
116 Assert.ok(emailCheckbox.checked, "Cert should be trusted for e-mail in UI");
118 sslCheckbox.checked = true;
119 emailCheckbox.checked = false;
121 info("Canceling dialog");
122 win.document.getElementById("editCaCert").cancelDialog();
123 await BrowserTestUtils.windowClosed(win);
126 !gCertDB.isCertTrusted(
128 Ci.nsIX509Cert.CA_CERT,
129 Ci.nsIX509CertDB.TRUSTED_SSL
131 "Cert should still not be trusted for SSL"
134 gCertDB.isCertTrusted(
136 Ci.nsIX509Cert.CA_CERT,
137 Ci.nsIX509CertDB.TRUSTED_EMAIL
139 "Cert should still be trusted for e-mail"