forked from claudio/pEpForThunderbird
parent
8548d92c07
commit
96647989e9
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -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
|
||||
}
|
@ -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…
Reference in new issue