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 OpenPGP signed messages, when the
* signer isn't in From.
*/
"use strict";
const {
be_in_folder,
get_about_3pane,
get_about_message,
get_special_folder,
select_click_row,
} = ChromeUtils.importESModule(
);
const { OpenPGPTestUtils } = ChromeUtils.importESModule(
);
const { PromiseTestUtils } = ChromeUtils.importESModule(
);
const { MailServices } = ChromeUtils.importESModule(
);
var gInbox;
add_setup(async function () {
await OpenPGPTestUtils.importPublicKey(
window,
new FileUtils.File(
getTestFilePath("data/keys/carol@example.com-0x3099ff1238852b9f-pub.asc")
)
);
await OpenPGPTestUtils.importPublicKey(
window,
new FileUtils.File(
getTestFilePath(
"data/keys/alice@openpgp.example-0xf231550c4f47e38e-pub.asc"
)
)
);
gInbox = await get_special_folder(Ci.nsMsgFolderFlags.Inbox, true);
await be_in_folder(gInbox);
registerCleanupFunction(async function () {
await OpenPGPTestUtils.removeKeyById("0x3099ff1238852b9f");
await OpenPGPTestUtils.removeKeyById("0xf231550c4f47e38e");
gInbox.deleteMessages([...gInbox.messages], null, true, false, null, false);
});
});
/**
* 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 OpenPGP signed state. For
* "notok", "mismatch" and "unknown" no signed icon is shown, otherwise the
* icon for that state is.
* @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
);
await TestUtils.waitForCondition(
() => aboutMessage.Enigmail.hdrView.msgSignedStateString == signed,
`${file}: the signed state should be ${signed}`
);
if (["notok", "mismatch", "unknown"].includes(signed)) {
Assert.ok(
OpenPGPTestUtils.hasNoSignedIconState(aboutMessage.document),
`${file}: signed icon should be hidden`
);
} else {
Assert.ok(
OpenPGPTestUtils.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 testOpenPGPUnobtrusiveSignedBySender() {
await checkSenderShown([
{
file: "data/eml/unob-signed-group-from-with-sender.eml",
signed: "verified",
sender: "carol@example.com",
},
{
file: "data/eml/unob-signed-with-other-sender.eml",
signed: "verified",
sender: null,
},
]);
});
add_task(async function testOpenPGPMimeSignedBySender() {
await checkSenderShown([
{
file: "data/eml/signed-by-0x3099ff1238852b9f-from-bob-with-sender.eml",
signed: "mismatch",
sender: "carol@example.com",
},
{
file: "data/eml/signed-by-0x3099ff1238852b9f-with-other-sender.eml",
signed: "verified",
sender: null,
},
{
file: "data/eml/signed-by-0x3099ff1238852b9f-from-bob-with-other-sender.eml",
signed: "mismatch",
sender: null,
},
]);
});
add_task(async function testOpenPGPInlineSignedBySender() {
await checkSenderShown([
{
file: "data/eml/alice-signed-from-bob-with-sender.eml",
signed: "mismatch",
sender: "alice@openpgp.example",
},
{
file: "data/eml/alice-signed-with-other-sender.eml",
signed: "verified",
sender: null,
},
]);
});