Browse Source

P4TB-108 mock most tests so that they can run in every environment

1.1.101
francesco 3 years ago
parent
commit
96647989e9
24 changed files with 1513 additions and 1406 deletions
  1. +1093
    -1193
      package-lock.json
  2. +5
    -1
      package.json
  3. +31
    -0
      tests/boilerplate.js
  4. +33
    -30
      tests/features/get_ongoing_message_rating_feature.js
  5. +16
    -21
      tests/features/get_trustwords_feature_spec.js
  6. +21
    -26
      tests/features/get_version_feature_spec.js
  7. +15
    -18
      tests/features/identity_rating_feature_spec.js
  8. +18
    -19
      tests/features/is_pEp_user_feature_spec.js
  9. +26
    -19
      tests/features/key_mistrusted_feature_spec.js
  10. +26
    -19
      tests/features/key_reset_trust_feature_spec.js
  11. +19
    -21
      tests/features/myself_feature_spec.js
  12. +15
    -19
      tests/features/trust_personal_key_feature_spec.js
  13. +16
    -20
      tests/features/update_identity_feature_spec.js
  14. +4
    -0
      tests/legacy-features/README.md
  15. +0
    -0
      tests/legacy-features/decrypt_feature_spec.js
  16. +0
    -0
      tests/legacy-features/decrypt_mime_feature_spec.js
  17. +0
    -0
      tests/legacy-features/enc_dec_feature_spec.js
  18. +0
    -0
      tests/legacy-features/encrypt_feature_spec.js
  19. +0
    -0
      tests/legacy-features/get_mime_decode_message_feature.js
  20. +0
    -0
      tests/legacy-features/handshake_feature_spec.js
  21. +0
    -0
      tests/legacy-features/result_test_mime.eml
  22. +0
    -0
      tests/legacy-features/test_mime.eml
  23. +35
    -0
      tests/mock.js
  24. +140
    -0
      tests/unit/controller.js

+ 1093
- 1193
package-lock.json
File diff suppressed because it is too large
View File


+ 5
- 1
package.json View File

@ -8,7 +8,11 @@
"chai": "*",
"chai-as-promised": "*",
"mocha": "*",
"nyc": "^13.1.0",
"nyc": "^14.1.1",
"sinon": "^7.4.2",
"xhr2": "^0.1.4"
},
"scripts": {
"test": "./node_modules/.bin/mocha tests/unit/controller.js tests/features/*.js"
}
}

+ 31
- 0
tests/boilerplate.js View File

@ -0,0 +1,31 @@
module.exports = {
getController: function () {
let server, controller;
return {
before(q) {
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');
let connectionInfoDetector = function () {
return {
address: "127.0.0.1",
port: 4223,
path: "/ja/0.1/",
security_token: "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW"
};
};
server = new pEpServer(console.log, connectionInfoDetector, q);
let adapter = new pEpAdapter(console.log, server);
pEp.exists = false;
controller = new pEp([], console.log, adapter, fs, os);
controller.adapter = adapter;
return controller;
},
after() {
server.destroyInstance();
}
};
}
}

+ 33
- 30
tests/features/get_ongoing_message_rating_feature.js View File

@ -3,69 +3,68 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Get Ongoing Message Rating Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Get Ongoing Message Rating Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", ["cfg@pep.security"]);
});
it('should return a Object', () => {
return result.should.become(8);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
});
describe('Perfect scenario 2', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", ["hk@pep.security"]);
});
it('should return a Object', () => {
return result.should.become(6);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
});
describe('Perfect scenario 3', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", [{address: "hk@pep.security", username: ""}]);
});
it('should return a Object', () => {
return result.should.become(6);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
});
describe('Empty to', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", [{}]);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(0);
});
});
@ -73,11 +72,12 @@ describe('pEp Get Ongoing Message Rating Feature', () => {
describe('Empty to', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", [{address: "", username: "test"}]);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(0);
});
});
@ -85,23 +85,25 @@ describe('pEp Get Ongoing Message Rating Feature', () => {
describe('With 2 receviers', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", ["cfg@pep.security", "hk@pep.security"]);
});
it('should return a Object', () => {
return result.should.become(6);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
});
describe('With none receviers', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", []);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(0);
});
});
@ -110,12 +112,13 @@ describe('pEp Get Ongoing Message Rating Feature', () => {
describe('With none receviers', () => {
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getOngoingRating("cfg@pep.security", ["randomguy@randomdomain.com"]);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
});
});
});

