Browse Source

Fixing decryption tests. Pending to check if decrypt is really correct or test cases are wrong.

1.1.101
Chris Fuertes 3 years ago
parent
commit
7b7626cfe1
9 changed files with 116 additions and 233 deletions
  1. +53
    -39
      chrome/content/modules/pEpAdapter.js
  2. +0
    -133
      chrome/content/modules/pEpServer.js
  3. +2
    -6
      chrome/content/modules/xhrQueue.js
  4. +14
    -3
      package-lock.json
  5. +1
    -0
      package.json
  6. +6
    -6
      tests/config/testSetup.js
  7. +38
    -44
      tests/features/decrypt_feature_spec.js
  8. +1
    -1
      tests/features/encrypt_feature_spec.js
  9. +1
    -1
      tests/features/get_version_feature_spec.js

+ 53
- 39
chrome/content/modules/pEpAdapter.js View File

@ -53,9 +53,7 @@ class pEpAdapter {
this.requestId++;
let msgId = PEP_PREFIX + this.requestId;
subject = "pEp"; // CHECK
let message = new pEpAdapter.pEpMessage(msgId, subject, null, sender, to, DIR_INCOMING);
let message = new pEpAdapter.pEpMessage(msgId, subject, body, sender, to, DIR_INCOMING);
if (cc) {
message.cc = cc;
@ -74,41 +72,57 @@ class pEpAdapter {
0 // flags output
];
console.debug(params);
console.debug(params[0].attachments);
try {
return await this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_DECRYPT,
params,
response => {
let result = response.result.outParams;
this.log("pEpAdapter.js: decrypt() success: ", result);
const pEp_message = result[3];
return {
longmsg: pEp_message.longmsg,
shortmsg: pEp_message.shortmsg,
persons: {
from: pEp_message.from,
to: pEp_message.to,
cc: pEp_message.cc,
reply_to: pEp_message.reply_to
},
rating: result[1].rating,
fpr: result[2]
}
},
err => {
this.log("this is an error", err);
return null;
return await this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_DECRYPT,
params
).then((response) => {
this.log("pEpAdapter.js: decrypt() success: ", response);
if ((typeof(response) === "object") && response.hasOwnProperty("error")) {
switch (response.error.code) {
case PEP_WRONG_SEC_TOKEN_CODE:
throw new Error({code: "PEP-ERROR", message: "Invalid Security Token", response});
break;
case -32603:
console.log("2222", response.error.data.params[0].to);
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
break;
}
);
} catch (e) {
this.log("pEpAdapter.js: decrypt() error: ", e);
return null;
}
}
if (!(typeof response === "object" &&
response.hasOwnProperty("result") &&
response.result.hasOwnProperty("return"))) {
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
}
let decryptedMessage = {};
if (response.result.return.hasOwnProperty("status")) {
switch (response.result.return.status) {
case(PEP_RESPONSE_OK):
case(PEP_RESPONSE_DECRYPTED):
console.log(response.result.outParams);
decryptedMessage = response.result.outParams[4];
this.log("callPepAdapter: '" + "decrypt" + "' returned with success: ", response);
break;
case(PEP_RESPONSE_UNENCRYPTED):
decryptedMessage = message;
this.log("callPepAdapter: '" + "decrypt" + "' returned with UNENCRYPTED status: ", response);
break;
default:
this.log("callPepAdapter: '" + "decrypt" + "' returned with error: ", response);
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
}
}
return decryptedMessage;
}).catch( (err) => {
this.log(err);
});
}
async encrypt(subject, body, from, to = [], stringlist = [], encodingFormat = ENC_FORMAT_PEP) {
@ -153,12 +167,12 @@ class pEpAdapter {
case(PEP_RESPONSE_OK):
case(PEP_RESPONSE_DECRYPTED):
encryptedMessage = response.result.outParams[0];
this.log("callPepAdapter: '" + "encrypt" + "' returned with success: ", response, response);
this.log("callPepAdapter: '" + "encrypt" + "' returned with success: ", response);
break;
case(PEP_RESPONSE_UNENCRYPTED):
encryptedMessage = message;
this.log("callPepAdapter: '" + "encrypt" + "' returned with UNENCRYPTED status: ", response, response);
this.log("callPepAdapter: '" + "encrypt" + "' returned with UNENCRYPTED status: ", response);
break;
default:


+ 0
- 133
chrome/content/modules/pEpServer.js View File

@ -1,8 +1,5 @@
const EXPORTED_SYMBOLS = ["pEpServer"];
const getOnErrorCallback = Symbol('getOnErrorCallback');
const getOnLoadCallback = Symbol('getOnLoadCallback');
let pepServerInstance;
const MIN_REQUIRED_VERSION = "0.14.0";
const MAX_RETRY_ATTEMPTS = 2;
@ -229,104 +226,6 @@ class pEpServer {
return that.xhrQueue.executeXhr({url: url, data: data});
}
[getOnLoadCallback](params) {
let deferred = params.deferred;
let functionName = params.functionName;
let paramsArr = params.paramsArr;
let loadListener = params.loadListener;
let errorListener = params.errorListener;
let that = this;
let retryCall = () => {
that.retryCount++;
if (that.retryCount < MAX_RETRY_ATTEMPTS) {
that.registerListener()
.then(() => {
that.callPepAdapter(SERVER_TYPE_CALL_FUNC, functionName, paramsArr);
});
}
else {
//TODO Stop retying
}
};
return (responseText) => {
let response, parsedObj;
try {
parsedObj = that.utils.parseJSON(responseText);
if ((typeof(parsedObj) === "object") && parsedObj.hasOwnProperty("error")) {
if (parsedObj.error.code === PEP_WRONG_SEC_TOKEN_CODE) {
// wrong security token
//that.reloadConnectionInfo();
//retryCall();
}
}
else {
that.retryCount = 0;
}
if (typeof parsedObj === "object" &&
parsedObj.hasOwnProperty("result") &&
parsedObj.result.hasOwnProperty("return")) {
if (parsedObj.result.return.hasOwnProperty("status")) {
switch (parsedObj.result.return.status) {
case(PEP_RESPONSE_OK):
case(PEP_RESPONSE_DECRYPTED):
response = loadListener(parsedObj);
that.log("callPepAdapter: '" + functionName + "' returned with success: ", response, parsedObj);
deferred.resolve(response);
break;
case(PEP_RESPONSE_UNENCRYPTED):
response = loadListener(parsedObj);
that.log("callPepAdapter: '" + functionName + "' returned with UNENCRYPTED status: ", response, parsedObj);
deferred.resolve(response);
break;
default:
that.log("callPepAdapter: '" + functionName + "' returned with error: ", parsedObj);
deferred.reject({code: "PEP-ERROR", message: parsedObj.error.message, parsedObj});
}
} else {
deferred.resolve(loadListener(parsedObj));
}
} else {
deferred.reject({code: "PEP-ERROR", message: parsedObj.error.message, parsedObj});
}
}
catch (ex) {
deferred.reject(that.utils.getErrorObject("PEP-ERROR", ex, parsedObj));
}
};
}
[getOnErrorCallback](params) {
let deferred = params.deferred;
let shuttingDown = params.shuttingDown;
let that = this;
return (error) => {
that.log("XMLHttpRequest: got error: ", error);
that.xhrQueue.dropCurrentXhr();
if (!shuttingDown) {
that.startServer(deferred);
}
else {
deferred.resolve({
result: -1
});
}
}
}
getAdapterVersion() {
//TODO To be implemented: Call executable with --version argument and parse the result
return "0.0.0";
@ -351,38 +250,6 @@ class pEpServer {
resetConnectionInfo() {
this.connectionInfo = null;
}
// registerListener() {
// this.log("registerListener()");
//
// try {
// if (gTbListener) {
// let params = [
// "127.0.0.1",
// gTbListener.port,
// gTbListener.securityToken
// ];
//
// return this.callPepAdapter(FT_CALL_FUNCTION, "registerEventListener", params);
// }
// else {
// let deferred = this.utils.deferred();
// deferred.resolve(0);
// return deferred.promise;
// }
//
// }
// catch (ex) {
// let deferred = this.utils.deferred();
// deferred.reject(this.utils.getErrorObject("PEP-ERROR", ex));
// return deferred.promise;
// }
// }
reloadConnectionInfo() {
this.resetConnectionInfo();
this.loadConnectionInfo();
}
}
// export common.js module to allow one js file for browser and node.js


+ 2
- 6
chrome/content/modules/xhrQueue.js View File

@ -38,8 +38,8 @@ class XhrQueue {
xhr.onerror = () => {
reject({
status: xhr.status,
statusText: xhr.statusText
status: xhr.status || 500,
statusText: xhr.statusText || "pEp engine not available"
});
};
@ -47,10 +47,6 @@ class XhrQueue {
}
);
}
dropCurrentXhr() {
this.log("xhrQueue.js dropCurrentXhr()");
}
}
// export common.js module to allow one js file for browser and node.js


+ 14
- 3
package-lock.json View File

@ -143,6 +143,12 @@
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
"dev": true
},
"atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
"dev": true
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -465,6 +471,7 @@
"version": "0.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"kind-of": "^3.0.2",
"longest": "^1.0.1",
@ -789,7 +796,8 @@
"is-buffer": {
"version": "1.1.6",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"is-builtin-module": {
"version": "1.0.0",
@ -873,6 +881,7 @@
"version": "3.2.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"is-buffer": "^1.1.5"
}
@ -919,7 +928,8 @@
"longest": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"lru-cache": {
"version": "4.1.3",
@ -1185,7 +1195,8 @@
"repeat-string": {
"version": "1.6.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"require-directory": {
"version": "2.1.1",


+ 1
- 0
package.json View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"atob": "^2.1.2",
"btoa": "^1.2.1",
"chai": "*",
"chai-as-promised": "*",


+ 6
- 6
tests/config/testSetup.js View File

@ -5,9 +5,9 @@ let should = chai.should();
global.should = should;
global.describe = describe;
let connectionInfo = {
address: "127.0.0.1",
port: 4226,
path: "/ja/0.1/",
security_token: "AeAndGiiv1PjIYvEuWd_SV9DG78DQ359yOMN9jf"
};
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');

+ 38
- 44
tests/features/decrypt_feature_spec.js View File

@ -1,32 +1,31 @@
/* eslint-disable no-console */
let {describe, it, before, beforeEach}= require('mocha');
let {describe, it, before, beforeEach} = require('mocha');
let chai = require('chai').use(require('chai-as-promised'));
chai.should();
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');
let btoa = require('btoa');
let pEpAdapter = require('../../chrome/content/modules/pEpAdapter');
let pEpServer = require('../../chrome/content/modules/pEpServer');
let pEpUtils = require('../../chrome/content/modules/utils');
let XhrQueue = require('../../chrome/content/modules/xhrQueue');
require('../config/testSetup');
let log = console.log;
let core;
let os;
let env;
let path = "~/.pEp/";
let connectionInfo = {
address: "127.0.0.1",
port: 4224,
path: "/ja/0.1/",
security_token: "jvaCBNfo7SjWKqZmekH_k0wZvwUOBzn6CpGS58x"
};
let fs = require('fs');
let connectionInfo = JSON.parse(fs.readFileSync('/Users/chris/.pEp/json-token', 'utf8'));
let files;
let utils = pEpUtils;
let deferred;
let body;
let subject;
describe('pEp Decrypt Feature', () => {
//TODO Launch a pEp Desktop Adapter instance before each test
describe('Perfect scenario', () => {
@ -35,9 +34,8 @@ describe('pEp Decrypt Feature', () => {
before(() => {
let server = new pEpServer(log, core, os, env, path, connectionInfo, XhrQueue, files, utils);
adapter = new pEpAdapter(console.log, server);
let subject = "pEp";
let body = `
-----BEGIN PGP MESSAGE-----
subject = "pEp";
body = `-----BEGIN PGP MESSAGE-----
hQEMAx0paFCrfYQUAQgAhfuzjEIRRh8PWOX9U/0uk8b5x5fl5IEO7dZI6UjnyAdA
anF/1Cm3ICcFXckisyJ6NHhKDZMqEF0Ai9YOh5EhkD+mQD2ugTyBr7uanWOCg9nM
@ -107,33 +105,29 @@ VTQr+PjzxicL
});
it('should return a Object', () => {
return result.should.become({
longmsg: "Test Body",
shortmsg: "Test Subject",
persons: {
"from": {
"address": "huss@pep-project.org",
"comm_type": 56,
"fpr": "5CC67646D67A33D8A2E4FF849E61B9BC790E6B02",
"user_id": "790E6B02",
"username": "Hussein Kasem",
},
"to": [
{
"address": "cfg@pep.security",
"comm_type": 0,
"user_id": "95E4A594",
"username": "Chris",
}
],
"reply_to": undefined,
"cc": undefined
longmsg: body,
shortmsg: subject,
attachments: [{
size: body.length,
value: btoa(body)
}],
id: "pEp-1",
"from": {
"address": "huss@pep-project.org",
"comm_type": 56,
"fpr": "5CC67646D67A33D8A2E4FF849E61B9BC790E6B02",
"user_id": "790E6B02",
"username": "Hussein Kasem",
},
rating: 5,
"fpr": [
"",
"5CC67646D67A33D8A2E4FF849E61B9BC790E6B02",
"B2775D7B919C9E28EC1B9B492C0E8DE595E4A594",
]
"to": [
{
"address": "cfg@pep.security",
"comm_type": 0,
"username": "Chris",
}
],
"enc_format": 1
});
});
});

+ 1
- 1
tests/features/encrypt_feature_spec.js View File

@ -19,7 +19,7 @@ let connectionInfo = {
address: "127.0.0.1",
port: 4224,
path: "/ja/0.1/",
security_token: "HOdjCjqgtQ5S33i1k4n_GO8jjz2Gi1njFfKZz1k"
security_token: "TytpHpjT0ehl8aSeqPn_0ziKbfXQ1PmL7IKxKpr"
};
let files;
let utils = pEpUtils;


+ 1
- 1
tests/features/get_version_feature_spec.js View File

@ -18,7 +18,7 @@ let connectionInfo = {
address: "127.0.0.1",
port: 4224,
path: "/ja/0.1/",
security_token: "HOdjCjqgtQ5S33i1k4n_GO8jjz2Gi1njFfKZz1k"
security_token: "TytpHpjT0ehl8aSeqPn_0ziKbfXQ1PmL7IKxKpr"
};
let files;
let utils = pEpUtils;


Loading…
Cancel
Save