Browse Source

Lint all the tests, even the dead ones.

1.1.101
Jorg Knobloch 9 months ago
parent
commit
e8af8e6205
35 changed files with 3270 additions and 2728 deletions
  1. +1
    -0
      README.md
  2. +2
    -1
      package.json
  3. +16
    -0
      tests/.eslintrc.json
  4. +21
    -23
      tests/boilerplate.js
  5. +5
    -9
      tests/config/testSetup.js
  6. +507
    -472
      tests/features/decrypt_feature_spec.js
  7. +518
    -406
      tests/features/encrypt_feature_spec.js
  8. +320
    -134
      tests/features/get_outgoing_message_rating_feature.js
  9. +53
    -40
      tests/features/get_trustwords_feature_spec.js
  10. +48
    -34
      tests/features/get_version_feature_spec.js
  11. +43
    -33
      tests/features/identity_rating_feature_spec.js
  12. +65
    -47
      tests/features/is_pEp_user_feature_spec.js
  13. +51
    -41
      tests/features/key_mistrusted_feature_spec.js
  14. +51
    -41
      tests/features/key_reset_trust_feature_spec.js
  15. +80
    -54
      tests/features/myself_feature_spec.js
  16. +134
    -115
      tests/features/token_reload.js
  17. +40
    -30
      tests/features/trust_personal_key_feature_spec.js
  18. +56
    -36
      tests/features/update_identity_feature_spec.js
  19. +38
    -40
      tests/legacy-features/decrypt_mime_feature_spec.js
  20. +228
    -229
      tests/legacy-features/enc_dec_feature_spec.js
  21. +55
    -60
      tests/legacy-features/get_mime_decode_message_feature.js
  22. +63
    -64
      tests/legacy-features/get_mime_encode_message_feature.js
  23. +56
    -57
      tests/legacy-features/handshake_feature_spec.js
  24. +154
    -168
      tests/legacy-features/p4tb-151.js
  25. +100
    -106
      tests/legacy-features/passive_feature_spec.js
  26. +64
    -63
      tests/messages.js
  27. +30
    -30
      tests/mock.js
  28. +0
    -34
      tests/mocks/mockPrefs.js
  29. +6
    -10
      tests/mocks/mockpepcore.js
  30. +25
    -25
      tests/mocks/mockpepfiles.js
  31. +17
    -17
      tests/mocks/mockpepos.js
  32. +21
    -20
      tests/mocks/mockxhrqueue.js
  33. +7
    -18
      tests/runtime/pepmessengercompose.js
  34. +43
    -48
      tests/runtime/pepmsghdrview.js
  35. +352
    -223
      tests/unit/controller.js

+ 1
- 0
README.md View File

@ -37,3 +37,4 @@ To run tests first is needed to install all dependencies
### Run
npm run test
npm run linttest

+ 2
- 1
package.json View File

@ -25,6 +25,7 @@
"scripts": {
"test": "./node_modules/.bin/mocha tests/unit/*.js tests/features/*.js",
"syntaxCheck": "./node_modules/.bin/babel addon -d /tmp/babelOutput",
"lint": "./node_modules/.bin/eslint addon"
"lint": "./node_modules/.bin/eslint addon",
"linttest": "./node_modules/.bin/eslint tests"
}
}

+ 16
- 0
tests/.eslintrc.json View File

@ -0,0 +1,16 @@
{
"rules": {
"max-len": [
"error",
{
"code": 8000,
"tabWidth": 2
}
],
"global-require": "off",
"func-names": "off",
"no-return-await": "off",
"no-shadow": "off",
"no-undef": "off"
}
}

+ 21
- 23
tests/boilerplate.js View File

