js: more testing of nativeMessaging connection

--

* There were some inconsistencies between utf-8, transfer and browsers'
  utf16, which broke characters that were split between individual
  messages. src/Connection now contains a workaround that reassembles
  javascripts' format from passed base64 strings. This needs someone
  more experienced looking.
* Added several new tests which were failing during initial debugging
  of this issue
* reorganized BrowsertestExtension to avoid cluttering.
This commit is contained in:
Maximilian Krambach 2018-05-09 19:40:57 +02:00
parent 5f5bf024a8
commit c92326cc25
12 changed files with 328 additions and 162 deletions

View File

@ -12,14 +12,11 @@
<script src="libs/chai.js"></script>
<script src="setup_testing.js"></script>
<script src="libs/gpgmejs.bundle.js"></script>
<script src="tests/inputvalues.js"></script>
<script src="libs/gpgmejs_unittests.bundle.js"></script>
<!-- insert tests here-->
<script src="tests/startup.js"></script>
<script src="tests/encryptTest.js"></script>
<script src="tests/encryptDecryptTest.js"></script>
<!-- run tests -->
<script src="runbrowsertest.js"></script>
</body>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="libs/mocha.css" rel="stylesheet" />
</head>
<body>
<h3>gpgmejs - Tests</h3>
<p>
The unittests rely on a separately packaged version of gpgmejs,
with the different classes and functions exposed. These tests and their
input values can be found in gpgme/lang/js/test. They do not test the
overall functionality, but the individual behaviour of the components.
<ul>
<li>
<a href="unittests.html">
Unittests of the individual functions and classes.
</a>
</li>
</ul>
</p>
<p>
The functionality tests, to be found in
gpgme/lang/js/BrowserTestExtension, check the overall functionality of
the standard packaged version of gpgmejs.
<ul>
<li>
<a href="browsertest.html">
Functionality tests using the bundled library.
</a>
</li>
<li>
<a href="longTests.html">
Functionality tests with larger/longer running data sets.
</a>
</li>
</ul>
</p>
</body>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="libs/mocha.css" rel="stylesheet" />
</head>
<body>
<h3>Browsertest</h3>
<div id="mocha"></div>
<!-- load unit tests -->
<script src="libs/mocha.js"></script>
<script src="libs/chai.js"></script>
<script src="setup_testing.js"></script>
<script src="libs/gpgmejs.bundle.js"></script>
<script src="tests/inputvalues.js"></script>
<!-- insert tests here-->
<script src="tests/startup.js"></script>
<script src="tests/longRunningTests.js"></script>
<!-- run tests -->
<script src="runbrowsertest.js"></script>
</body>
</html>

View File

@ -39,6 +39,6 @@
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.create({
url: './browsertest.html'
url: './index.html'
});
});

View File

@ -19,4 +19,3 @@
*/
mocha.run();
Gpgmejs_test.unittests();

View File

@ -0,0 +1,21 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1+
*/
Gpgmejs_test.unittests();
mocha.run();

View File

