Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
/**
* Tests that the Sender header is shown for S/MIME signed messages, when it
* was Sender and not From who signed the message.
*/
"use strict";
const {
be_in_folder,
get_about_3pane,
get_about_message,
get_special_folder,
select_click_row,
} = ChromeUtils.importESModule(
);
const { PromiseTestUtils } = ChromeUtils.importESModule(
);
const { SmimeUtils } = ChromeUtils.importESModule(
);
const { MailServices } = ChromeUtils.importESModule(
);
var gInbox;
add_setup(async function () {
SmimeUtils.ensureNSS();
SmimeUtils.loadPEMCertificate(
new FileUtils.File(getTestFilePath("data/TestCA.pem")),
Ci.nsIX509Cert.CA_CERT
);
gInbox = await get_special_folder(Ci.nsMsgFolderFlags.Inbox, true);
await be_in_folder(gInbox);
registerCleanupFunction(async function () {
await SmimeUtils.removeCertificates(["NSS Test CA (RSA)"]);
gInbox.deleteMessages([...gInbox.messages], null, true, false, null, false);
});
});
function hasSignedIconState(doc, state) {
return !!doc.querySelector(`#signedHdrIcon[src*=message-signed-${state}]`);
}
/**
* Copy the given messages to the inbox, then select them one by one, in the
* same order, and check whether the Sender header is shown.
*
* @param {object[]} messages
* @param {string} messages[].file - Path of the message file.
* @param {string} messages[].signed - The expected signed icon state, or
* "mismatch" if the signer isn't in From, in which case no icon is shown.
* @param {?string} messages[].sender - The Sender address expected to be
* shown, or null if the Sender header should be hidden.
*/
async function checkSenderShown(messages) {
const keys = [];
for (const { file } of messages) {
const copyListener = new PromiseTestUtils.PromiseCopyListener();
MailServices.copy.copyFileMessage(
new FileUtils.File(getTestFilePath(file)),
gInbox,
null,
false,
0,
"",
copyListener,
null
);
const { messageKeys } = await copyListener.promise;
keys.push(messageKeys[0]);
}
const about3Pane = get_about_3pane();
const aboutMessage = get_about_message();
const senderRow = aboutMessage.document.getElementById("expandedsenderRow");
for (const [i, { file, signed, sender }] of messages.entries()) {
const hdr = gInbox.msgDatabase.getMsgHdrForKey(keys[i]);
await select_click_row(
about3Pane.gDBView.findIndexOfMsgHdr(hdr, true),
AccessibilityUtils
);
if (signed == "mismatch") {
await TestUtils.waitForCondition(
() =>
aboutMessage.gSignatureStatus ==
Ci.nsICMSMessageErrors.VERIFY_HEADER_MISMATCH,
`${file}: the signature should be reported as a From mismatch`
);
Assert.ok(
aboutMessage.document.getElementById("signedHdrIcon").hidden,
`${file}: signed icon should be hidden`
);
} else {
await TestUtils.waitForCondition(
() => hasSignedIconState(aboutMessage.document, signed),
`${file}: signed icon should be ${signed}`
);
}
if (sender) {
await TestUtils.waitForCondition(
() => BrowserTestUtils.isVisible(senderRow),
`${file}: the Sender header should be shown`
);
Assert.stringContains(
senderRow.textContent,
sender,
`${file}: the Sender header should show the signer`
);
} else {
Assert.ok(
BrowserTestUtils.isHidden(senderRow),
`${file}: the Sender header should be hidden`
);
}
}
}
add_task(async function testSmimeSignedBySender() {
await checkSenderShown([
{
file: "data/alice.groupfrom.dsig.SHA256.multipart.eml",
signed: "ok",
sender: "Alice@example.com",
},
{
file: "data/alice.bobsender.dsig.SHA256.multipart.eml",
signed: "ok",
sender: null,
},
{
file: "data/alice.bobfrom.dsig.SHA256.multipart.eml",
signed: "mismatch",
sender: "Alice@example.com",
},
{
file: "data/alice.bobfrom.carolsender.dsig.SHA256.multipart.eml",
signed: "mismatch",
sender: null,
},
]);
});