+ 16
- 21
tests/features/get_trustwords_feature_spec.js View File

@ -2,27 +2,21 @@
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
let b = require('../boilerplate').getController();
let m = require('../mock');
describe('pEp Get Trustwords Feature', () => {
let getController, pEpController, q;
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(log, server);
let pEpController = new pEp([], log, adapter, fs, os);
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Get Trustwords Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -40,14 +34,15 @@ describe('pEp Get Trustwords Feature', () => {
fpr: "B39706EF952EC3AF0BA5921A91F792D28B044A71",
user_id: ""
};
before(() => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[41,"CRYSTAL ELOPER ACCEPTABLY COHAN CLANKING "],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.get_trustwords(identity1, identity2, lang);
});
it('should return a Array', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"get_trustwords","params":[{"user_id":"","username":"Test User 01","address":"test@test.com","fpr":"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"},{"user_id":"","username":"Test User 02","address":"test2@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"},"en","OUT","OUT",false],"id":1,"jsonrpc":"2.0"});
return result.should.become("CRYSTAL ELOPER ACCEPTABLY COHAN CLANKING ");
});
});
});
});

+ 21
- 26
tests/features/get_version_feature_spec.js View File

@ -3,45 +3,40 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Get Version Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Get Version Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let adapter;
let result = "initial value";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[],"return":{"major":0,"minor":17,"patch":0,"api_version":"0.17.0","name":"(40) Eisenach-Ost","package_version":[null],"engine_version":"1.1.1","pep_protocol_version":"2.1"},"errorstack":["(1 elements cleared)"]}});
result = pEpController.getVersion();
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"serverVersion","params":[],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"api_version": "0.15.5",
"api_version": "0.17.0",
"engine_version": "1.1.1",
"major": 0,
"minor": 15,
"name": "(39) Eisenach",
"package_version": null,
"patch": 5,
"pep_protocol_version": "2.0"
"minor": 17,
"name": "(40) Eisenach-Ost",
"package_version": [null],
"patch": 0,
"pep_protocol_version": "2.1"
});
});
});
});
});

+ 15
- 18
tests/features/identity_rating_feature_spec.js View File

@ -2,27 +2,22 @@
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
describe('pEp Identity Rating Feature', () => {
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Identity Rating Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -34,11 +29,13 @@ describe('pEp Identity Rating Feature', () => {
let identity = new pEp.Identity(testMail, testId, testName, testFp);
identity.rating = 6;
before(() => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[{"rating":6}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.identity_rating(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"identity_rating","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":""},["OP"]],"id":1,"jsonrpc":"2.0"});
return result.should.become(identity);
});
});
});
});

+ 18
- 19
tests/features/is_pEp_user_feature_spec.js View File

@ -2,27 +2,22 @@
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
describe('pEp Is pEp User Feature', () => {
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Is pEp User Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('User doesnt exist', () => {
let result;
@ -32,11 +27,13 @@ describe('pEp Is pEp User Feature', () => {
let testId = "test_user_id";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[false],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.is_pEp_user(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
return result.should.become(false);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"is_pEp_user","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":""},true],"id":1,"jsonrpc":"2.0"});
return result.should.eventually.have.property('is_pEp', false);
});
});
@ -51,11 +48,13 @@ describe('pEp Is pEp User Feature', () => {
let identity = new pEp.Identity(testMail, testId, testName, testFp);
identity.is_pEp = true;
before(() => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[true],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.is_pEp_user(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"is_pEp_user","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":""},true],"id":1,"jsonrpc":"2.0"});
return result.should.become(identity);
});
});
});
});

+ 26
- 19
tests/features/key_mistrusted_feature_spec.js View File

