Commit 6b3e1ea5 authored by Patrick Brunschwig's avatar Patrick Brunschwig

completed re-implementation of new persistent decryption/encryption

parent 74648654
Pipeline #66381083 failed with stage
in 60 minutes
This diff is collapsed.
......@@ -12,7 +12,7 @@
do_load_module("file://" + do_get_cwd().path + "/testHelper.js"); /*global TestHelper: false, component: false, withTestGpgHome: false, withEnigmail: false */
TestHelper.loadDirectly("tests/mailHelper.js"); /*global MailHelper: false */
testing("persistentCrypto.jsm"); /*global EnigmailPersistentCrypto: false, Promise: false */
testing("persistentCrypto.jsm"); /*global EnigmailPersistentCrypto: false, Promise: false, EnigmailMime: false */
var EnigmailKeyRing = component("enigmail/keyRing.jsm").EnigmailKeyRing;
/*global MsgHdrToMimeMessage: false, MimeMessage: false, MimeContainer: false, EnigmailStreams: false */
......@@ -70,7 +70,7 @@ test(withTestGpgHome(withEnigmail(function messageIsMovedAndDecrypted() {
loadSecretKey();
MailHelper.cleanMailFolder(MailHelper.rootFolder);
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email.eml", sourceFolder);
MailHelper.loadEmailToMailFolder("resources/encrypted-pgpmime-email.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
......@@ -85,20 +85,29 @@ test(withTestGpgHome(withEnigmail(function messageIsMovedAndDecrypted() {
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
MsgHdrToMimeMessage(
dispatchedHeader,
null,
function(header, mime) {
Assert.ok(!mime.isEncrypted);
Assert.assertContains(mime.parts[0].body, "This is encrypted");
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.equal(mimeTree.subParts.length, 1);
if (mimeTree.subParts.length > 0) {
Assert.assertContains(mimeTree.subParts[0].body, "This message is encrypted");
}
do_test_finished();
},
false
);
})));
/*
test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndDecrypted() {
loadSecretKey();
loadPublicKey();
......@@ -118,23 +127,71 @@ test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndDecryp
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
MsgHdrToMimeMessage(
dispatchedHeader,
null,
function(header, mime) {
Assert.ok(!mime.isEncrypted);
Assert.assertContains(mime.parts[0].parts[0].body, "This is encrypted");
const atts = extractAttachments(mime);
Assert.ok(!atts[0].isEncrypted);
Assert.assertContains(atts[0].body, "This is an attachment.");
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.assertContains(mimeTree.subParts[0].body, "This is encrypted");
Assert.equal(mimeTree.subParts.length, 2);
if (mimeTree.subParts.length >= 2) {
Assert.assertContains(mimeTree.subParts[1].body, "This is an attachment.");
}
do_test_finished();
},
false
);
})));
*/
test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndReEncrypted() {
loadSecretKey();
loadPublicKey();
MailHelper.cleanMailFolder(MailHelper.getRootFolder());
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email-with-attachment.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
const move = true;
copyListener.OnStopCopy = function(statusCode) {
inspector.exitNestedEventLoop();
};
let keyObj = EnigmailKeyRing.getKeyById("0x65537E212DC19025AD38EDB2781617319CE311C4");
EnigmailPersistentCrypto.dispatchMessages([header], targetFolder.URI, copyListener, move, keyObj);
inspector.enterNestedEventLoop(0);
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.assertContains(mimeTree.headers._rawHeaders.get("content-type")[0], "multipart/encrypted");
Assert.assertContains(mimeTree.subParts[0].body, "Version: 1");
Assert.equal(mimeTree.subParts.length, 2);
if (mimeTree.subParts.length >= 2) {
Assert.assertContains(mimeTree.subParts[1].body, "---BEGIN PGP MESSAGE---");
}
do_test_finished();
},
false
);
})));
var loadSecretKey = function() {
const secretKey = do_get_file("resources/dev-strike.sec", false);
......
To: Tester 2 <example@domain.invalid>
From: Tester 1 <tester@enigmail.org>
Message-ID: <3299853e-ad1b-236e-e4c1-ecbb266c26cb@gmail.com>
Date: Tue, 19 Jun 2018 23:39:32 +0530
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0)
Gecko/20100101 Thunderbird/52.8.0
MIME-Version: 1.0
Subject: Encrypted Message
Content-Type: multipart/encrypted;
protocol="application/pgp-encrypted";
boundary="UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4"
This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4
Content-Type: application/pgp-encrypted
Content-Description: PGP/MIME version identification
Version: 1
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4
Content-Type: application/octet-stream; name="encrypted.asc"
Content-Description: OpenPGP encrypted message
Content-Disposition: inline; filename="encrypted.asc"
-----BEGIN PGP MESSAGE-----
hQIMA9U1Yju2Dp5xAQ/6AnDaC/oxD65YSD6I1e5JX3vAzOgB0TL4eTPabl/KZJ6K
8eAWiZubWF7i/EWlEXOYZbWycZC0Vo0mUlSiye4EXB/dnY369r/2UIF6kAEW0d7J
LwMbmg0WMcL+liZSa7HyxajYn8Zb7CohNI4l41KjjYGAbKiJNaK442eEvAQ3fuNp
5/KvV10jwS6fGV3caouTa8aCT8r2U5FdxowuYGGvazLCfPI9aTnz84JgeTutZfW5
B/yBBNDeRxmUEa9c3k+8aH9c5DKYBH4Chp5EMfvlTE/pZdhRd2RcTZsR637FQVgO
FpTHKvOqQNJla4WqGeH9iHOLJh9OAhHkRaiMbbo+072KfwNHqDD4iwjQ04jFIph1
zImMJg79PTgSsjcTRTdvkQiHaIx7pVW1m212JEl4km1lmT/C6NCHxTYfNLooEAs1
6YPbaARnbFTTWjJXfEto7s2PZoX1pZ7GG1MNVpAL6J/puUnmVktj+87bJLkxHQVu
wf3Qq+vcFqB5t63quPMbGbXnHh4P9V+ceWhUhNFSutKWcCmeQL4vxCtL9eOphHEb
1YDHb4FpSlpVJyVUmLh7g/1X3IMCS1HKpiIqJHAUu4FfouAprL5CAfFmCeCRMkqs
/4iR3KtpnwRPwNDgY8Gfy7CL0IdvWZdpyLFaFOPr604Kz2JsJwyxbu1opM3acILS
bgFYYz3p3HwqnGdbnch3+5H3XEToOaeXsH51zSUkR/oq/wNXDWKMKiU5hIUkHYq1
NsC04Y4EHsbpDPo/GqkcdXEx7Dg0sgohqYqoU+iyq+jjyOEZxNEUdboMadxIm879
nu672xjC+wg8rBvFr8jh
=q7pm
-----END PGP MESSAGE-----
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4--
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment