Commit cb437413 authored by Ola Bini's avatar Ola Bini

Add all test cases we have. They won't run correctly until the rest of

the commits are pushed.

Contribution from Fan Jiang, Iván Pazmiño and Ola Bini.
parent b08f6493
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false, component: false, Cc: false, Ci: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
do_load_module("file://" + do_get_cwd().path + "/testHelper.js");
testing("armor.jsm"); /*global Armor: false */
test(function shouldLocateArmoredBlock() {
const text = "" +
" -----BEGIN PGP SIGNATURE-----\n" +
" Version: GnuPG/MacGPG2 v2.0.22 (Darwin)\n" +
" Comment: GPGTools - https://gpgtools.org\n" +
"\n" +
" iQIcBAEBCgAGBQJVSkxrAAoJEFco/AmgID3sm68QALBa6I6r7LLopA8R+S/CpO66\n" +
" 6qQm0zidQ7bhMDNiKPD+/TG/Blvu0n10Cnt5Wk6lD7dwPKAsHVq1fGUva4rkEbi4\n" +
" R9nx7BQGBiFCpYl3K1bHJ/QrnYms5wpKseqGtW+8wq8wKx68sWi83xsKN2Ml2SGA\n" +
" 95nvbvaQ6yQlynGXhPhGhdT3L2tdPsulnSwnd3NZJ83U73aYIN5jc5+UyWduLqho\n" +
" xnD127JQYb8X2UjdXyOnA/E/VHvCWt9+Ck9s6VdwUSEBs41vJ/kyrmPE6u9sIQX7\n" +
" 9ZujMzN05+9A1Mtwp4dsDIbLMeX6FS44CqcGiUKzyx5ewiYq9lcAReM52i+4kmBM\n" +
" 4B/yLXDrWWOBiUCUQaOWC8PyBAc2cHLf62m6+oEfEMMCXli/XZuBC442qYuWNgf+\n" +
" yLLhyaA27rqMxmhdFtKSOzrRaxkTTb1oQFQwHYfeHT7kFpPjq4p1Jv+p8w0pcq0P\n" +
" j5hiLABLveEcLn4fEpqLROdi/Vz6Mp2nnbhcz+xe/w2KWmGgfl/kg2T/9YVeLox9\n" +
" kaqVqNezYPfFZ1iQgGKNBXl1SMqHtTRAvHfH1k0E8qg3t222KU2pALp0A/LSvu/T\n" +
" P3g8OIpqWRI0uBZQ/Gp/S1Fjb3DHfE+Y3IhVf5SkhjIYIvViSrbGqGUmK+jwGMia\n" +
" o29CFuiGhiz3ISDRKrtH\n" +
" =MeaY\n" +
" -----END PGP SIGNATURE-----";
const beginIndexObj = {};
const endIndexObj = {};
const indentStrObj = {};
const indentStr = "";
const blockType = Armor.locateArmoredBlock(text, 0, indentStr, beginIndexObj, endIndexObj, indentStrObj);
Assert.equal(0, beginIndexObj.value);
Assert.equal(" ", indentStrObj.value);
Assert.equal("SIGNATURE", blockType);
});
test(function shouldExtractSignaturePart() {
const signature = {
text: "Hello I'm here.\n please contact me via this email! \n",
header: "Version: GnuPG/MacGPG2 v2.0.22 (Darwin)\n" +
"Comment: GPGTools - https://gpgtools.org\n",
armor: "iQIcBAEBCgAGBQJVSkxrAAoJEFco/AmgID3sm68QALBa6I6r7LLopA8R+S/CpO66\n" +
"6qQm0zidQ7bhMDNiKPD+/TG/Blvu0n10Cnt5Wk6lD7dwPKAsHVq1fGUva4rkEbi4\n" +
"R9nx7BQGBiFCpYl3K1bHJ/QrnYms5wpKseqGtW+8wq8wKx68sWi83xsKN2Ml2SGA\n" +
"95nvbvaQ6yQlynGXhPhGhdT3L2tdPsulnSwnd3NZJ83U73aYIN5jc5+UyWduLqho\n" +
"xnD127JQYb8X2UjdXyOnA/E/VHvCWt9+Ck9s6VdwUSEBs41vJ/kyrmPE6u9sIQX7\n" +
"9ZujMzN05+9A1Mtwp4dsDIbLMeX6FS44CqcGiUKzyx5ewiYq9lcAReM52i+4kmBM\n" +
"4B/yLXDrWWOBiUCUQaOWC8PyBAc2cHLf62m6+oEfEMMCXli/XZuBC442qYuWNgf+\n" +
"yLLhyaA27rqMxmhdFtKSOzrRaxkTTb1oQFQwHYfeHT7kFpPjq4p1Jv+p8w0pcq0P\n" +
"j5hiLABLveEcLn4fEpqLROdi/Vz6Mp2nnbhcz+xe/w2KWmGgfl/kg2T/9YVeLox9\n" +
"kaqVqNezYPfFZ1iQgGKNBXl1SMqHtTRAvHfH1k0E8qg3t222KU2pALp0A/LSvu/T\n" +
"P3g8OIpqWRI0uBZQ/Gp/S1Fjb3DHfE+Y3IhVf5SkhjIYIvViSrbGqGUmK+jwGMia\n" +
"o29CFuiGhiz3ISDRKrtH\n" +
"=MeaY"
};
const signature_block = "\n\n" +
signature.text +
"-----BEGIN PGP SIGNATURE-----\n" +
signature.header +
"\n" +
signature.armor +
"\n" +
"-----END PGP SIGNATURE-----";
const signature_text = Armor.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_TEXT);
const signature_headers = Armor.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_HEADERS);
const signature_armor = Armor.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_ARMOR);
Assert.equal(signature.text, signature_text);
Assert.equal(signature.header, signature_headers);
Assert.equal(signature.armor.replace(/\s*/g, ""), signature_armor);
});
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
const CustomAssert = {
registerExtraAssertionsOn: function(assertModule) {
assertModule.assertContains = CustomAssert.assertContains;
assertModule.assertArrayContains = CustomAssert.assertArrayContains;
assertModule.assertArrayNotContains = CustomAssert.assertArrayNotContains;
},
assertContains: function(actual, expected, message) {
var msg = message || "Searching for <".concat(expected)
.concat("> to be contained within ")
.concat("<").concat(actual).concat(">");
this.report(actual.search(expected) == -1, actual, expected, message, "contains");
},
assertArrayContains: function(array, value, message) {
this.report(array.indexOf(value) == -1, array, value, message, "contains");
},
assertArrayNotContains: function(array, value, message) {
this.report(array.indexOf(value) > -1, array, value, message, "not contains");
}
};
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false */
/*global Data: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
do_load_module("file://" + do_get_cwd().path + "/testHelper.js");
testing("data.jsm");
// testing: extractMessageId
test(function extractMessageIdExtractsARegularMessageId() {
var result = Data.extractMessageId("enigmail:message/foobar");
Assert.equal("foobar", result);
});
test(function extractMessageIdReturnsAnEmptyStringWhenItCantMatch() {
var result = Data.extractMessageId("enigmail:mime-message/foobar");
Assert.equal("", result);
});
// testing: extractMimeMessageId
test(function extractMimeMessageIdExtractsARegularMessageId() {
var result = Data.extractMimeMessageId("enigmail:mime-message/fluff");
Assert.equal("fluff", result);
});
test(function extractMimeMessageIdReturnsAnEmptyStringWhenItCantMatch() {
var result = Data.extractMimeMessageId("enigmail:message/mess");
Assert.equal("", result);
});
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false */
/*global Cc: false, Ci: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
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("decryptPermanently.jsm"); /*global DecryptPermanently: false, Promise: false */
component("enigmail/keyRing.jsm"); /*global KeyRing: false */
/*global msgHdrToMimeMessage: false, MimeMessage: false, MimeContainer: false */
component("enigmail/glodaMime.jsm");
component("enigmail/streams.jsm"); /*global Streams: false */
test(withTestGpgHome(withEnigmail(function messageIsCopiedToNewDir() {
loadSecretKey();
MailHelper.cleanMailFolder(MailHelper.getRootFolder());
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
const move = false;
const reqSync = true;
DecryptPermanently.dispatchMessages([header], targetFolder.URI, move, reqSync);
Assert.equal(targetFolder.getTotalMessages(false), 1);
Assert.equal(sourceFolder.getTotalMessages(false), 1);
})));
test(withTestGpgHome(withEnigmail(function messageIsMovedToNewDir() {
loadSecretKey();
MailHelper.cleanMailFolder(MailHelper.rootFolder);
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
const move = true;
const reqSync = true;
DecryptPermanently.dispatchMessages([header], targetFolder.URI, move, reqSync);
Assert.equal(targetFolder.getTotalMessages(false), 1);
Assert.equal(sourceFolder.getTotalMessages(false), 0);
})));
test(withTestGpgHome(withEnigmail(function messageIsMovedAndDecrypted() {
loadSecretKey();
MailHelper.cleanMailFolder(MailHelper.rootFolder);
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
const move = true;
const reqSync = true;
DecryptPermanently.dispatchMessages([header], targetFolder.URI, move, reqSync);
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
do_test_pending();
msgHdrToMimeMessage(
dispatchedHeader,
null,
function(header, mime) {
Assert.ok(!mime.isEncrypted);
Assert.assertContains(mime.parts[0].body, "This is encrypted");
do_test_finished();
},
false
);
})));
test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndDecrypted() {
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;
const reqSync = true;
DecryptPermanently.dispatchMessages([header], targetFolder.URI, move, reqSync);
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
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.");
do_test_finished();
},
false
);
})));
var loadSecretKey = function() {
const secretKey = do_get_file("resources/dev-strike.sec", false);
KeyRing.importKeyFromFile(null, secretKey, [], {});
};
var loadPublicKey = function() {
const publicKey = do_get_file("resources/dev-strike.asc", false);
KeyRing.importKeyFromFile(null, publicKey, [], {});
};
function stringFromUrl(url) {
const inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
let result = null;
const p = new Promise(function(resolve, reject) {
const iOService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
const uri = iOService.newURI(url, null, null);
const attChannel = iOService.newChannelFromURI(uri);
const listener = Streams.newStringStreamListener(function(data) {
result = data;
inspector.exitNestedEventLoop();
resolve();
});
attChannel.asyncOpen(listener, uri);
});
if(!result) {
inspector.enterNestedEventLoop({value : 0});
}
return result;
}
function extractAttachment(att) {
const name = att.name;
const body = stringFromUrl(att.url);
const isEncrypted = att.isEncrypted;
return {
name: name,
body: body,
isEncrypted: isEncrypted
};
}
function extractAttachments(msg) {
const result = [];
for(let i=0; i < msg.allAttachments.length; i++){
result.push(extractAttachment(msg.allAttachments[i]));
}
return result;
}
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false, component: false, Cc: false, Ci: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
do_load_module("file://" + do_get_cwd().path + "/testHelper.js"); /*global withEnigmail: false, withTestGpgHome: false */
testing("decryption.jsm"); /*global Decryption: false, nsIEnigmail: false */
component("enigmail/keyRing.jsm"); /*global KeyRing: fales */
component("enigmail/armor.jsm"); /*global Armor: fales */
test(withTestGpgHome(withEnigmail(function shouldDecryptMessage() {
const secretKey = do_get_file("resources/dev-strike.sec", false);
const importedKeysObj = {};
KeyRing.importKeyFromFile(JSUnit.createStubWindow(), secretKey, {}, importedKeysObj);
var encryptResult = "-----BEGIN PGP MESSAGE-----\n"+
"Version: GnuPG v2.0.22 (GNU/Linux)\n"+
"\n"+
"hQIMA9U1Yju2Dp5xAQ//eeoS38nAWPdJslfVaEuUhthZk4WxAua97+JNGX9vDiae\n"+
"jKJbjmQ5T2Sl2wvSqwjEIKzzjRAzr6SYuL9xaRkt3/BbMpSm/aSjc/cWNgcKtbHt\n"+
"u8u9Ha016XZke3/EpjLqMcXmK1eT9oa+UqR8u+B3ggOjz5BrjW+FMR+zfyiWv1cb\n"+
"6U4KO0YHuOq7G0lO4i3ro0ckhzZqCBLfCiQSfnF8R7p/KfQdUFBIdB41OALP0q4x\n"+
"UD+CNWhbIjyhfE0VX5KUn/5S5Se31VjKjfeo+5fN8HRUVQYu8uj2F+gPvALF5KKW\n"+
"an63O3IcUvZo6yOSoMjkMVJBHZRY6An2if+GXm330yQD3CDaonuihR+e+k6sd0kj\n"+
"hpwQs+4/uE96slRMqQMx573krc/p/WUWwG5qexOvwxzcqEdE5LYPEMKdH1fUX3tC\n"+
"kktNpSU8gJqluTk6cvtjCfMSwcEyKFmM13/RoitAw22DVOdLlcTHxbaNsIoxeRk/\n"+
"rxpsraIEs2H4uyF19K1nLioGkyubeUKPnBTB6qAwp0ZhZ1RleMwHRTFQU+jpbi51\n"+
"t87E+JI0UuLd14pDb7YJUKenHvAqa1jHAZKEfa2XFMfT/1MZzohlwjNpcPhYFWeB\n"+
"zq3cg/m/J5sb+FpdD42nfYnLsSYu7CwcTX8MU2vrSwHyHnmux6SjDXGrAaddWsrS\n"+
"RwGvjZsiFW/E82l2eMj5Zpm6HXY8kZx9TBSbWLSgU44nBhDvX1MrIGdd+rmYT2xt\n"+
"j4KAKpyV51VzmJUOqHrb7bPv70ncMx0w\n"+
"=uadZ\n"+
"-----END PGP MESSAGE-----\n\n";
const parentWindow = JSUnit.createStubWindow();
const exitCodeObj = {};
const statusFlagObj = {};
const errorMsgObj = {};
const decryptResult = Decryption.decryptMessage(parentWindow,
nsIEnigmail.UI_TEST,
encryptResult,
{},
exitCodeObj,
statusFlagObj,
{},
{},
{},
errorMsgObj,
{},
{},
"STRIKEfreedom@Qu1to"
);
Assert.equal(0, exitCodeObj.value);
Assert.equal(0, errorMsgObj.value);
Assert.equal("Hello there!", decryptResult);
Assert.equal(true, (statusFlagObj.value & (nsIEnigmail.DISPLAY_MESSAGE | nsIEnigmail.DECRYPTION_OKAY)) !== 0);
const blockType = Armor.locateArmoredBlock(encryptResult, 0, "", {}, {}, {});
Assert.equal("MESSAGE", blockType);
})));
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false, component: false, Cc: false, Ci: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
do_load_module("file://" + do_get_cwd().path + "/testHelper.js"); /*global withEnigmail: false, withTestGpgHome: false */
testing("encryption.jsm"); /*global Encryption: false, nsIEnigmail: false */
component("enigmail/keyRing.jsm"); /*global KeyRing: fales */
component("enigmail/armor.jsm"); /*global Armor: fales */
test(withTestGpgHome(withEnigmail(function shouldSignMessage() {
const secretKey = do_get_file("resources/dev-strike.sec", false);
const errorMsgObj = {};
const importedKeysObj = {};
KeyRing.importKeyFromFile(JSUnit.createStubWindow(), secretKey, errorMsgObj, importedKeysObj);
const parentWindow = JSUnit.createStubWindow();
const plainText = "Hello there!";
const strikeAccount = "strike.devtest@gmail.com";
const exitCodeObj = {};
const statusFlagObj = {};
const encryptResult = Encryption.encryptMessage(parentWindow,
nsIEnigmail.UI_TEST,
plainText,
strikeAccount,
strikeAccount,
"",
nsIEnigmail.SEND_TEST | nsIEnigmail.SEND_SIGNED,
exitCodeObj,
statusFlagObj,
errorMsgObj
);
Assert.equal(0, exitCodeObj.value);
Assert.equal(0, errorMsgObj.value);
Assert.equal(true, (statusFlagObj.value == nsIEnigmail.SIG_CREATED));
const blockType = Armor.locateArmoredBlock(encryptResult, 0, "", {}, {}, {});
Assert.equal("SIGNED MESSAGE", blockType);
})));
test(withTestGpgHome(withEnigmail(function shouldEncryptMessage() {
const publicKey = do_get_file("resources/dev-strike.asc", false);
const errorMsgObj = {};
const importedKeysObj = {};
KeyRing.importKeyFromFile(JSUnit.createStubWindow(), publicKey, errorMsgObj, importedKeysObj);
const parentWindow = JSUnit.createStubWindow();
const plainText = "Hello there!";
const strikeAccount = "strike.devtest@gmail.com";
const exitCodeObj = {};
const statusFlagObj = {};
const encryptResult = Encryption.encryptMessage(parentWindow,
nsIEnigmail.UI_TEST,
plainText,
strikeAccount,
strikeAccount,
"",
nsIEnigmail.SEND_TEST | nsIEnigmail.SEND_ENCRYPTED | nsIEnigmail.SEND_ALWAYS_TRUST,
exitCodeObj,
statusFlagObj,
errorMsgObj
);
Assert.equal(0, exitCodeObj.value);
Assert.equal(0, errorMsgObj.value);
Assert.equal(true, (statusFlagObj.value & nsIEnigmail.END_ENCRYPTION) !== 0);
const blockType = Armor.locateArmoredBlock(encryptResult, 0, "", {}, {}, {});
Assert.equal("MESSAGE", blockType);
})));
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false, withTestGpgHome:false */
/*global EnigmailCore: false, Enigmail: false, component: false, Cc: false, Ci: false, withEnvironment: false, nsIEnigmail: false, nsIEnvironment: false, Ec: false, Prefs: false, OS: false, Armor: false */
/*jshint -W120 */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
function run_test() {
var md = do_get_cwd().parent;
md.append("enigmail.js");
do_load_module("file://" + md.path);
shouldNotUseGpgAgent_test();
shouldUseGpgAgent_test();
shouldLocateArmoredBlock_test();
shouldExtractSignaturePart_test();
shouldGetKeyDetails_test();
}
function shouldNotUseGpgAgent_test() {
var enigmail = Cc["@mozdev.org/enigmail/enigmail;1"].createInstance(Ci.nsIEnigmail);
var isuseGpgAgent = enigmail.useGpgAgent();
Assert.equal(false, isuseGpgAgent);
}
do_load_module("file://" + do_get_cwd().path + "/testHelper.js");
function initalizeService(enigmail) {
window = JSUnit.createStubWindow();
enigmail.initialize(window, "", EnigmailCore.prefBranch);
return enigmail;
}
function shouldUseGpgAgent_test() {
var enigmail = Cc["@mozdev.org/enigmail/enigmail;1"].createInstance(Ci.nsIEnigmail);
enigmail = initalizeService(enigmail);
Assert.equal(true, enigmail.useGpgAgent());
}
function shouldLocateArmoredBlock_test() {
var enigmail = Cc["@mozdev.org/enigmail/enigmail;1"].createInstance(Ci.nsIEnigmail);
enigmail = initalizeService(enigmail);
var text = ""
+ " -----BEGIN PGP SIGNATURE-----\n"
+ " Version: GnuPG/MacGPG2 v2.0.22 (Darwin)\n"
+ " Comment: GPGTools - https://gpgtools.org\n"
+ "\n"
+ " iQIcBAEBCgAGBQJVSkxrAAoJEFco/AmgID3sm68QALBa6I6r7LLopA8R+S/CpO66\n"
+ " 6qQm0zidQ7bhMDNiKPD+/TG/Blvu0n10Cnt5Wk6lD7dwPKAsHVq1fGUva4rkEbi4\n"
+ " R9nx7BQGBiFCpYl3K1bHJ/QrnYms5wpKseqGtW+8wq8wKx68sWi83xsKN2Ml2SGA\n"
+ " 95nvbvaQ6yQlynGXhPhGhdT3L2tdPsulnSwnd3NZJ83U73aYIN5jc5+UyWduLqho\n"
+ " xnD127JQYb8X2UjdXyOnA/E/VHvCWt9+Ck9s6VdwUSEBs41vJ/kyrmPE6u9sIQX7\n"
+ " 9ZujMzN05+9A1Mtwp4dsDIbLMeX6FS44CqcGiUKzyx5ewiYq9lcAReM52i+4kmBM\n"
+ " 4B/yLXDrWWOBiUCUQaOWC8PyBAc2cHLf62m6+oEfEMMCXli/XZuBC442qYuWNgf+\n"
+ " yLLhyaA27rqMxmhdFtKSOzrRaxkTTb1oQFQwHYfeHT7kFpPjq4p1Jv+p8w0pcq0P\n"
+ " j5hiLABLveEcLn4fEpqLROdi/Vz6Mp2nnbhcz+xe/w2KWmGgfl/kg2T/9YVeLox9\n"
+ " kaqVqNezYPfFZ1iQgGKNBXl1SMqHtTRAvHfH1k0E8qg3t222KU2pALp0A/LSvu/T\n"
+ " P3g8OIpqWRI0uBZQ/Gp/S1Fjb3DHfE+Y3IhVf5SkhjIYIvViSrbGqGUmK+jwGMia\n"
+ " o29CFuiGhiz3ISDRKrtH\n"
+ " =MeaY\n"
+ " -----END PGP SIGNATURE-----";
var beginIndexObj = {};
var endIndexObj = {};
var indentStrObj = {};
var indentStr = "";
var blockType = enigmail.locateArmoredBlock(text, 0, indentStr, beginIndexObj, endIndexObj, indentStrObj);
Assert.equal(0, beginIndexObj.value);
Assert.equal(" ", indentStrObj.value);
Assert.equal("SIGNATURE", blockType);
}
function shouldExtractSignaturePart_test() {
var enigmail = Cc["@mozdev.org/enigmail/enigmail;1"].createInstance(Ci.nsIEnigmail);
enigmail = initalizeService(enigmail);
const signature = {
text: "Hello I'm here.\n please contact me via this email! \n",
header: "Version: GnuPG/MacGPG2 v2.0.22 (Darwin)\n"
+ "Comment: GPGTools - https://gpgtools.org\n",
armor: "iQIcBAEBCgAGBQJVSkxrAAoJEFco/AmgID3sm68QALBa6I6r7LLopA8R+S/CpO66\n"
+ "6qQm0zidQ7bhMDNiKPD+/TG/Blvu0n10Cnt5Wk6lD7dwPKAsHVq1fGUva4rkEbi4\n"
+ "R9nx7BQGBiFCpYl3K1bHJ/QrnYms5wpKseqGtW+8wq8wKx68sWi83xsKN2Ml2SGA\n"
+ "95nvbvaQ6yQlynGXhPhGhdT3L2tdPsulnSwnd3NZJ83U73aYIN5jc5+UyWduLqho\n"
+ "xnD127JQYb8X2UjdXyOnA/E/VHvCWt9+Ck9s6VdwUSEBs41vJ/kyrmPE6u9sIQX7\n"
+ "9ZujMzN05+9A1Mtwp4dsDIbLMeX6FS44CqcGiUKzyx5ewiYq9lcAReM52i+4kmBM\n"
+ "4B/yLXDrWWOBiUCUQaOWC8PyBAc2cHLf62m6+oEfEMMCXli/XZuBC442qYuWNgf+\n"
+ "yLLhyaA27rqMxmhdFtKSOzrRaxkTTb1oQFQwHYfeHT7kFpPjq4p1Jv+p8w0pcq0P\n"
+ "j5hiLABLveEcLn4fEpqLROdi/Vz6Mp2nnbhcz+xe/w2KWmGgfl/kg2T/9YVeLox9\n"
+ "kaqVqNezYPfFZ1iQgGKNBXl1SMqHtTRAvHfH1k0E8qg3t222KU2pALp0A/LSvu/T\n"
+ "P3g8OIpqWRI0uBZQ/Gp/S1Fjb3DHfE+Y3IhVf5SkhjIYIvViSrbGqGUmK+jwGMia\n"
+ "o29CFuiGhiz3ISDRKrtH\n"
+ "=MeaY"
};
var signature_block = "\n\n"
+ signature.text
+ "-----BEGIN PGP SIGNATURE-----\n"
+ signature.header
+ "\n"
+ signature.armor
+ "\n"
+ "-----END PGP SIGNATURE-----";
var signature_text = enigmail.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_TEXT);
var signature_headers = enigmail.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_HEADERS);
var signature_armor = enigmail.extractSignaturePart(signature_block, Ci.nsIEnigmail.SIGNATURE_ARMOR);
Assert.equal(signature.text, signature_text);
Assert.equal(signature.header, signature_headers);
Assert.equal(signature.armor.replace(/\s*/g, ""), signature_armor);
}
testing("enigmail.js");
function shouldGetKeyDetails_test() {
do_print("testing should get key details ");
var enigmail = Cc["@mozdev.org/enigmail/enigmail;1"].createInstance(Ci.nsIEnigmail);
enigmail = initalizeService(enigmail);
EC.setLogLevel(5);
var publicKey = do_get_file("resources/dev-strike.asc", false);
var errorMsgObj = {};
var importedKeysObj = {};
var importResult = enigmail.importKeyFromFile(JSUnit.createStubWindow(), publicKey, errorMsgObj, importedKeysObj);
Assert.equal(importResult, 0, errorMsgObj);
var keyDetails = enigmail.getKeyDetails("0xD535623BB60E9E71", false, true);
Assert.assertContains(keyDetails, "strike.devtest@gmail.com");
function newEnigmail(f) {
var oldEnigmail = EnigmailCore.getEnigmailService();
try {
var enigmail = new Enigmail();
EnigmailCore.setEnigmailService(enigmail);
f(enigmail);
} finally {
EnigmailCore.setEnigmailService(oldEnigmail);
}
}
Assert.assertContains = function(actual, expected, message) {
var msg = message || "Searching for <".concat(expected).concat("> to be contained within actual string.");
Assert.equal(actual.search(expected) > -1, true, msg);
};
// testing: initialize
test(function initializeWillPassEnvironmentIfAskedTo() {
var window = JSUnit.createStubWindow();
withEnvironment({
"ENIGMAIL_PASS_ENV": "STUFF:BLARG",
"STUFF": "testing"
}, function() {
newEnigmail(function(enigmail) {
enigmail.initialize(window, "");
Assert.assertArrayContains(EnigmailCore.getEnvList(), "STUFF=testing");
});
});
});
test(function initializeWillNotPassEnvironmentsNotAskedTo() {
var window = JSUnit.createStubWindow();
var environment = Cc["@mozilla.org/process/environment;1"].getService(nsIEnvironment);
environment.set("ENIGMAIL_PASS_ENV", "HOME");
environment.set("STUFF", "testing");
newEnigmail(function(enigmail) {
enigmail.initialize(window, "");
Assert.assertArrayNotContains(EnigmailCore.getEnvList(), "STUFF=testing");
});
});
test(function initializeWillNotSetEmptyEnvironmentValue() {
var window = JSUnit.createStubWindow();
var environment = Cc["@mozilla.org/process/environment;1"].getService(nsIEnvironment);
environment.set("APPDATA", "");
newEnigmail(function(enigmail) {
enigmail.initialize(window, "");
Assert.assertArrayNotContains(EnigmailCore.getEnvList(), "APPDATA=");
});
});
/*global do_load_module: false, do_get_file: false, do_get_cwd: false, testing: false, test: false, Assert: false, resetting: false, JSUnit: false, do_test_pending: false, do_test_finished: false */
/*global decryptionFailed: false, newContext: false, detectForgedInsets: false */
/*jshint -W097 */
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
do_load_module("file://" + do_get_cwd().path + "/testHelper.js"); /*global withTestGpgHome: false */
testing("enigmailErrorHandling.jsm"); /*global EnigmailErrorHandling: false */
test(function decryptionFailedWillSetDecryptionFailedFlag() {
var context = {};
decryptionFailed(context);
Assert.equal(context.inDecryptionFailed, true, "expected decryption failing to set the correct flag in the context");
});
test(function shouldExtractSingleBlockSeparation() {
var testStatusArray = [
"BEGIN_DECRYPTION" ,
"DECRYPTION_INFO 2 9" ,
"PLAINTEXT 62 1431644287 text.txt" ,
"PLAINTEXT_LENGTH 15" ,
"DECRYPTION_FAILED" ,
"END_DECRYPTION"
];
var context = newContext({},{},{},{});
context.statusArray=testStatusArray;
detectForgedInsets(context);
Assert.equal(context.retStatusObj.blockSeparation, "1:15 ");
});
test(function shouldExtractMultipleBlockSeparation() {
var testStatusArray = [
"FILE_START 3 file1.gpg",
"ENC_TO D535623BB60E9E71 1 0",
"USERID_HINT D535623BB60E9E71 anonymous strike <strike.devtest@gmail.com>",
"NEED_PASSPHRASE D535623BB60E9E71 781617319CE311C4 1 0",
"GOOD_PASSPHRASE",
"BEGIN_DECRYPTION",
"DECRYPTION_INFO 2 9",
"PLAINTEXT 62 1432677982 test",
"PLAINTEXT_LENGTH 14",
"DECRYPTION_OKAY",
"GOODMDC",
"END_DECRYPTION",
"FILE_DONE",
"FILE_START 3 file0.gpg",
"ENC_TO D535623BB60E9E71 1 0",
"GOOD_PASSPHRASE",
"BEGIN_DECRYPTION",
"DECRYPTION_INFO 2 9",
"PLAINTEXT 62 1432677982 test",
"PLAINTEXT_LENGTH 14",
"DECRYPTION_OKAY",
"GOODMDC",
"END_DECRYPTION",
"FILE_DONE",
"PLAINTEXT 62 1432677982 test",
"PLAINTEXT_LENGTH 15"
];
var context = newContext({},{},{},{});
context.statusArray=testStatusArray;
detectForgedInsets(context);
Assert.equal(context.retStatusObj.blockSeparation, "1:14 1:14 0:15 ");
});
test(function shouldHandleNoDataErrors() {
const errorOutput = "gpg: no valid OpenPGP data found.\n" +
"[GNUPG:] NODATA 1\n" +
"[GNUPG:] NODATA 2\n" +
"gpg: decrypt_message failed: Unknown system error\n";
const result = Enigma