Browse Source

Update status

1.1.101
Chris Fuertes 2 years ago
parent
commit
e2b41a1e14
16 changed files with 1980 additions and 1666 deletions
  1. +11
    -1
      .eslintrc.json
  2. +14
    -0
      chrome/content/constants.js
  3. +42
    -12
      chrome/content/modules/MimeEmitter.js
  4. +0
    -4
      chrome/content/modules/pEp.js
  5. +12
    -4
      chrome/content/pEpForThunderbird.js
  6. +10
    -9
      chrome/content/pEpLogger.js
  7. +22
    -20
      chrome/content/pEpMimeEncrypt.js
  8. +20
    -32
      chrome/content/pepmessengercompose.js
  9. +68
    -107
      chrome/content/pepmsghdrview.js
  10. +24
    -23
      tests/boilerplate.js
  11. +495
    -194
      tests/features/decrypt_feature_spec.js
  12. +370
    -378
      tests/features/encrypt_feature_spec.js
  13. +204
    -207
      tests/legacy-features/enc_dec_feature_spec.js
  14. +1
    -4
      tests/legacy-features/p4tb-151.js
  15. +19
    -21
      tests/mock.js
  16. +668
    -650
      tests/unit/message.js

+ 11
- 1
.eslintrc.json View File

@ -16,7 +16,17 @@
"rules": {
"indent": [
"error",
4
4,
{
"SwitchCase": 1
}
],
"max-len": [
"error",
{
"code": 120,
"tabWidth": 4
}
]
}
}

+ 14
- 0
chrome/content/constants.js View File