@ -3,32 +3,30 @@
// case the `before` part would probably be part of its constructor
// and this file could be deleted
const pEp = require('../addon/content/modules/pEp');
const pEpAdapter = require('../addon/content/modules/pEpAdapter');
const pEpServer = require('../addon/content/modules/pEpServer');
const pEpLogger = require('../addon/content/pEpLogger');
/* eslint new-cap: ["error", { "newIsCap": false }] */
const pEp = require("../addon/content/modules/pEp");
const pEpAdapter = require("../addon/content/modules/pEpAdapter");
const pEpServer = require("../addon/content/modules/pEpServer");
const pEpLogger = require("../addon/content/pEpLogger");
function getControllerWithDetector(queue, detector) {
const log = new pEpLogger(0);
const server = new pEpServer(log, detector, queue);
const adapter = new pEpAdapter(log, server);
const controller = new pEp(log, adapter);
pEp.exists = false;
controller.adapter = adapter;
controller.after = () => server.destroyInstance();
return controller;
const log = new pEpLogger(0);
const server = new pEpServer(log, detector, queue);
const adapter = new pEpAdapter(log, server);
const controller = new pEp(log, adapter);
pEp.exists = false;
controller.adapter = adapter;
controller.after = () => server.destroyInstance();
return controller;
}
module.exports = {
getController(queue) {
return getControllerWithDetector(queue, () => ({
address: '127.0.0.1',
port: 4223,
path: '/ja/0.1/',
security_token: '0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW',
}));
},
getControllerWithDetector,
getController(queue) {
return getControllerWithDetector(queue, () => ({
address: "127.0.0.1",
port: 4223,
path: "/ja/0.1/",
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
}));
},
getControllerWithDetector,
};

+ 5
- 9
tests/config/testSetup.js View File