@ -3,26 +3,20 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Key Mistrusted Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Key Mistrusted Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -32,11 +26,24 @@ describe('pEp Key Mistrusted Feature', () => {
let testId = "test_user_id";
before(() => {
q.respondWith({
"jsonrpc":"2.0",
"id":1,
"result":{
"outParams":[],
"return":{
"status":0,
"hex":"0 \"PEP_STATUS_OK\""
},
"errorstack": ["(1 elements cleared)"]
}
});
result = pEpController.key_mistrusted(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"key_mistrusted","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
});
});
});

+ 26
- 19
tests/features/key_reset_trust_feature_spec.js View File

@ -3,26 +3,20 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Key Reset Trust Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Key Reset Trust Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -32,11 +26,24 @@ describe('pEp Key Reset Trust Feature', () => {
let testId = "test_user_id";
before(() => {
q.respondWith({
"jsonrpc":"2.0",
"id":1,
"result":{
"outParams":[],
"return":{
"status":0,
"hex":"0 \"PEP_STATUS_OK\""
},
"errorstack": ["(1 elements cleared)"]
}
});
result = pEpController.key_reset_trust(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"key_reset_trust","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
});
});
});

+ 19
- 21
tests/features/myself_feature_spec.js View File

@ -3,26 +3,20 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Myself Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Myself Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -31,14 +25,16 @@ describe('pEp Myself Feature', () => {
let testFp = "";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[{"address":"test@test.com","fpr":"1737B1324BC4997FCD24D997E9E71570C8644E1C","user_id":"pEp_own_userId","username":"Test User 01","comm_type":255}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.myself(testMail, "pEp_own_userId", testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"myself","params":[{"user_id":"pEp_own_userId","username":"Test User 01","address":"test@test.com","fpr":""}],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"address": testMail,
"comm_type": 255,
"fpr": "B39706EF952EC3AF0BA5921A91F792D28B044A71",
"fpr": "1737B1324BC4997FCD24D997E9E71570C8644E1C",
"user_id": "pEp_own_userId",
"username": testName,
});
@ -53,17 +49,19 @@ describe('pEp Myself Feature', () => {
let testFp = "";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[{"address":"test@test.com","fpr":"1737B1324BC4997FCD24D997E9E71570C8644E1C","user_id":"pEp_own_userId","username":"Test User 01","comm_type":255}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.myself(testMail, "pEp_own_userId", testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"myself","params":[{"user_id":"pEp_own_userId","username":"Test User 01","address":"test@test.com","fpr":""}],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"address": testMail,
"comm_type": 255,
"fpr": "B39706EF952EC3AF0BA5921A91F792D28B044A71",
"fpr": "1737B1324BC4997FCD24D997E9E71570C8644E1C",
"user_id": "pEp_own_userId",
"username": "Test User 01", // previous test username TODO dont make it dependant
});
});
});
});
});

+ 15
- 19
tests/features/trust_personal_key_feature_spec.js View File

@ -3,26 +3,20 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Trust Personal Key Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Trust Personal Key Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -32,11 +26,13 @@ describe('pEp Trust Personal Key Feature', () => {
let testId = "test_user_id";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[],"return":{"status":518,"hex":"0x206 \"PEP_KEY_UNSUITABLE\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.trust_personal_key(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"trust_personal_key","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
});
});
});

+ 16
- 20
tests/features/update_identity_feature_spec.js View File

@ -3,26 +3,20 @@ let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
describe('pEp Update Identity Feature', () => {
let pEp = require('../../chrome/content/modules/pEp');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
let log = console.log;
let fs = require('fs');
let os = require('os');
let connectionInfoDetector = function () {
return JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
};
let server = new pEpServer(log, connectionInfoDetector, new XhrQueue(log));
let adapter = new pEpAdapter(console.log, server);
let pEpController = new pEp([], log, adapter, fs, os);
let b = require('../boilerplate').getController();
let m = require('../mock');
let q, pEpController;
before(() => {
q = m.getQ();
pEpController = b.before(q);
});
after(() => {
q.after();
b.after();
});
describe('pEp Update Identity Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
let result;
@ -32,17 +26,19 @@ describe('pEp Update Identity Feature', () => {
let testId = "test_user_id";
before(() => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[{"address":"test@test.com","fpr":"1737B1324BC4997FCD24D997E9E71570C8644E1C","user_id":"test_user_id","username":"Test User 01","comm_type":56}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = pEpController.update_identity(testMail, testId, testName, testFp);
});
it('should return a Object', () => {
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"update_identity","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":""}],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"address": testMail,
"comm_type": 56,
"fpr": "B39706EF952EC3AF0BA5921A91F792D28B044A71",
"fpr": "1737B1324BC4997FCD24D997E9E71570C8644E1C",
"user_id": testId,
"username": testName,
});
});
});
});
});