@ -19,7 +19,7 @@
*/
describe('Encryption and Decryption', function () {
it('Successful encrypt and decrypt', function (done) {
it('Successful encrypt and decrypt simple string', function (done) {
let prm = Gpgmejs.init();
prm.then(function (context) {
context.encrypt(
@ -39,54 +39,6 @@ describe('Encryption and Decryption', function () {
});
});
});
/**
* Fails with random data! Some bytes (up to 100) of the original are missing in
* the result
*/
/**
for (let j = 0; j < 10; j++){
it('Successful encrypt and decrypt specific sets: ',
function (done) {
let prm = Gpgmejs.init();
let data = bigBoringString(5); //see ./inputvalues.js
expect(Object.prototype.toString.call(data)).to.equal("[object String]");
prm.then(function (context) {
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function (result) {
if (data.length !== result.data.length) {
for (let k = 0; k < data.length; k++) {
if (data[k] !== result.data[k]) {
console.log(k);
console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
break;
}
}
}
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
context.connection.disconnect();
done();
});
});
});
}).timeout(5000);
}
it('Roundtrip does not destroy trailing whitespace',
function (done) {
let prm = Gpgmejs.init();
@ -112,15 +64,18 @@ describe('Encryption and Decryption', function () {
});
});
});
}).timeout(3000);
}).timeout(5000);
it('Test with simple non-ascii input',
for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
it('Roundtrip with >1MB non-ascii input meeting default chunksize (' + (j + 1) + '/' + inputvalues.encrypt.good.data_nonascii_32.length + ')',
function (done) {
let input = inputvalues.encrypt.good.data_nonascii_32[j];
expect(input).to.have.length(32);
let prm = Gpgmejs.init();
prm.then(function (context) {
let data = '';
for (let i=0; i < 1024 * 1024 * 0.1; i++){
data += inputvalues.encrypt.good.data_nonascii;
for (let i=0; i < 34 * 1024; i++){
data += input;
}
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
@ -131,49 +86,8 @@ describe('Encryption and Decryption', function () {
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
console.log(answer);
context.decrypt(answer.data).then(
function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
if (data.length !== result.data.length) {
for (let k = 0; k < data.length; k++) {
if (data[k] !== result.data[k]) {
console.log(k);
console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
break;
}
}
}
console.log(data.length - result.data.length);
expect(result.data).to.equal(data);
context.connection.disconnect();
done();
});
});
});
}).timeout(3000);
*/
/**
for (let i=0; i< 100; i++) {
it('Successful encrypt random data '+ (i+1) + '/100', function (done) {
let prm = Gpgmejs.init();
let data = bigString(0.2); // << set source data here
prm.then(function (context) {
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function(result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
@ -184,36 +98,9 @@ describe('Encryption and Decryption', function () {
});
}).timeout(5000);
};
*/
/** still fails
it('Successful encrypt 0.8 MB Uint8Array', function (done) {
let prm = Gpgmejs.init();
let data = bigUint8(0.8);
prm.then(function (context) {
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function(result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(5000);
*/
it('Decrypt simple non-ascii',
function (done) {
it('Encrypt-decrypt simple non-ascii', function (done) {
//FAILS TODO: Check newline at the end
let prm = Gpgmejs.init();
prm.then(function (context) {
data = encryptedData;
@ -225,7 +112,7 @@ describe('Encryption and Decryption', function () {
context.encrypt(inputvalues.encrypt.good.data_nonascii, inputvalues.encrypt.good.fingerprint).then(
function(result){
context.decrypt(result.data).then(function(answer){
expect(answer.data).to.equal(inputvalues.encrypt.good.data_nonascii);
expect(answer.data).to.equal('¡Äußerste µ€ før ñoquis@hóme! Добрый день');
context.connection.disconnect();
done();
});
@ -233,6 +120,6 @@ describe('Encryption and Decryption', function () {
});
});
}).timeout(8000);
}).timeout(6000);
});

View File

@ -49,7 +49,7 @@ describe('Encryption', function () {
done();
});
});
}).timeout(5000);
}).timeout(10000);
/**
it('Successful encrypt 20 MB', function (done) {

View File

@ -23,7 +23,23 @@ var inputvalues = {
good:{
data : 'Hello World.',
fingerprint : 'D41735B91236FDB882048C5A2301635EEFF0CB05',
data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день\n'
data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день',
data_nonascii_32: [
'K€K€K€K€K€K€K€K€K€K€K€K€K€K€K€K€',
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€', //fails result has 3 chars more
'€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€', //fails 3 chars
'²³²³²³²³²³²³²³²³²³²³²³²³²³²³²³²³',
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€A€µ€µ€µ€µ€', //fails 2 chars
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µAµ€µ€µ€µ€', //is okay if 2 chunksizes.
'üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü',
'µAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA€',
'µAAAAµAAAAAAAAAAAAAAAAAAAAAAAAA€',
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAµ€',
'µAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA°',
'€AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA€',
'µ||||||||||||||||||||||||||||||€',
'æſæſ³¼„¬“³³¬“¬½”æſæſ³¼„¬“³³¬“¬½”'
]
},
bad: {
fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
@ -56,7 +72,7 @@ function bigUint8(megabytes){
function bigBoringString(megabytes){
let maxlength = 1024 * 1024 * megabytes;
let string = '';
let chars = ' ä0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let chars = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let i= 0; i < maxlength; i++){
string = string + chars[Math.floor(Math.random() * chars.length)];
}
@ -102,3 +118,100 @@ var encryptedData =
'kSAQYOHplfA7YJWkrlRm\n' +
'=zap6\n' +
'-----END PGP MESSAGE-----\n';
var encryptedBroken = '-----BEGIN PGP MESSAGE-----\n' +
'\n' +
'hQEMA6B8jfIUScGEAQf/bUYF70KRCHWITfNH7zaYaLa8P+QoCo+NpFzc3U9J4mty\n' +
'FxjIpoNwxEvQ9UUEMi6LgHhvURYCbWrCV5XYjo/sE66CRXsEuNirfYkAzXVNcUf7\n' +
'BaAzio/QzyyvBfzwHHqMLSxAcNggs+f5lob+TcBnBghwpn1lh5BgNUuhDKVq21/F\n' +
'wWK4rqjmmjrpoR3tKcl916+/Z0VI5SAkPG4IrWUfumxG0xbePB9IFT8uGMmXy2qr\n' +
'ICmEfPakLUIo7NLrdMNInnVQaAeNS/5u5TbpZpRxZWtRP7m4EyUoEA+TgSkp+hG8\n' +
'Um7hmbFsB99H0yiyCSLicN5AxzmgCrL3D77Fqh7LaNLsAYjcyVZm+R7te4vwpv9P\n' +
'F/MCAEUFKGfNYHqyVjBhBlm4/PMC+YtOE9jF920hwtDckT/V3L2POk1Kr78+nVjw\n' +
'1HXTfK/Tk6QMGrzCd2ril5aB2RCi+Fr41B2ftS8SLwcrnrFkP2enH6VYBserx5l8\n' +
'qZlgRR53QNnLvqnn7h/NO1ZNN5cnD2pf0PWBkSHmr5ph82JQ+XyB0h4eV1kwX80K\n' +
'8IkBAq6hFpfm7TU4gy5x1VNTeVoCRdlzESkzVwbvjNZ+OU6+vcpfCaHMbuVBUmYz\n' +
'xjTKYlenevSzwfF1RY7noDTrPUQrBrVor2cPjN3ROLCbFpARrQf44BfzGaq5XdWc\n' +
'NZWFgiRKVGVJQeBQjRyqHAv4e8rkcr5qwnY8kyZpLYAKIVBgtqnh7GExaW5efWRG\n' +
'tyJMgUuP+dF/+HymhlEmMKZabLf5W8J3p8+uBOkU359O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uuNSF/iI0tANw5twlQjdRQtqxnF1yETh/hFA4bgD9bmBOBFd+GT\n' +
'+ECxkqI4/UYMgYfVMFja/e6+dQTWLblzuNaZh6wHASeNqpFmeQSBawBVV7qK3nC7\n' +
'CDY9r6Aq9JYMiJTE/TzyfBmBhnxtL1aKTu6EHy3siDlID7EjQx1Xyr/EtbJCmsVl\n' +
'E14StpggdK8=\n' +
'=enm3\n' +
'-----END PGP MESSAGE-----\n';

View File

@ -0,0 +1,53 @@
describe('Long running Encryption/Decryption', function () {
for (let i=0; i< 100; i++) {
it('Successful encrypt/decrypt completely random data ' + (i+1) + '/100', function (done) {
let prm = Gpgmejs.init();
let data = bigString(2);
prm.then(function (context) {
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function(result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
context.connection.disconnect();
done();
});
});
});
}).timeout(5000);
};
it('Successful encrypt 1 MB Uint8Array', function (done) {
let prm = Gpgmejs.init();
let data = bigUint8(1);
prm.then(function (context) {
context.encrypt(data,
inputvalues.encrypt.good.fingerprint).then(
function (answer){
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function(result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(5000);
});

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="libs/mocha.css" rel="stylesheet" />
</head>
<body>
<h3>Unit tests</h3>
<div id="mocha"></div>
<script src="libs/mocha.js"></script>
<script src="libs/chai.js"></script>
<script src="setup_testing.js"></script>
<script src="libs/gpgmejs_unittests.bundle.js"></script>
<script src="rununittests.js"></script>
</body>
</html>

View File

@ -181,7 +181,8 @@ class Answer{
if (!this._response.hasOwnProperty(key)){
this._response[key] = '';
}
this._response[key] = this._response[key].concat(msg[key]);
// console.log(msg[key]);
this._response[key] += msg[key];
}
//params should not change through the message
else if (poa.params.indexOf(key) >= 0){
@ -214,6 +215,22 @@ class Answer{
* TODO: does not care yet if completed.
*/
get message(){
let keys = Object.keys(this._response);
let poa = permittedOperations[this.operation].answer;
for (let i=0; i < keys.length; i++) {
if (poa.data.indexOf(keys[i]) >= 0){
if (this._response.base64 == true){
let respatob = atob(this._response[keys[i]]);
let result = decodeURIComponent(
respatob.split('').map(function(c) {
return '%' +
('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
this._response[keys[i]] = result;
}
}
}
return this._response;
}
}