Browse Source

Fix encrypt_feature_spec.js. 72 pass, 9 fail, sum: 81.

1.1.101
Jorg Knobloch 1 year ago
parent
commit
1f90a9ebca
1 changed files with 95 additions and 121 deletions
  1. +95
    -121
      tests/features/encrypt_feature_spec.js

+ 95
- 121
tests/features/encrypt_feature_spec.js View File

@ -8,17 +8,62 @@ chai.should();
const pEp = require('../../addon/content/modules/pEp');
const {getQueue} = require('../mock');
const {getController} = require('../boilerplate');
const ENC_FORMAT_PEP = 4;
const DIR_OUTGOING = 1;
// Restored from https://pep-security.lu/dev/repos/pEp_for_Thunderbird/diff/2770741ed46e/chrome/content/modules/pEp.js
function encryptMail(controller, subject = '', body = '', htmlBody = '', from = '', to = [], cc = [], bcc = [], encodingFormat = ENC_FORMAT_PEP) {
body = quoted_printable_decode(body);
const msgId = "testID@pep.security";
const message = new pEp.Message(msgId, subject, body, from, to, DIR_OUTGOING, encodingFormat, [], [], htmlBody);
if (cc) message.setCc(cc);
return controller.cache_encrypt_message(message, encodingFormat);
}
function quoted_printable_decode(str) {
if (!str) return str;
// discuss at: http://phpjs.org/functions/quoted_printable_decode/
// original by: Ole Vrijenhoek
// bugfixed by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Theriault
// reimplemented by: Theriault
// improved by: Brett Zamir (http://brett-zamir.me)
// example 1: quoted_printable_decode('a=3Db=3Dc');
// returns 1: 'a=b=c'
// example 2: quoted_printable_decode('abc =20\r\n123 =20\r\n');
// returns 2: 'abc \r\n123 \r\n'
// example 3: quoted_printable_decode('012345678901234567890123456789012345678901234567890123456789012345678901234=\r\n56789');
// returns 3: '01234567890123456789012345678901234567890123456789012345678901234567890123456789'
// example 4: quoted_printable_decode("Lorem ipsum dolor sit amet=23, consectetur adipisicing elit");
// returns 4: 'Lorem ipsum dolor sit amet#, consectetur adipisicing elit'
/**
* @return {string}
*/
const RFC2045Decode1 = /=\r\n/gm;
// Decodes all equal signs followed by two hex digits
const RFC2045Decode2IN = /=([0-9A-F]{2})/gim;
// the RFC states against decoding lower case encodings, but following apparent PHP behavior
// RFC2045Decode2IN = /=([0-9A-F]{2})/gm,
const RFC2045Decode2OUT = function (sMatch, sHex) {
return String.fromCharCode(parseInt(sHex, 16));
};
return str.replace(RFC2045Decode1, '')
.replace(RFC2045Decode2IN, RFC2045Decode2OUT);
}
describe('pEp Encrypt Feature', () => {
let b;
let queue;
let
pEpController;
let pEpController;
describe('Without having public key', () => {
let result;
let
message;
let message;
const from = 'cfg@pep.security';
const to = 'to@test.com';
const subject = 'subject';
const body = 'Not Encrypted Message';
before(() => {
queue = getQueue();
pEpController = getController(queue);
@ -26,17 +71,23 @@ describe('pEp Encrypt Feature', () => {
jsonrpc: '2.0',
id: 1,
result: {
outParams: [null],
outParams: [null, {
dir: 1,
id: 'pEp-0',
shortmsg: subject,
longmsg: body,
longmsg_formatted: "",
attachments: [],
from: {address: 'cfg@pep.security', fpr: '', user_id: '', username: '' },
to: [{address: to, fpr: '', user_id: '', username: ''}],
enc_format: 3,
}],
return: {status: 1024, hex: '0x400 "PEP_UNENCRYPTED"'},
errorstack: ['(1 elements cleared)'],
},
});
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);
result = encryptMail(pEpController, subject, body, '', from, to);
});
after(() => {
queue.after();
@ -44,34 +95,15 @@ 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',
});
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"cache_encrypt_message","params":[{"dir":1,"id":"testID@pep.security","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","attachments":[],"rawmsg_ref":"","rawmsg_size":"","from":{"user_id":"","username":"","address":"cfg@pep.security","fpr":""},"to":[{"user_id":"","username":"","address":"to@test.com","fpr":""}],"in_reply_to":[],"opt_fields":[],"enc_format":4,"cc":[]},[],["OP"],4,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.setCc([]);
message.setBcc([]);
message.enc_format = 0;
return result.should.become(message);
@ -134,7 +166,7 @@ describe('pEp Encrypt Feature', () => {
to = 'cfg@pep.security';
subject = 'subject';
body = 'Not Encrypted Message';
result = pEpController.encryptMail(subject, body, '', from, to);
result = encryptMail(pEpController, subject, body, '', from, to);
});
after(() => {
queue.after();
@ -142,29 +174,9 @@ 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',
});
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"cache_encrypt_message","params":[{"dir":1,"id":"testID@pep.security","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","attachments":[],"rawmsg_ref":"","rawmsg_size":"","from":{"user_id":"","username":"","address":"cfg@pep.security","fpr":""},"to":[{"user_id":"","username":"","address":"cfg@pep.security","fpr":""}],"in_reply_to":[],"opt_fields":[],"enc_format":4,"cc":[]},[],["OP"],4,0],"id":1,"jsonrpc":"2.0"}
);
});
it('should resolve into an encrypted mail', () => result.should.be.fulfilled);
@ -287,7 +299,7 @@ describe('pEp Encrypt Feature', () => {
bcc = ['cfg@pep.security'];
subject = 'subject';
body = 'Not Encrypted Message';
result = pEpController.encryptMail(subject, body, '', from, to, cc);
result = encryptMail(pEpController, subject, body, '', from, to, cc);
});
after(() => {
queue.after();
@ -295,36 +307,9 @@ 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',
});
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"cache_encrypt_message","params":[{"dir":1,"id":"testID@pep.security","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","attachments":[],"rawmsg_ref":"","rawmsg_size":"","from":{"user_id":"","username":"","address":"fo@pep.security","fpr":""},"to":[{"user_id":"","username":"","address":"cfg@pep.security","fpr":""},{"user_id":"","username":"","address":"rg@pep.security","fpr":""}],"in_reply_to":[],"opt_fields":[],"enc_format":4,"cc":[{"user_id":"","username":"","address":"kinga@pep-security.net","fpr":""}]},[],["OP"],4,0],"id":1,"jsonrpc":"2.0"}
);
});
it('should resolve into an encrypted mail', () => result.should.be.fulfilled);
@ -394,27 +379,36 @@ describe('pEp Encrypt Feature', () => {
let to;
let subject;
let body;
let
message;
let message;
before(() => {
queue = getQueue();
pEpController = getController(queue);
from = 'cfg@pep.security';
to = 'cfg@pep.security';
subject = 'subject';
body = 'Not Encrypted Message';
queue.respondWith({
jsonrpc: '2.0',
id: 2,
result: {
outParams: [null],
outParams: [null, {
dir: 1,
id: 'pEp-0',
shortmsg: subject,
longmsg: body,
longmsg_formatted: "",
attachments: [],
from: {address: 'cfg@pep.security', fpr: '', user_id: '', username: '' },
to: [{address: to, fpr: '', user_id: '', username: ''}],
enc_format: 3,
}],
return: {status: 1024, hex: '0x400 "PEP_UNENCRYPTED"'},
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, undefined, undefined, 0);
result = encryptMail(pEpController, subject, body, '', from, to, undefined, undefined, 0);
});
after(() => {
queue.after();
@ -422,29 +416,9 @@ 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: 0,
attachments: [],
opt_fields: [],
cc: [],
}, [], ['OP'], 0, 0],
id: 1,
jsonrpc: '2.0',
});
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"cache_encrypt_message","params":[{"dir":1,"id":"testID@pep.security","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","attachments":[],"rawmsg_ref":"","rawmsg_size":"","from":{"user_id":"","username":"","address":"cfg@pep.security","fpr":""},"to":[{"user_id":"","username":"","address":"cfg@pep.security","fpr":""}],"in_reply_to":[],"opt_fields":[],"enc_format":0,"cc":[]},[],["OP"],0,0],"id":1,"jsonrpc":"2.0"}
);
});
it('should resolve into an encrypted mail', () => result.should.be.fulfilled);
@ -461,7 +435,7 @@ describe('pEp Encrypt Feature', () => {
sender.address.should.be.equal(from);
sender.fpr.should.be.equal('');
sender.user_id.should.be.equal('');
sender.username.should.be.equal('anonymous');
sender.username.should.be.equal('');
}));
it('should return receiver fingerprints', () => result.should.eventually.have.property('to').then((receivers) => {
@ -469,7 +443,7 @@ describe('pEp Encrypt Feature', () => {
receivers[0].address.should.be.equal(to);
receivers[0].fpr.should.be.equal('');
receivers[0].user_id.should.be.equal('');
receivers[0].username.should.be.equal('anonymous');
receivers[0].username.should.be.equal('');
}));
it('should have original subject', () => result.should.eventually.have.property('shortmsg').then((shortmsg) => {


Loading…
Cancel
Save