+ 4
- 0
tests/legacy-features/README.md View File

@ -0,0 +1,4 @@
The tests here rely on a specific environment in order to succeed. You
will need the adapter service to be running, and you might need to
adjust some expected values like the fingerprint.

tests/features/decrypt_feature_spec.js → tests/legacy-features/decrypt_feature_spec.js View File


tests/features/decrypt_mime_feature_spec.js → tests/legacy-features/decrypt_mime_feature_spec.js View File


tests/features/enc_dec_feature_spec.js → tests/legacy-features/enc_dec_feature_spec.js View File


tests/features/encrypt_feature_spec.js → tests/legacy-features/encrypt_feature_spec.js View File


tests/features/get_mime_decode_message_feature.js → tests/legacy-features/get_mime_decode_message_feature.js View File


tests/features/handshake_feature_spec.js → tests/legacy-features/handshake_feature_spec.js View File


tests/features/result_test_mime.eml → tests/legacy-features/result_test_mime.eml View File


tests/features/test_mime.eml → tests/legacy-features/test_mime.eml View File


+ 35
- 0
tests/mock.js View File

@ -0,0 +1,35 @@
/*
https://github.com/sinonjs/nise/blob/master/lib/fake-server/index.js
https://sinonjs.org/releases/v7.4.2/fake-xhr-and-server/#fake-server
*/
let expect = require('chai').expect
let sinon = require('sinon');
let mocked = true; // unset to use the actual server
function getQ () {
let XhrQueue = require('../chrome/content/modules/xhrQueue');
let s = sinon.fakeServer.create();
s.respondImmediately = true;
let q = new XhrQueue(console.log);
if (mocked) {
q.XMLHttpRequest = s.xhr;
}
q.respondWith = (receive) => {
s.respondWith([200, {}, JSON.stringify(receive)]);
};
q.expectSent = (expected) => {
if (mocked) {
let body = s.getRequest(0).requestBody;
expect(body).to.equal(JSON.stringify(expected));
}
};
q.after = () => {
s.restore();
};
return q;
}
module.exports = {
getQ
}

+ 140
- 0
tests/unit/controller.js View File