@ -1,13 +1,9 @@
let {describe, it, before, beforeEach, afterEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
let {
describe, it, before, beforeEach, afterEach,
} = require("mocha");
let chai = require("chai").use(require("chai-as-promised"));
let should = chai.should();
global.should = should;
global.describe = describe;
let pEpAdapter = require ( '../../chrome/content/modules/pEpAdapter');
let pEpServer = require ( '../../chrome/content/modules/pEpServer');
let pEpUtils = require ( '../../chrome/content/modules/utils');
let pEpOs = require ( '../../chrome/content/modules/pEpOs');
let pEpCore = require ( '../../chrome/content/modules/pEpCore');
let XhrQueue = require ( '../../chrome/content/modules/xhrQueue');

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


+ 518
- 406
tests/features/encrypt_feature_spec.js View File

@ -1,18 +1,18 @@
/* eslint-disable no-console */
const {
describe, it, before, after,
} = require('mocha');
const chai = require('chai').use(require('chai-as-promised'));
describe, it, before, after,
} = require("mocha");
const chai = require("chai").use(require("chai-as-promised"));
chai.should();
const pEp = require('../../addon/content/modules/pEp');
const {getQueue} = require('../mock');
const {getController} = require('../boilerplate');
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) {
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);
@ -46,412 +46,524 @@ function quoted_printable_decode(str) {
// 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 String.fromCharCode(parseInt(sHex, 16));
};
return str.replace(RFC2045Decode1, '')
.replace(RFC2045Decode2IN, RFC2045Decode2OUT);
return str.replace(RFC2045Decode1, "")
.replace(RFC2045Decode2IN, RFC2045Decode2OUT);
}
describe('pEp Encrypt Feature', () => {
let b;
let queue;
let pEpController;
describe('Without having public key', () => {
let result;
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);
queue.respondWith({
jsonrpc: '2.0',
id: 1,
result: {
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)'],
},
});
result = encryptMail(pEpController, subject, body, '', from, to);
});
after(() => {
queue.after();
pEpController.after();
});
it('returns an unencrypted message', () => {
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);
});
describe("pEp Encrypt Feature", () => {
let b;
let queue;
let pEpController;
describe("Without having public key", () => {
let result;
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);
queue.respondWith({
jsonrpc: "2.0",
id: 1,
result: {
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)"],
},
});
result = encryptMail(pEpController, subject, body, "", from, to);
});
after(() => {
queue.after();
pEpController.after();
});
describe('Perfect scenario', () => {
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',
}, {
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,
},
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)'],
},
});
from = 'cfg@pep.security';
to = 'cfg@pep.security';
subject = 'subject';
body = 'Not Encrypted Message';
result = encryptMail(pEpController, subject, body, '', from, to);
});
after(() => {
queue.after();
pEpController.after();
});
it('sends as expected', () => {
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);
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');
}));
it("returns an unencrypted message", () => {
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);
});
});
describe("Perfect scenario", () => {
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",
}, {
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,
},
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)"],
},
});
from = "cfg@pep.security";
to = "cfg@pep.security";
subject = "subject";
body = "Not Encrypted Message";
result = encryptMail(pEpController, subject, body, "", from, to);
});
after(() => {
queue.after();
pEpController.after();
});
describe('Multiple recivers', () => {
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',
}, {
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,
},
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,
}],
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)'],
},
});
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 = encryptMail(pEpController, subject, body, '', from, to, cc);
});
after(() => {
queue.after();
pEpController.after();
});
it('sends as expected', () => {
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);
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 original sender info', () => 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 original receivers info', () => result.should.eventually.have.property('to').then((receivers) => receivers.should.be.deep.equal([{
address: 'cfg@pep.security',
comm_type: 255,
fpr: 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5',
user_id: 'pEp_own_userId',
username: 'anonymous',
}, {
address: 'rg@pep.security',
comm_type: 56,
fpr: '14120CA823EA419E6A297EEDE37AADE4CCFDFBAD',
user_id: 'TOFU_rg@pep.security',
username: 'anonymous',
}])));
it('should return cc fingerprints', () => result.should.eventually.have.property('cc').then((receivers) => receivers.should.be.deep.equal([{
address: 'kinga@pep-security.net',
comm_type: 56,
fpr: 'B49167205B22B4891CD69580A1D55C3A106407CF',
user_id: 'TOFU_kinga@pep-security.net',
username: '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');
}));
it("sends as expected", () => {
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);
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;
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",
}, {
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,
},
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,
}],
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)"],
},
});
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 = encryptMail(pEpController, subject, body, "", from, to, cc);
});
after(() => {
queue.after();
pEpController.after();
});
describe('Encryption None scenario', () => {
let from;
let to;
let subject;
let body;
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, {
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)'],
},
});
result = encryptMail(pEpController, subject, body, '', from, to, undefined, undefined, 0);
});
after(() => {
queue.after();
pEpController.after();
});
it('sends as expected', () => {
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);
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(0);
}));
it('should return sender fingerprints', () => result.should.eventually.have.property('from').then((sender) => {
sender.address.should.be.equal(from);
sender.fpr.should.be.equal('');
sender.user_id.should.be.equal('');
sender.username.should.be.equal('');
}));
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].fpr.should.be.equal('');
receivers[0].user_id.should.be.equal('');
receivers[0].username.should.be.equal('');
}));
it('should have original subject', () => result.should.eventually.have.property('shortmsg').then((shortmsg) => {
shortmsg.should.be.equal('subject');
}));
it('should have original body', () => result.should.eventually.have.property('longmsg').then((longmsg) => {
longmsg.should.be.equal('Not Encrypted Message');
}));
it("sends as expected", () => {
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);
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 original sender info", () => 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 original receivers info", () => result.should.eventually.have.property("to").then((receivers) => receivers.should.be.deep.equal([{
address: "cfg@pep.security",
comm_type: 255,
fpr: "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
user_id: "pEp_own_userId",
username: "anonymous",
}, {
address: "rg@pep.security",
comm_type: 56,
fpr: "14120CA823EA419E6A297EEDE37AADE4CCFDFBAD",
user_id: "TOFU_rg@pep.security",
username: "anonymous",
}])));
it("should return cc fingerprints", () => result.should.eventually.have.property("cc").then((receivers) => receivers.should.be.deep.equal([{
address: "kinga@pep-security.net",
comm_type: 56,
fpr: "B49167205B22B4891CD69580A1D55C3A106407CF",
user_id: "TOFU_kinga@pep-security.net",
username: "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("Encryption None scenario", () => {
let from;
let to;
let subject;
let body;
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, {
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)"],
},
});
result = encryptMail(pEpController, subject, body, "", from, to, undefined, undefined, 0);
});
after(() => {
queue.after();
pEpController.after();
});
it("sends as expected", () => {
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);
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(0);
}));
it("should return sender fingerprints", () => result.should.eventually.have.property("from").then((sender) => {
sender.address.should.be.equal(from);
sender.fpr.should.be.equal("");
sender.user_id.should.be.equal("");
sender.username.should.be.equal("");
}));
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].fpr.should.be.equal("");
receivers[0].user_id.should.be.equal("");
receivers[0].username.should.be.equal("");
}));
it("should have original subject", () => result.should.eventually.have.property("shortmsg").then((shortmsg) => {
shortmsg.should.be.equal("subject");
}));
it("should have original body", () => result.should.eventually.have.property("longmsg").then((longmsg) => {
longmsg.should.be.equal("Not Encrypted Message");
}));
});
});