@ -1,3 +1,4 @@
/* eslint no-unused-vars:1 */
const ENV_PEPHOME = 'PEPHOME';
const ENV_HOME = 'HOME';
const ENV_APPDATA = 'LocalAppData';
@ -10,6 +11,12 @@ const LEVEL_INFO = 3;
const LEVEL_DEBUG = 4;
const LEVEL_ALL = 5;
const PEP_ENCRYPTED_SUBJECT = 'p≡p';
const RATING_COLOR_NO_COLOR = 'no-color';
const RATING_COLOR_RED = 'red';
const RATING_COLOR_GREEN = 'green';
const RATING_COLOR_YELLOW = 'yellow';
const EXPORTED_SYMBOLS = [
'ENV_PEPHOME',
@ -23,4 +30,11 @@ const EXPORTED_SYMBOLS = [
'LEVEL_INFO',
'LEVEL_DEBUG',
'LEVEL_ALL',
'PEP_ENCRYPTED_SUBJECT',
'RATING_COLOR_NO_COLOR',
'RATING_COLOR_RED',
'RATING_COLOR_GREEN',
'RATING_COLOR_YELLOW',
];

+ 42
- 12
chrome/content/modules/MimeEmitter.js View File

@ -1,9 +1,12 @@
const newLine = '\r\n'; // portable newline
function addNewLine(s) {
return s + newLine;
}
const ADDR_FIELDS = ['Bcc', 'Cc', 'From', 'Reply-To', 'Resent-Bcc', 'Resent-Cc', 'Resent-From', 'Resent-Reply-To',
'Resent-Sender', 'Resent-To', 'Sender', 'To', 'Approved', 'Disposition-Notification-To', 'Delivered-To',
'Return-Receipt-To', 'Mail-Reply-To', 'Mail-Followup-To'];
class MimeEmitter {
constructor(jsmime, atob, boundary) {
this.jsmime = jsmime;
@ -20,21 +23,41 @@ class MimeEmitter {
}
emitHeader([key, value]) {
return this.jsmime.headeremitter.emitStructuredHeader(key, value || `undefined value: ${key}`, {});
let val = value || '';
if (ADDR_FIELDS.includes(key)) {
val = this.jsmime.headerparser.parseAddressingHeader(value, true);
}
return this.jsmime.headeremitter.emitStructuredHeader(key, val, {});
}
emitPart(part) {
let addresses = '';
let type = '';
if (part.addresses) {
addresses = addNewLine(part.addresses.map(this.emitAddress.bind(this)).join('') || '');
emitBody(body, type = '') {
const mimeBody = addNewLine(body);
let mimeType = type;
if (type) {
mimeType = addNewLine(this.emitHeader(['Content-type', `${type};boundary="${this.boundary}"`]));
}
const headers = addNewLine(part.headers.map(this.emitHeader.bind(this)).join(''));
const body = addNewLine(part.body);
if (part.type) {
type = addNewLine(this.emitHeader(['Content-type', `${part.type};boundary="${this.boundary}"`]));
return mimeType + mimeBody;
}
emitAddresses(addresses) {
let mimeAddresses = '';
if (addresses) {
mimeAddresses = addresses.map(this.emitAddress.bind(this)).join('') || '';
}
return headers + type + addresses + body;
return mimeAddresses;
}
emitHeaders(headers) {
if (!headers) return '';
return addNewLine(headers.map(this.emitHeader.bind(this)).join(''));
}
emitPart(part) {
const addresses = this.emitAddresses(part.addresses);
const headers = this.emitHeaders(part.headers);
const body = this.emitBody(part.body, part.type);
return headers + addresses + body;
}
emit(parts) {
@ -50,6 +73,13 @@ class MimeEmitter {
fromMessage(message) {
return this.emit(message.toParts(this.atob, this.boundary));
}
emitBodyFromMessage(message) {
let parts = message.toParts(this.atob, this.boundary);
parts = parts.map((part) => ({body: part.body, type: part.type}));
return this.emit(parts);
}
}
const EXPORTED_SYMBOLS = ['MimeEmitter'];


+ 0
- 4
chrome/content/modules/pEp.js View File

@ -337,10 +337,6 @@ pEp.Identity = class {
}
}
toMail() {
return `${this.username} <${this.address}>`;
}
static getClassName() {
return 'Identity';
}


+ 12
- 4
chrome/content/pEpForThunderbird.js View File

@ -1,3 +1,4 @@
/* global Components, ChromeUtils */
const {classes: Cc, interfaces: Ci} = Components;
const {pEp} = ChromeUtils.import('chrome://p4t/content/modules/pEp.js');
const {pEpFactory} = ChromeUtils.import('chrome://p4t/content/pEpFactory.js');
@ -18,7 +19,9 @@ class pEpForThunderbird extends pEp {
super.init(prefs);
const decryptionComponent = pEpMimeDecrypt.makeComponent(this);
this.factories = {
// eslint-disable-next-line new-cap
encryption: new pEpFactory(pEpMimeEncrypt.Handler, this, pEp),
// eslint-disable-next-line new-cap
decryption: new pEpFactory(decryptionComponent, this, pEp),
};
}
@ -33,23 +36,24 @@ class pEpForThunderbird extends pEp {
privacyStatusToTextClass(privacyStatus, protectionDisabled = false) {
let privacyText = 'Unknown';
let privacyClass = privacyStatus;
switch (privacyStatus) {
case 'red':
privacyText = 'Mistrusted';
case 'green':
privacyText = 'Secure and Trusted';
if (protectionDisabled) privacyStatus = 'green-disabled';
if (protectionDisabled) privacyClass = 'green-disabled';
break;
case 'yellow':
privacyText = 'Secure';
if (protectionDisabled) privacyStatus = 'yellow-disabled';
if (protectionDisabled) privacyClass = 'yellow-disabled';
break;
default:
privacyStatus = 'no-color';
privacyClass = 'no-color';
break;
}
return {class: privacyStatus, text: privacyText};
return {class: privacyClass, text: privacyText};
}
compFieldsToMessage(compFields) {
@ -76,6 +80,10 @@ class pEpForThunderbird extends pEp {
mimeFromMessage(pEpMessage) {
return this.emitter.fromMessage(pEpMessage);
}
mimeBodyFromMessage(pEpMessage) {
return this.emitter.emitBodyFromMessage(pEpMessage);
}
}
const EXPORTED_SYMBOLS = ['pEpForThunderbird'];

+ 10
- 9
chrome/content/pEpLogger.js View File

@ -6,26 +6,29 @@ const LEVEL_DEBUG = 4;
const LEVEL_ALL = 5;
class pEpLogger {
constructor(level) {
constructor(level = LEVEL_ALL, write = console) {
this.level = level;
this.write = write;
}
_log(msg, ...params) {
switch (this.level) {
case LEVEL_OFF:
break;
case LEVEL_INFO:
console.info(msg, ...params);
this.write.info(msg, ...params);
break;
case LEVEL_DEBUG:
console.debug(msg, ...params);
this.write.debug(msg, ...params);
break;
case LEVEL_ERROR:
console.error(msg, ...params);
this.write.error(msg, ...params);
break;
case LEVEL_WARN:
console.warn(msg, ...params);
this.write.warn(msg, ...params);
break;
default:
console.log(msg, ...params);
this.write.log(msg, ...params);
}
}
@ -42,9 +45,7 @@ class pEpLogger {
}
error(msg, ...params) {
if (this.level > LEVEL_ERROR) {
this._log(`[ERROR] ${msg}`, params);
}
if (this.level > LEVEL_ERROR) this._log(`[ERROR] ${msg}`, params);
}
}


+ 22
- 20
chrome/content/pEpMimeEncrypt.js View File

@ -3,6 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/* global gPgpMimeObj, Components, ChromeUtils */
const {jsmime} = ChromeUtils.import('resource:///modules/jsmime.jsm');
const {classes: Cc, results: Cr, interfaces: Ci} = Components;
const {pEp} = ChromeUtils.import('chrome://p4t/content/modules/pEp.js');
@ -22,6 +24,7 @@ function isMessageUriInPgpMime() {
if (typeof gPgpMimeObj === 'undefined') {
// eslint-disable-next-line no-global-assign
gPgpMimeObj = Cc['@mozilla.org/mime/pgp-mime-decrypt;1'].createInstance(Ci.nsIPgpMimeProxy);
}
@ -65,8 +68,6 @@ function PgpMimeEncrypt(sMimeSecurityInfo) {
// our own contract IDs
const PGPMIME_ENCRYPT_CID = Components.ID('{96fe88f9-d2cd-466f-93e0-3a351df4c6d2}');
const PGPMIME_ENCRYPT_CONTRACTID = '@pep.security/compose/mimeencrypt;1';
// S/MIME contract IDs
const SMIME_ENCRYPT_CONTRACTID = '@mozilla.org/messengercompose/composesecure;1';
@ -139,10 +140,6 @@ PgpMimeEncrypt.prototype = {
console.log('mimeEncrypt.js: onDataAvailable\n');
this.inStream.init(stream);
const data = this.inStream.read(count);
// LOCAL_DEBUG("mimeEncrypt.js: >"+data+"<\n");
console.log('==============');
console.log(data);
console.log('==============');
},
/**
@ -302,7 +299,7 @@ PgpMimeEncrypt.prototype = {
const self = this;
let resultObj = null;
let originalSubject = null;
let sendFlags = 0;
let sendFlags = 0x0;
this.outQueue = '';
let enc_format = ENC_FORMAT_PGP_MIME;
@ -319,20 +316,19 @@ PgpMimeEncrypt.prototype = {
} catch (ex) {
}
const fromAddr = jsmime.headerparser.parseAddressingHeader(self.msgIdentity.email);
const fromAddr = jsmime.headerparser.parseAddressingHeader(self.msgIdentity.fullAddress);
const toAddr = jsmime.headerparser.parseAddressingHeader(this.recipientList);
let toAddr;
let encryptFlags = 0;
toAddr = jsmime.headerparser.parseAddressingHeader(this.recipientList);
if (!self.msgIdentity.getBoolAttribute('attachPepKey')) {
encryptFlags = 0x4; // do not attach own key
}
// This attribute is never defined. Keep there just to remember the flag in the future.
// let encryptFlags = 0;
// if (!self.msgIdentity.getBoolAttribute('attachPepKey')) {
// encryptFlags = 0x4; // do not attach own key
// }
if (sendFlags & SEND_ENCRYPTED) {
let s = jsmime.headeremitter.emitStructuredHeader('from', fromAddr, {});
s += jsmime.headeremitter.emitStructuredHeader('to', toAddr, {});
let s = '';
// let s = jsmime.headeremitter.emitStructuredHeader('from', fromAddr, {});
// s += jsmime.headeremitter.emitStructuredHeader('to', toAddr, {});
if (originalSubject !== null) {
console.log('======= EMITING ORIGINAL SUBJECT =======');
@ -352,7 +348,13 @@ PgpMimeEncrypt.prototype = {
return this.pEpController.disclaimerStep(pEpMessage);
}).then((pEpMessage) => {
this.pEpController.encryptMailWithMessage(pEpMessage, enc_format).then((result) => {
let decoratedMessage = pEpMessage;
//if(this.msgIdentity.doBcc) { decoratedMessage.setBcc(this.msgIdentity.doBccList);}
//decoratedMessage.reply_to = this.msgIdentity.reply_to;
decoratedMessage.from = new pEp.Identity(fromAddr[0].email, 'pEp_own_id', fromAddr[0].name);
decoratedMessage.to = toAddr.map((addr) => new pEp.Identity(addr.email, undefined, addr.name));
this.pEpController.encryptMailWithMessage(decoratedMessage, enc_format).then((result) => {
resultObj = result;
// unblock the waiting lock in finishCryptoEncapsulation
if (self.inspector && self.inspector.eventLoopNestLevel > 0) {
@ -395,7 +397,7 @@ PgpMimeEncrypt.prototype = {
// value of `resultObj`
} else {
const resultMessage = pEp.Message.fromJSON(pEp.cloneMessage(resultObj));
this.outQueue = this.pEpController.mimeFromMessage(resultMessage);
this.outQueue = this.pEpController.mimeBodyFromMessage(resultMessage);
}
if (this.outQueue === '') {


+ 20
- 32
chrome/content/pepmessengercompose.js View File

@ -1,27 +1,20 @@
console.log('pepmessengercompose.js');
/* global gCurrentIdentity, gMsgCompose, ChromeUtils, Cc, Ci, Recipients2CompFields, Services */
const {pEpController} = ChromeUtils.import('chrome://p4t/content/p4tb.js');
const {Handshake} = ChromeUtils.import('chrome://p4t/content/modules/handshake.js');
const helper = ChromeUtils.import('chrome://p4t/content/TbHelper.js').TbHelper;
const {prefsFactory} = ChromeUtils.import('chrome://p4t/content/prefsFactory.js');
const PEP_ENCRYPTED_SUBJECT = 'p≡p';
const RATING_COLOR_NO_COLOR = 'no-color';
const RATING_COLOR_RED = 'red';
const RATING_COLOR_GREEN = 'green';
const RATING_COLOR_YELLOW = 'yellow';
const {
PEP_ENCRYPTED_SUBJECT, RATING_COLOR_NO_COLOR,
} = ChromeUtils.import('chrome://p4t/content/constants.js');
// Abstract Thunderbird methods
const TbAbstraction = {
getCurrentIdentity: () =>
/* global gCurrentIdentity: false */
gCurrentIdentity,
getCurrentIdentity: () => gCurrentIdentity,
};
const getMsgCompose = () =>
/* global gMsgCompose: false */
gMsgCompose;
const getMsgCompose = () => gMsgCompose;
const getCompFields = () => getMsgCompose().compFields;
const createNode = (nodeId, elementType, parentId, text, ...nodeClass) => {
@ -30,15 +23,11 @@ const createNode = (nodeId, elementType, parentId, text, ...nodeClass) => {
newNode.classList.add(...nodeClass);
newNode.id = nodeId;
const nodeText = document.createTextNode(text);
const nodeLabel = document.createXULElement('label');
// nodeLabel.id = nodeId+"-label";
nodeLabel.value = text;
nodeLabel.innerHTML = text;
newNode.appendChild(nodeLabel);
const parentNode = document.getElementById(parentId);
parentNode.parentNode.appendChild(newNode);
@ -59,21 +48,18 @@ const createPrivacyNode = (privacyStatus, protectionDisabled = false) => {
if (protectionDisabled || privacyStatus === RATING_COLOR_NO_COLOR) return;
const privacyTextClass = pEpController.privacyStatusToTextClass(privacyStatus, protectionDisabled);
const node = createNode(privacyNodeId, 'hbox', 'appcontent', privacyTextClass.text, privacyTextClass.class, 'footer-privacy-bar');
const node = createNode(privacyNodeId, 'hbox', 'appcontent', privacyTextClass.text,
privacyTextClass.class, 'footer-privacy-bar');
node.onclick = () => pEpComposer.openPrivacyDialogButtonAction();
};
const updateMsgIdentity = (rating) => {
const identity = getCurrentIdentity();
const identity = TbAbstraction.getCurrentIdentity();
identity.setIntAttribute('pEpRating', rating);
identity.setBoolAttribute('pEpEnabled', true); // TODO Set this using preferences
};
// let getMsgComposeWindow = () => {
// return document.getElementById("msgcomposeWindow");
// };
const _parseAddress = (address) => {
const hdr = Cc['@mozilla.org/messenger/headerparser;1'].createInstance(Ci.nsIMsgHeaderParser);
const mails = hdr.parseEncodedHeader(address, 'utf-8');
@ -89,11 +75,11 @@ function isPrivate(rating) {
return rating && rating > 5;
}
var pEpComposer = {
const pEpComposer = {
init(window) {
console.log('pEpComposer: init()');
const kEncryptionPolicy_Always = 2;
this.window = window;
this.prefs = prefsFactory();
this.originalRatingPromise = this.getOriginalRating();
@ -137,7 +123,6 @@ var pEpComposer = {
console.log('pepmessengercompose.js: addressPopupListener()');
const msgCompFields = getCompFields();
/* global Recipients2CompFields: false */
Recipients2CompFields(msgCompFields);
const currentIdentity = TbAbstraction.getCurrentIdentity();
@ -157,7 +142,6 @@ var pEpComposer = {
return Promise.resolve(-2);
})
.then((rating) => {
console.log('ONGOING RATING: ', rating);
if (typeof rating === 'undefined') rating = -2;
updateMsgIdentity(rating);
@ -228,9 +212,9 @@ var pEpComposer = {
// Check one last time if the message should be encrypted, if so encrypt subject
// The rating should be recalculated on the engine for a more reliable value.
// If we cannot recalculate it here, the best option will be revert the subject in pEpMimeEncrypt: processPepEncryption()
// where we have the most accurate rating, the one returned from the encrypt.
const rating = getCurrentIdentity().getIntAttribute('pEpRating');
// If we cannot recalculate it here, the best option will be revert the subject in pEpMimeEncrypt:
// processPepEncryption() where we have the most accurate rating, the one returned from the encrypt.
const rating = TbAbstraction.getCurrentIdentity().getIntAttribute('pEpRating');
if (isPrivate(rating)) { // If rating is RATING_COLOR_YELLOW or RATING_COLOR_GREEN encrypt subject
let securityInfo;
@ -289,7 +273,7 @@ var pEpComposer = {
openPrivacyDialogButtonAction() {
const msgCompFields = getCompFields();
/* global Recipients2CompFields: false */
Recipients2CompFields(msgCompFields);
const [from, to, cc, bcc] = this.getAddresses(TbAbstraction.getCurrentIdentity(), msgCompFields);
@ -315,6 +299,10 @@ var pEpComposer = {
},
};
// let getMsgComposeWindow = () => {
// return document.getElementById("msgcomposeWindow");
// };
window.addEventListener('compose-window-init', pEpComposer.initListener.bind(pEpComposer), true);
window.addEventListener('compose-from-changed', pEpComposer.fromChangedListener.bind(pEpComposer), true);
window.addEventListener('compose-send-message', pEpComposer.sendMessageListener.bind(pEpComposer), true);


+ 68
- 107
chrome/content/pepmsghdrview.js View File

@ -1,4 +1,7 @@
/* global gFolderDisplay, gDBView, Cc, Ci, ChromeUtils */
const {pEpController} = ChromeUtils.import('chrome://p4t/content/p4tb.js');
const {pEpUtils} = ChromeUtils.import('chrome://p4t/content/modules/utils.js');
const Helper = ChromeUtils.import('chrome://p4t/content/TbHelper.js').TbHelper;
const MessageView = ChromeUtils.import('chrome://p4t/content/TbMessageView.js').TbMessageView;
const Prefs = ChromeUtils.import('chrome://p4t/content/prefsFactory.js')
@ -6,6 +9,24 @@ const Prefs = ChromeUtils.import('chrome://p4t/content/prefsFactory.js')
const PEP_COLUMN_NAME = 'pEpStatusCol';
const IMG_FOLDER = 'chrome://p4t/content/resources/images';
/**
* Checks pEp Preferences, if enabled store the decrypted version in the server.
*
* @param msgHdr Thunderbird Headers object
* @param {string} mime MIME message to be stored in a new message
*/
const storeDecryptedCopy = (msgHdr, mime) => {
if (msgHdr && !Prefs.isStoreAllSecurely()) {
if (pEpController.isTrustedServer(msgHdr.folder.URI)) {
Helper.copyMessageToFolder(msgHdr, mime);
}
}
};
const columnHandler = {
_usingPep: true,
resetUsingPep() {
@ -31,22 +52,20 @@ const columnHandler = {
getImageSrc(row, col) {
const key = gDBView.getKeyAt(row);
const hdr = gDBView.db.GetMsgHdrForKey(key);
const newProp = null;
let newProp = null;
const rating = hdr.getStringProperty('pEpPrivacyColor');
// TODO Use numeric rating instead of color name
if (rating) {
let newProp;
switch (rating) {
case 'red':
case 'yellow':
case 'green':
newProp = `chrome://p4t/content/${rating}-shield.png`;
newProp = `${IMG_FOLDER}/${rating}-shield.png`;
break;
default:
newProp = 'chrome://p4t/content/no-color-shield.png';
newProp = `${IMG_FOLDER}/no-color-shield.png`;
}
return newProp;
@ -65,9 +84,9 @@ const dbObserver = {
try {
gDBView.addColumnHandler(PEP_COLUMN_NAME, columnHandler);
} catch (ex) {
console.log('==============');
console.log(ex);
console.log('==============');
pEpController.log.debug('==============');
pEpController.log.debug(ex);
pEpController.log.debug('==============');
throw new Error('Cannot add column handler');
}
},
@ -75,14 +94,14 @@ const dbObserver = {
const ColumnOverlay = {
init(win) {
console.debug('columnOverlay.js: init()', win);
pEpController.log.debug('columnOverlay.js: init()', win);
this.win = win;
this.addColumn(win);
},
destroy() {
console.debug('columnOverlay.js: destroy()');
pEpController.log.debug('columnOverlay.js: destroy()');
this.destroyColumn();
delete this.win.ColumnOverlay;
delete this.win.columnHandler;
@ -107,7 +126,7 @@ const ColumnOverlay = {
threadCols.appendChild(treeCol);
// Add Db Observer
const observerService = Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
const observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
observerService.addObserver(dbObserver, 'MsgCreateDBView', false);
const folderTree = this.win.document.getElementById('folderTree');
@ -124,13 +143,13 @@ const ColumnOverlay = {
const pEpHdrView = {
init() {
console.debug('pEpHdrView: init()', this, window);
pEpController.log.debug('pEpHdrView: init()', this, window);
this.onLoadListener();
pEpController.init(Prefs);
},
destroy() {
console.debug('pEpHdrView: destroy()');
pEpController.log.debug('pEpHdrView: destroy()');
ColumnOverlay.destroy();
pEpController.shutdown();
delete window.pEpHdrView;
@ -140,7 +159,7 @@ const pEpHdrView = {
},
onLoadListener(event) {
console.debug('pepmsghdrview.js: onLoadListener()', this, window);
pEpController.log.debug('pepmsghdrview.js: onLoadListener()', this, window);
MessageView.init(window);
ColumnOverlay.init(window, gDBView);
@ -153,7 +172,7 @@ const pEpHdrView = {
},
onLoadMsgPanelFrameListener(event) {
console.debug('pepmsghdrview.js: onLoadMsgPanelFrameListener()');
pEpController.log.debug('pepmsghdrview.js: onLoadMsgPanelFrameListener()');
// do nothing if we are disabled for this account
if (!Helper.decryptForSelectedAccount(gFolderDisplay)) {
@ -175,14 +194,14 @@ const pEpHdrView = {
try {
mimeMessage = Helper.readMailFromURI(currentUri);
} catch (e) {
console.debug('Errors while reading message from uri', e);
pEpController.log.debug('Errors while reading message from uri', e);
}
// Process mail
this.processMail(mimeMessage, msgHdr);
},
processMail(mimeMessage, msgHdr) {
async processMail(mimeMessage, msgHdr) {
function setPrivacyStatusFromHeader(message) {
if (message.opt_fields && message.opt_fields.includes('X-EncStatus')) {
let color;
@ -209,7 +228,6 @@ const pEpHdrView = {
color = 'no-color';
}
const privacyTextClass = pEpController.privacyStatusToTextClass(color);
msgHdr.setStringProperty('pEpPrivacyText', privacyTextClass.text);
@ -239,11 +257,16 @@ const pEpHdrView = {
return message;
}
const decodedPromise = pEpController.messageFromMIME(mimeMessage);
const decryptedPromise = decodedPromise.then(decryptFromMessage1);
const decryptedPromise = pEpController.messageFromMIME(mimeMessage)
.then(pEpController.decryptMailWithMessage.bind(pEpController));
/*
const boundary = pEpUtils.generateRandomString(33);
pEpController.emitter.setBoundary(boundary);
const mimeDecryptedPromise = decryptedPromise.then((message) => message.toMime(atob, pEpController.emitter));
/*
¡
We pass the decrypted message to the Thunderbird interface
mainly in two ways. One way is to update the interface shown
in the message pane with the `updateMessagePanel` handler
@ -253,43 +276,41 @@ const pEpHdrView = {
attachments and act on them
*/
const messagePanelFrame = Helper.getMessagePane(window);
console.debug('pepmsghdrview.js: onLoadMsgPanelFrameListener(),frame: ', messagePanelFrame);
pEpController.log.debug('pepmsghdrview.js: onLoadMsgPanelFrameListener(),frame: ', messagePanelFrame);
if (messagePanelFrame != null) {
console.debug('pepmsghdrview.js: onLoadListener() added listener');
messagePanelFrame.addEventListener('load', updateMessagePanel, false);
pEpController.log.debug('pepmsghdrview.js: onLoadListener() added listener');
function updateMessagePanel() {
decryptedPromise
.then(decryptFromMessage2)
.then(([decryptedMessage, decryptedMIMEMessage]) => {
let panel;
let
body;
let panel;
let body;
// Validations
validateDecryptOutput(decryptedMessage);
decryptedPromise.then((decryptedMessage) => {
// Validations
validateDecryptOutput(decryptedMessage);
// Update the UI
updatePrivacyFromMessage(decryptedMessage);
decodedPromise.then(setPrivacyStatusFromHeader);
// Update the UI
updatePrivacyFromMessage(decryptedMessage);
setPrivacyStatusFromHeader(decryptedMessage);
body = decryptedMessage.longmsg_formatted || decryptedMessage.longmsg;
body = decryptedMessage.longmsg_formatted || decryptedMessage.longmsg;
panel = Helper.getMessagePane(window);
MessageView.updateBody(panel, body);
MessageView.updateSubject(gFolderDisplay.selectedMessage, decryptedMessage.shortmsg);
panel = Helper.getMessagePane(window);
MessageView.updateBody(panel, body);
MessageView.updateSubject(gFolderDisplay.selectedMessage, decryptedMessage.shortmsg);
msgHdr.setStringProperty('pEpDecryptedMessage', body);
msgHdr.setStringProperty('pEpDecryptedMessage', body);
// Store decrypted copy if possible
storeDecryptedCopy(msgHdr, decryptedMIMEMessage);
})
.catch((err) => {
console.error('pepmsghdrview.js: onLoadMsgPanelFrameListener(): getMimeDecodedMessage', err);
// Store decrypted copy if possible
mimeDecryptedPromise.then((decryptedMimeMessage) => {
storeDecryptedCopy(msgHdr, decryptedMimeMessage);
});
});
}
messagePanelFrame.addEventListener('load', updateMessagePanel, false);
}
/*
@ -301,69 +322,9 @@ const pEpHdrView = {
message to Thunderbird's MIME proxy service
*/
pEpController.decryptionComponentPromise = decryptedPromise.then((message) => message.longmsg);
pEpController.decryptionComponentPromise = decryptedPromise.then(mimeDecryptedPromise);
},
};
/**
* Checks pEp Preferences, if enabled store the decrypted version in the server.
*
* @param msgHdr Thunderbird Headers object
* @param {string} mime MIME message to be stored in a new message
*/
var storeDecryptedCopy = (msgHdr, mime) => {
if (msgHdr && !Prefs.isStoreAllSecurely()) {
if (pEpController.isTrustedServer(msgHdr.folder.URI)) {
Helper.copyMessageToFolder(msgHdr, mime);
}
}
};
/**
* Decrypts a message from a {pEp.Message}
*
* WARNING: 03/02/2020: The current JSON Adapter / Engine does not decrypt a message
* if the body isn't a PGP Message. This function goes around that problem that initially should not exist.
* Once that problem is fixed this function should be only a call to pEpController.decryptMailWithMessage,
* without a need to get the message from the attachments and having to parse the MIME multiple times.
*
* @param {pEp.Message} message Encrypted message to be decrypted
* @returns {pEp.Message}
*/
var decryptFromMessage1 = async (message) => {
let innerMIMEMessage;
let innerMessage;
let outerMessage;
let
decryptedMessage;
try {
message.longmsg = atob(message.attachments[1].value);
decryptedMessage = await pEpController.decryptMailWithMessage(message);
} catch (err) {
throw new Error('pepmsghdrview.js: decryptFromMessage(): Unable to decrypt the message', err.message);
}
return decryptedMessage;
};
var decryptFromMessage2 = async (decrypted) => {
try {
outerMessage = await pEpController.messageFromMIME(decrypted.longmsg);
} catch (err) {
throw new Error('pepmsghdrview.js: decryptFromMessage(): Error occurred while parsing outer message', err.message);
}
try {
innerMIMEMessage = atob(outerMessage.attachments[0].value);
innerMessage = await pEpController.messageFromMIME(innerMIMEMessage);
} catch (err) {
throw new Error('pepmsghdrview.js: decryptFromMessage(): Error occurred while parsing inner message', err.message);
}
innerMessage.rating = decrypted.rating;
return [innerMessage, innerMIMEMessage];
};
pEpHdrView.init();

+ 24
- 23
tests/boilerplate.js View File

@ -2,34 +2,35 @@
// because we could combine all these pEp objects into one, in that
// case the `before` part would probably be part of its constructor
// and this file could be deleted
var log = () => {}
if (false) {
log = console.log
}
const os = require('os');
const fs = require('fs');
const pEp = require('../chrome/content/modules/pEp');
const pEpAdapter = require('../chrome/content/modules/pEpAdapter');
const pEpServer = require('../chrome/content/modules/pEpServer');
const pEpLogger = require('../chrome/content/pEpLogger');
/* eslint new-cap: ["error", { "newIsCap": false }] */
function getControllerWithDetector(queue, detector) {
pEp = require('../chrome/content/modules/pEp');
let pEpAdapter = require('../chrome/content/modules/pEpAdapter');
let pEpServer = require('../chrome/content/modules/pEpServer');
let fs = require('fs');
let os = require('os');
server = new pEpServer(log, detector, queue);
let adapter = new pEpAdapter(log, server);
const log = new pEpLogger(0);
const server = new pEpServer(log, detector, queue);
const adapter = new pEpAdapter(log, server);
const controller = new pEp([], log, adapter, fs, os);
pEp.exists = false;
controller = new pEp([], log, adapter, fs, os);
controller.adapter = adapter;
controller.after = () => server.destroyInstance();
return controller;
}
module.exports = {
getController: function (queue) {
return getControllerWithDetector(queue, function () {
return {
address: "127.0.0.1",
port: 4223,
path: "/ja/0.1/",
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW"
};
});
getController(queue) {
return getControllerWithDetector(queue, () => ({
address: '127.0.0.1',
port: 4223,
path: '/ja/0.1/',
security_token: '0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW',
}));
},
getControllerWithDetector: getControllerWithDetector
}
getControllerWithDetector,
};

+ 495
- 194
tests/features/decrypt_feature_spec.js
File diff suppressed because it is too large
View File


+ 370
- 378
tests/features/encrypt_feature_spec.js View File

@ -1,35 +1,42 @@
/* eslint-disable no-console */
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
const {
describe, it, before, after,
} = require('mocha');
const chai = require('chai').use(require('chai-as-promised'));
chai.should();
let pEp = require('../../chrome/content/modules/pEp');
const pEp = require('../../chrome/content/modules/pEp');
const {getQueue} = require('../mock');
const {getController} = require('../boilerplate');
describe('pEp Encrypt Feature', () => {
let getQueue = require('../mock').getQueue;
let getController = require('../boilerplate').getController;
let b, queue, pEpController;
let b;
let queue;
let
pEpController;
describe('Without having public key', () => {
let result, message;
let result;
let
message;
before(() => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({
"jsonrpc": "2.0",
"id": 1,
"result": {
"outParams": [null],
"return": {"status": 1024, "hex": "0x400 \"PEP_UNENCRYPTED\""},
"errorstack": ["(1 elements cleared)"]
}
jsonrpc: '2.0',
id: 1,
result: {
outParams: [null],
return: {status: 1024, hex: '0x400 "PEP_UNENCRYPTED"'},
errorstack: ['(1 elements cleared)'],
},
});
from = "cfg@pep.security";
to = "to@test.com";
subject = "subject";
body = "Not Encrypted Message";
result = pEpController.encryptMail(subject, body, "", from, to);
const from = 'cfg@pep.security';
const to = 'to@test.com';
const subject = 'subject';
const body = 'Not Encrypted Message';
result = pEpController.encryptMail(subject, body, '', from, to);
});
after(() => {
queue.after();
@ -38,28 +45,32 @@ describe('pEp Encrypt Feature', () => {
it('returns an unencrypted message', () => {
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""},
"to": [{"user_id": "", "username": "anonymous", "address": "to@test.com", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": []
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
security_token: '0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW',
method: 'encrypt_message',
params: [{
id: 'pEp-0',
shortmsg: 'subject',
longmsg: 'Not Encrypted Message',
longmsg_formatted: '',
from: {
user_id: '', username: 'anonymous', address: 'cfg@pep.security', fpr: '',
},
to: [{
user_id: '', username: 'anonymous', address: 'to@test.com', fpr: '',
}],
dir: 1,
enc_format: 3,
attachments: [],
opt_fields: [],
cc: [],
}, [], ['OP'], 3, 0],
id: 1,
jsonrpc: '2.0',
});
result.should.eventually.have.property('enc_format', 0);
message = new pEp.Message("pEp-0", subject, body, from, to);
message.longmsg_formatted = "";
message = new pEp.Message('pEp-0', subject, body, from, to);
message.longmsg_formatted = '';
message.setCc([]);
message.enc_format = 0;
@ -68,55 +79,62 @@ describe('pEp Encrypt Feature', () => {
});
describe('Perfect scenario', () => {
let from, to, subject, body, message;
let from;
let to;
let subject;
let body;
let message;
let result;
before(() => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({
"jsonrpc": "2.0",
"id": 2,
"result": {
"outParams": [{
"dir": 1,
"id": "pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security",
"shortmsg": "p≡p",
"longmsg": "this message was encrypted with p≡p https://pEp-project.org",
"attachments": [{
"value": "VmVyc2lvbjogMQ==",
"size": 10,
"mime_type": "application/pgp-encrypted"
jsonrpc: '2.0',
id: 2,
result: {
outParams: [{
dir: 1,
id: 'pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security',
shortmsg: 'p≡p',
longmsg: 'this message was encrypted with p≡p https://pEp-project.org',
attachments: [{
value: 'VmVyc2lvbjogMQ==',
size: 10,
mime_type: 'application/pgp-encrypted',
}, {
"value": "mockvalue",
"size": 3681,
"mime_type": "application/octet-stream",
"filename": "file://msg.asc"
value: 'mockvalue',
size: 3681,
mime_type: 'application/octet-stream',
filename: 'file://msg.asc',
}],
"from": {
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
from: {
address: 'cfg@pep.security',
fpr: 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5',
user_id: 'pEp_own_userId',
username: 'anonymous',
comm_type: 255,
},
"to": [{
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
to: [{
address: 'cfg@pep.security',
fpr: 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5',
user_id: 'pEp_own_userId',
username: 'anonymous',
comm_type: 255,
}],
"opt_fields": [{"key": "X-pEp-Version", "value": "2.1"}],
"enc_format": 3
}], "return": {"status": 0, "hex": "0 \"PEP_STATUS_OK\""}, "errorstack": ["(1 elements cleared)"]
}
opt_fields: [{key: 'X-pEp-Version', value: '2.1'}],
enc_format: 3,
}],
return: {status: 0, hex: '0 "PEP_STATUS_OK"'},
errorstack: ['(1 elements cleared)'],
},
});
from = "cfg@pep.security";
to = "cfg@pep.security";
subject = "subject";
body = "Not Encrypted Message";
result = pEpController.encryptMail(subject, body, "", from, to);
from = 'cfg@pep.security';
to = 'cfg@pep.security';
subject = 'subject';
body = 'Not Encrypted Message';
result = pEpController.encryptMail(subject, body, '', from, to);
});
after(() => {
queue.after();
@ -125,155 +143,151 @@ describe('pEp Encrypt Feature', () => {
it('sends as expected', () => {
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""},
"to": [{"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": []
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
security_token: '0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW',
method: 'encrypt_message',
params: [{
id: 'pEp-0',
shortmsg: 'subject',
longmsg: 'Not Encrypted Message',
longmsg_formatted: '',
from: {
user_id: '', username: 'anonymous', address: 'cfg@pep.security', fpr: '',
},
to: [{
user_id: '', username: 'anonymous', address: 'cfg@pep.security', fpr: '',
}],
dir: 1,
enc_format: 3,
attachments: [],
opt_fields: [],
cc: [],
}, [], ['OP'], 3, 0],
id: 1,
jsonrpc: '2.0',
});
});
it('should resolve into an encrypted mail', () => {
return result.should.be.fulfilled;
});
it("should return an outgoing message", () => {
return result.should.eventually.have.property("dir").then((dir) => {
dir.should.be.equal(1);
});
});
it("should return formated with enc_format default", () => {
return result.should.eventually.have.property("enc_format").then((enc_format) => {
enc_format.should.be.equal(3);
});
});
it("should return sender fingerprints", () => {
return result.should.eventually.have.property("from").then((sender) => {
sender.address.should.be.equal(from);
sender.comm_type.should.be.equal(255);
sender.fpr.should.be.equal("B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5");
sender.user_id.should.be.equal("pEp_own_userId");
sender.username.should.be.equal("anonymous");
});
});
it("should return receiver fingerprints", () => {
return result.should.eventually.have.property("to").then((receivers) => {
receivers.length.should.be.gte(1);
receivers[0].address.should.be.equal(to);
receivers[0].comm_type.should.be.equal(255);
receivers[0].fpr.should.be.equal("B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5");
receivers[0].user_id.should.be.equal("pEp_own_userId");
receivers[0].username.should.be.equal("anonymous");
});
});
it("should have at least 2 attachments", () => {
return result.should.eventually.have.property("attachments").then((attachments) => {
attachments.length.should.be.gte(2);
attachments[0].mime_type.should.be.equal("application/pgp-encrypted");
attachments[1].mime_type.should.be.equal("application/octet-stream");
attachments[1].filename.should.be.equal("file://msg.asc");
});
});
it("should have x-pEp-version header", () => {
return result.should.eventually.have.property("opt_fields").then((opt_fields) => {
opt_fields[0].key.should.be.equal("X-pEp-Version");
});
});
it("should have pEp subject", () => {
return result.should.eventually.have.property("shortmsg").then((shortmsg) => {
shortmsg.should.be.equal("p≡p");
});
});
it('should have encrypted body', () => {
return result.should.eventually.have.property("longmsg").then((longmsg) => {
longmsg.should.be.equal("this message was encrypted with p≡p https://pEp-project.org");
});
});
it('should resolve into an encrypted mail', () => result.should.be.fulfilled);
it('should return an outgoing message', () => result.should.eventually.have.property('dir').then((dir) => {
dir.should.be.equal(1);
}));
it('should return formated with enc_format default', () => result.should.eventually.have.property('enc_format').then((enc_format) => {
enc_format.should.be.equal(3);
}));
it('should return sender fingerprints', () => result.should.eventually.have.property('from').then((sender) => {
sender.address.should.be.equal(from);
sender.comm_type.should.be.equal(255);
sender.fpr.should.be.equal('B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5');
sender.user_id.should.be.equal('pEp_own_userId');
sender.username.should.be.equal('anonymous');
}));
it('should return receiver fingerprints', () => result.should.eventually.have.property('to').then((receivers) => {
receivers.length.should.be.gte(1);
receivers[0].address.should.be.equal(to);
receivers[0].comm_type.should.be.equal(255);
receivers[0].fpr.should.be.equal('B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5');
receivers[0].user_id.should.be.equal('pEp_own_userId');
receivers[0].username.should.be.equal('anonymous');
}));
it('should have at least 2 attachments', () => result.should.eventually.have.property('attachments').then((attachments) => {
attachments.length.should.be.gte(2);
attachments[0].mime_type.should.be.equal('application/pgp-encrypted');
attachments[1].mime_type.should.be.equal('application/octet-stream');
attachments[1].filename.should.be.equal('file://msg.asc');
}));
it('should have x-pEp-version header', () => result.should.eventually.have.property('opt_fields').then((opt_fields) => {
opt_fields[0].key.should.be.equal('X-pEp-Version');
}));
it('should have pEp subject', () => result.should.eventually.have.property('shortmsg').then((shortmsg) => {
shortmsg.should.be.equal('p≡p');
}));
it('should have encrypted body', () => result.should.eventually.have.property('longmsg').then((longmsg) => {
longmsg.should.be.equal('this message was encrypted with p≡p https://pEp-project.org');
}));
});
describe('Multiple recivers', () => {
let from, to, subject, body, cc, bcc;
let from;
let to;
let subject;
let body;
let cc;
let
bcc;
before(() => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({
"jsonrpc": "2.0", "id": 1, "result": {
"outParams": [{
"dir": 1,
"id": "pEp-0",
"shortmsg": "p≡p",
"longmsg": "this message was encrypted with p≡p https://pEp-project.org",
"attachments": [{
"value": "VmVyc2lvbjogMQ==",
"size": 10,
"mime_type": "application/pgp-encrypted"
jsonrpc: '2.0',
id: 1,
result: {
outParams: [{
dir: 1,
id: 'pEp-0',
shortmsg: 'p≡p',
longmsg: 'this message was encrypted with p≡p https://pEp-project.org',
attachments: [{
value: 'VmVyc2lvbjogMQ==',
size: 10,
mime_type: 'application/pgp-encrypted',
}, {
"value": "mocked value",
"size": 5071,
"mime_type": "application/octet-stream",
"filename": "file://msg.asc"
value: 'mocked value',
size: 5071,
mime_type: 'application/octet-stream',
filename: 'file://msg.asc',
}],
"from": {
"address": "fo@pep.security",
"fpr": "B0E03850E2033BCBBF22F7087D45E0D0A78160AC",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
from: {
address: 'fo@pep.security',
fpr: 'B0E03850E2033BCBBF22F7087D45E0D0A78160AC',
user_id: 'pEp_own_userId',
username: 'anonymous',
comm_type: 255,
},
"to": [{
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
to: [{
address: 'cfg@pep.security',
fpr: 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5',
user_id: 'pEp_own_userId',
username: 'anonymous',
comm_type: 255,
}, {
"address": "rg@pep.security",
"fpr": "14120CA823EA419E6A297EEDE37AADE4CCFDFBAD",
"user_id": "TOFU_rg@pep.security",
"username": "anonymous",
"comm_type": 56
address: 'rg@pep.security',
fpr: '14120CA823EA419E6A297EEDE37AADE4CCFDFBAD',
user_id: 'TOFU_rg@pep.security',
username: 'anonymous',
comm_type: 56,
}],
"cc": [{
"address": "kinga@pep-security.net",
"fpr": "B49167205B22B4891CD69580A1D55C3A106407CF",
"user_id": "TOFU_kinga@pep-security.net",
"username": "anonymous",
"comm_type": 56
cc: [{
address: 'kinga@pep-security.net',
fpr: 'B49167205B22B4891CD69580A1D55C3A106407CF',
user_id: 'TOFU_kinga@pep-security.net',
username: 'anonymous',
comm_type: 56,
}],
"opt_fields": [{"key": "X-pEp-Version", "value": "2.1"}],
"enc_format": 3
}], "return": {"status": 0, "hex": "0 \"PEP_STATUS_OK\""}, "errorstack": ["(1 elements cleared)"]
}
opt_fields: [{key: 'X-pEp-Version', value: '2.1'}],
enc_format: 3,
}],
return: {status: 0, hex: '0 "PEP_STATUS_OK"'},
errorstack: ['(1 elements cleared)'],
},
});
from = "fo@pep.security";
to = ["cfg@pep.security", "rg@pep.security"];
cc = ["kinga@pep-security.net"];
bcc = ["cfg@pep.security"];
subject = "subject";
body = "Not Encrypted Message";
result = pEpController.encryptMail(subject, body, "", from, to, cc);
from = 'fo@pep.security';
to = ['cfg@pep.security', 'rg@pep.security'];
cc = ['kinga@pep-security.net'];
bcc = ['cfg@pep.security'];
subject = 'subject';
body = 'Not Encrypted Message';
result = pEpController.encryptMail(subject, body, '', from, to, cc);
});
after(() => {
queue.after();
@ -282,137 +296,125 @@ describe('pEp Encrypt Feature', () => {
it('sends as expected', () => {
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "fo@pep.security", "fpr": ""},
"to": [{
"user_id": "",
"username": "anonymous",
"address": "cfg@pep.security",
"fpr": ""
}, {"user_id": "", "username": "anonymous", "address": "rg@pep.security", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": [{"user_id": "", "username": "anonymous", "address": "kinga@pep-security.net", "fpr": ""}]
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
});
});
it('should resolve into an encrypted mail', () => {
return result.should.be.fulfilled;
});
it("should return an outgoing message", () => {
return result.should.eventually.have.property("dir").then((dir) => {
dir.should.be.equal(1);
security_token: '0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW',
method: 'encrypt_message',
params: [{
id: 'pEp-0',
shortmsg: 'subject',
longmsg: 'Not Encrypted Message',
longmsg_formatted: '',
from: {
user_id: '', username: 'anonymous', address: 'fo@pep.security', fpr: '',
},
to: [{
user_id: '',
username: 'anonymous',
address: 'cfg@pep.security',
fpr: '',
}, {
user_id: '', username: 'anonymous', address: 'rg@pep.security', fpr: '',
}],
dir: 1,
enc_format: 3,
attachments: [],
opt_fields: [],
cc: [{
user_id: '', username: 'anonymous', address: 'kinga@pep-security.net', fpr: '',
}],
}, [], ['OP'], 3, 0],
id: 1,
jsonrpc: '2.0',
});
});
it("should return formated with enc_format default", () => {
return result.should.eventually.have.property("enc_format").then((enc_format) => {
enc_format.should.be.equal(3);
});
});
it('should resolve into an encrypted mail', () => result.should.be.fulfilled);
it("should return original sender info", () => {
return result.should.eventually.have.property("from").then((sender) => {
sender.should.be.deep.equal({
"address": "fo@pep.security",
"comm_type": 255,
"fpr": "B0E03850E2033BCBBF22F7087D45E0D0A78160AC",
"user_id": "pEp_own_userId",
"username": "anonymous"
});
});
});
it('should return an outgoing message', () => result.should.eventually.have.property('dir').then((dir) => {