@ -0,0 +1,140 @@
/* eslint-disable no-console */
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
let getController = require('../boilerplate').getController();
let expect = require('chai').expect
chai.should();
describe('controller calls', () => {
let result, q, controller;
let testMail = "test@test.com";
let testName = "Test User 01";
let testFp = "B39706EF952EC3AF0BA5921A91F792D28B044A71";
let testId = "test_user_id";
beforeEach(() => {
q = require('../mock').getQ();
controller = getController.before(q);
});
afterEach(() => {
q.after();
getController.after();
});
it('get ongoing rating', () => {
q.respondWith({"jsonrpc":"2.0","id":3,"result":{"outParams":[{"rating":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
let result = controller.getOngoingRating("cfg@pep.security", ["cfg@pep.security", "hk@pep.security"]);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"outgoing_message_rating","params":[{"id":"pEp-0","shortmsg":"test","longmsg":"test","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security"},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security"},{"user_id":"","username":"anonymous","address":"hk@pep.security"}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[]},"0"],"id":1,"jsonrpc":"2.0"});
return result.should.become(3);
});
it('myself', () => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[{"address":"test@test.com","fpr":"1737B1324BC4997FCD24D997E9E71570C8644E1C","user_id":"pEp_own_userId","username":"Test User 01","comm_type":255}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
let result = controller.myself(testMail, "pEp_own_userId", testName, testFp)
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"myself","params":[{"user_id":"pEp_own_userId","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"address": testMail,
"comm_type": 255,
"fpr": "1737B1324BC4997FCD24D997E9E71570C8644E1C",
"user_id": "pEp_own_userId",
"username": testName,
});
});
describe('is pEp user', () => {
it('true', () => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[true],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = controller.is_pEp_user(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"is_pEp_user","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"},true],"id":1,"jsonrpc":"2.0"});
return expect(result).to.eventually.have.property('is_pEp', true);
});
it('false', () => {
q.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[false],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = controller.is_pEp_user(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"is_pEp_user","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"},true],"id":1,"jsonrpc":"2.0"});
return expect(result).to.eventually.have.property('is_pEp', false);
});
});
it('get trustwords', () => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[41,"CRYSTAL ELOPER ACCEPTABLY COHAN CLANKING "],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
let lang = "en";
let identity1 = {
address: "test@test.com",
username: "Test User 01",
fpr: "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97",
user_id: ""
};
let identity2 = {
address: "test2@test.com",
username: "Test User 02",
fpr: "B39706EF952EC3AF0BA5921A91F792D28B044A71",
user_id: ""
};
let result = controller.get_trustwords(identity1, identity2, lang)
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"get_trustwords","params":[{"user_id":"","username":"Test User 01","address":"test@test.com","fpr":"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"},{"user_id":"","username":"Test User 02","address":"test2@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"},"en","OUT","OUT",false],"id":1,"jsonrpc":"2.0"});
return result.should.become("CRYSTAL ELOPER ACCEPTABLY COHAN CLANKING ");
});
it('update identity', () => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[{"address":"test@test.com","fpr":"1737B1324BC4997FCD24D997E9E71570C8644E1C","user_id":"test_user_id","username":"Test User 01","comm_type":56}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
let result = controller.update_identity(testMail, testId, testName, testFp)
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"update_identity","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become({
"address": testMail,
"comm_type": 56,
"fpr": "1737B1324BC4997FCD24D997E9E71570C8644E1C",
"user_id": testId,
"username": testName,
});
});
it('get version', () => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[],"return":{"major":0,"minor":17,"patch":0,"api_version":"0.17.0","name":"(40) Eisenach-Ost","package_version":[null],"engine_version":"1.1.1","pep_protocol_version":"2.1"},"errorstack":["(1 elements cleared)"]}});
let result = controller.getVersion();
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"serverVersion","params":[],"id":1,"jsonrpc":"2.0"});
return result.should.become({
api_version: "0.17.0",
engine_version: "1.1.1",
major: 0,
minor: 17,
name: "(40) Eisenach-Ost",
package_version: [null],
patch: 0,
pep_protocol_version: "2.1",
});
});
it('trust personal key', () => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[],"return":{"status":518,"hex":"0x206 \"PEP_KEY_UNSUITABLE\""},"errorstack":["(1 elements cleared)"]}});
result = controller.trust_personal_key(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"trust_personal_key","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
it('identity rating', () => {
q.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[{"rating":6}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
result = controller.identity_rating(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"identity_rating","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"},["OP"]],"id":1,"jsonrpc":"2.0"});
identity = new pEp.Identity(testMail, testId, testName, testFp);
identity.rating = 6;
return result.should.become(identity);
});
describe('with empty responses', () => {
beforeEach(() => {
q.respondWith({
"jsonrpc":"2.0",
"id":1,
"result":{
"outParams":[],
"return":{
"status":0,
"hex":"0 \"PEP_STATUS_OK\""
},
"errorstack": ["(1 elements cleared)"]
}
});
});
it('key mistrusted', () => {
result = controller.key_mistrusted(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"key_mistrusted","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
it('key reset trust', () => {
result = controller.key_reset_trust(testMail, testId, testName, testFp);
q.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"key_reset_trust","params":[{"user_id":"test_user_id","username":"Test User 01","address":"test@test.com","fpr":"B39706EF952EC3AF0BA5921A91F792D28B044A71"}],"id":1,"jsonrpc":"2.0"});
return result.should.become([]);
});
});
});

Loading…
Cancel
Save