+ 320
- 134
tests/features/get_outgoing_message_rating_feature.js View File

@ -1,140 +1,326 @@
/* eslint-disable no-console */
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
let {
describe, it, before, beforeEach,
} = require("mocha");
let chai = require("chai").use(require("chai-as-promised"));
chai.should();
describe('pEp Get Outgoing Message Rating Feature', () => {
describe("pEp Get Outgoing Message Rating Feature", () => {
let getController = require("../boilerplate").getController;
let getQueue = require("../mock").getQueue;
let queue; let
pEpController;
before(() => {
queue = getQueue();
pEpController = getController(queue);
});
after(() => {
queue.after();
pEpController.after();
});
describe("Perfect scenario", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", ["cfg@pep.security"]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
describe("Perfect scenario 2", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", ["hk@pep.security"]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
describe("Perfect scenario 3", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", [{ address: "hk@pep.security", username: "" }]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
let getController = require('../boilerplate').getController;
let getQueue = require('../mock').getQueue;
let queue, pEpController;
describe("Empty to (1)", () => {
let result = "initial value";
before(() => {
queue = getQueue();
pEpController = getController(queue);
});
after(() => {
queue.after();
pEpController.after();
});
describe('Perfect scenario', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", ["cfg@pep.security"]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('Perfect scenario 2', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", ["hk@pep.security"]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('Perfect scenario 3', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", [{address: "hk@pep.security", username: ""}]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('Empty to (1)', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", [{}]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('Empty to (2)', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", [{address: "", username: "test"}]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('With 2 receviers', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", ["cfg@pep.security", "hk@pep.security"]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
});
describe('With none receviers (1)', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", []);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(0);
});
});
describe('With none receviers (2)', () => {
let result = "initial value";
before(() => {
queue.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOutgoingRating("cfg@pep.security", ["randomguy@randomdomain.com"]);
});
it('should return a Object', () => {
queue.expectSent(
{"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"dir":1,"id":"pEp-0","shortmsg":"test","longmsg":"test","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},"0"],"id":1,"jsonrpc":"2.0"}
);
return result.should.become(3);
});
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", [{}]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
describe("Empty to (2)", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", [{ address: "", username: "test" }]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
describe("With 2 receviers", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", ["cfg@pep.security", "hk@pep.security"]);
});
it("should return a Object", () => {
queue.expectSent(
{
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
method: "outgoing_message_rating",
params: [{
dir: 1,
id: "pEp-0",
shortmsg: "test",
longmsg: "test",
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,
}, "0"],
id: 1,
jsonrpc: "2.0",
},
);
return result.should.become(3);
});
});
describe("With none receviers (1)", () => {
let result = "initial value";
before(() => {
queue.respondWith({ jsonrpc: "2.0", id: 3, result: { outParams: [{ rating: 3 }], return: { status: 0, hex: "0 \"PEP_STATUS_OK\"" }, errorstack: ["(1 elements cleared)"] } });
result = pEpController.getOutgoingRating("cfg@pep.security", []);
});
it("should return a Object", () => {
queue.expectSent(