js: clean up test extension
-- Tests will now run with one instance of gpgmejs each block, which reduces overhead. Readability is (hopefully) improved), some negative tests are added. There is still a performance problem in base64 encoding/decoding, which causes some tests to fail due to time out.
This commit is contained in:
parent
4b343c4e33
commit
b18b96fb36
@ -22,18 +22,25 @@
|
|||||||
* Raimund Renkert <rrenkert@intevation.de>
|
* Raimund Renkert <rrenkert@intevation.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global describe, it, expect, Gpgmejs, ImportablePublicKey, inputvalues */
|
/* global describe, it, expect, before, afterEach, Gpgmejs*/
|
||||||
|
/* global ImportablePublicKey, inputvalues */
|
||||||
|
|
||||||
describe('Key importing', function () {
|
describe('Key importing', function () {
|
||||||
it('Prepare test Key (deleting it from gnupg, if present)', function(done){
|
const fpr = ImportablePublicKey.fingerprint;
|
||||||
let prm = Gpgmejs.init();
|
const pubKey = ImportablePublicKey.key;
|
||||||
prm.then(function (context) {
|
const changedKey = ImportablePublicKey.keyChangedUserId;
|
||||||
expect(context.Keyring.getKeys).to.be.a('function');
|
|
||||||
context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
|
let context = null;
|
||||||
|
before(function(done){
|
||||||
|
const prm = Gpgmejs.init();
|
||||||
|
prm.then(function(gpgmejs){
|
||||||
|
context = gpgmejs;
|
||||||
|
context.Keyring.getKeys(fpr).then(
|
||||||
function(result){
|
function(result){
|
||||||
if (result.length === 1) {
|
if (result.length === 1) {
|
||||||
result[0].delete().then(function(result){
|
result[0].delete().then(function(){
|
||||||
expect(result).to.be.true;
|
done();
|
||||||
|
},function(){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -43,76 +50,79 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('importing, updating, then deleting public Key', function (done) {
|
afterEach(function(done){
|
||||||
//This test runs in one large step, to ensure the proper state of the
|
// delete the test key if still present
|
||||||
// key in all stages.
|
context.Keyring.getKeys(fpr).then(
|
||||||
let prm = Gpgmejs.init();
|
function(result){
|
||||||
prm.then(function (context) {
|
if (result.length === 1) {
|
||||||
context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
|
result[0].delete().then(function(){
|
||||||
function(result){
|
done();
|
||||||
expect(result).to.be.an('array');
|
},function(){
|
||||||
expect(result.length).to.equal(0);
|
done();
|
||||||
context.Keyring.importKey(ImportablePublicKey.key, true)
|
});
|
||||||
.then(function(result){
|
} else {
|
||||||
expect(result.Keys[0]).to.not.be.undefined;
|
done();
|
||||||
expect(result.Keys[0].key).to.be.an('object');
|
}
|
||||||
expect(result.Keys[0].key.fingerprint).to.equal(
|
});
|
||||||
ImportablePublicKey.fingerprint);
|
});
|
||||||
expect(result.Keys[0].status).to.equal('newkey');
|
|
||||||
context.Keyring.importKey(
|
it('Importing Key', function (done) {
|
||||||
ImportablePublicKey.keyChangedUserId,true)
|
context.Keyring.getKeys(fpr).then(function(result){
|
||||||
.then(function(res){
|
expect(result).to.be.an('array');
|
||||||
expect(res.Keys[0]).to.not.be.undefined;
|
expect(result.length).to.equal(0);
|
||||||
expect(res.Keys[0].key).to.be.an('object');
|
context.Keyring.importKey(pubKey).then(function(result){
|
||||||
expect(res.Keys[0].key.fingerprint).to.equal(
|
expect(result[0]).to.not.be.undefined;
|
||||||
ImportablePublicKey.fingerprint);
|
expect(result[0].key).to.be.an('object');
|
||||||
expect(res.Keys[0].status).to.equal(
|
expect(result[0].key.fingerprint).to.equal(fpr);
|
||||||
'change');
|
expect(result[0].status).to.equal('newkey');
|
||||||
expect(
|
done();
|
||||||
res.Keys[0].changes.userId).to.be.true;
|
});
|
||||||
expect(
|
});
|
||||||
res.Keys[0].changes.subkey).to.be.false;
|
});
|
||||||
expect(
|
|
||||||
res.Keys[0].changes.signature).to.be.true;
|
it('Updating Key', function(done){
|
||||||
res.Keys[0].key.delete().then(function(result){
|
context.Keyring.importKey(pubKey)
|
||||||
expect(result).to.be.true;
|
.then(function(result){
|
||||||
done();
|
expect(result[0].key).to.not.be.undefined;
|
||||||
});
|
expect(result[0].status).to.equal('newkey');
|
||||||
});
|
context.Keyring.importKey(changedKey).then(function(res){
|
||||||
});
|
expect(res[0].key).to.be.an('object');
|
||||||
|
expect(res[0].key.fingerprint).to.equal(fpr);
|
||||||
|
expect(res[0].status).to.equal('change');
|
||||||
|
expect(res[0].changes.userId).to.be.true;
|
||||||
|
expect(res[0].changes.subkey).to.be.false;
|
||||||
|
expect(res[0].changes.signature).to.be.true;
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Deleting Key', function(done) {
|
||||||
|
context.Keyring.importKey(pubKey).then(function(result){
|
||||||
|
expect(result[0].key).to.be.an('object');
|
||||||
|
expect(result[0].key.fingerprint).to.equal(fpr);
|
||||||
|
result[0].key.delete().then(function(result){
|
||||||
|
expect(result).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Import result feedback', function(done){
|
it('Import result feedback', function(done){
|
||||||
let prm = Gpgmejs.init();
|
context.Keyring.importKey(pubKey, true).then(function(result){
|
||||||
prm.then(function (context) {
|
expect(result).to.be.an('object');
|
||||||
context.Keyring.getKeys(ImportablePublicKey.fingerprint).then(
|
expect(result.Keys[0]).to.be.an('object');
|
||||||
function(result){
|
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
|
||||||
expect(result).to.be.an('array');
|
expect(result.Keys[0].status).to.equal('newkey');
|
||||||
expect(result.length).to.equal(0);
|
result.Keys[0].key.getArmor().then(function(armor){
|
||||||
context.Keyring.importKey(ImportablePublicKey.key, true)
|
expect(armor).to.be.a('string');
|
||||||
.then(function(result){
|
done();
|
||||||
expect(result).to.be.an('object');
|
});
|
||||||
expect(result.Keys[0]).to.be.an('object');
|
|
||||||
expect(result.Keys[0].key.fingerprint).to.equal(
|
|
||||||
ImportablePublicKey.fingerprint);
|
|
||||||
expect(result.Keys[0].status).to.equal('newkey');
|
|
||||||
result.Keys[0].key.getArmor().then(function(armor){
|
|
||||||
expect(armor).to.be.a('string');
|
|
||||||
result.Keys[0].key.delete().then(function(){
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('exporting armored Key with getKeysArmored', function (done) {
|
it('exporting armored Key with getKeysArmored', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
context.Keyring.importKey(pubKey).then(function(){
|
||||||
const fpr = inputvalues.encrypt.good.fingerprint;
|
|
||||||
prm.then(function (context) {
|
|
||||||
context.Keyring.getKeysArmored(fpr).then(function(result){
|
context.Keyring.getKeysArmored(fpr).then(function(result){
|
||||||
expect(result).to.be.an('object');
|
expect(result).to.be.an('object');
|
||||||
expect(result.armored).to.be.a('string');
|
expect(result.armored).to.be.a('string');
|
||||||
@ -121,18 +131,15 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('exporting armored Key (including secret fingerprints) with '
|
|
||||||
+ 'getKeysArmored', function (done) {
|
it('Exporting Key (including secret fingerprints)', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const key_secret = inputvalues.encrypt.good.fingerprint;
|
||||||
const fpr = inputvalues.encrypt.good.fingerprint;
|
context.Keyring.getKeysArmored(key_secret, true).then(function(result){
|
||||||
prm.then(function (context) {
|
expect(result).to.be.an('object');
|
||||||
context.Keyring.getKeysArmored(fpr, true).then(function(result){
|
expect(result.armored).to.be.a('string');
|
||||||
expect(result).to.be.an('object');
|
expect(result.secret_fprs).to.be.an('array');
|
||||||
expect(result.armored).to.be.a('string');
|
expect(result.secret_fprs[0]).to.equal(key_secret);
|
||||||
expect(result.secret_fprs).to.be.an('array');
|
done();
|
||||||
expect(result.secret_fprs[0]).to.equal(fpr);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -21,72 +21,124 @@
|
|||||||
* Maximilian Krambach <mkrambach@intevation.de>
|
* Maximilian Krambach <mkrambach@intevation.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global describe, it, expect, Gpgmejs */
|
/* global describe, it, expect, before, Gpgmejs */
|
||||||
/* global inputvalues, encryptedData, bigString, bigBoringString */
|
/* global inputvalues, encryptedData, bigString, bigBoringString */
|
||||||
|
|
||||||
describe('Encryption and Decryption', function () {
|
describe('Encryption and Decryption', function () {
|
||||||
|
let context = null;
|
||||||
|
let good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
|
|
||||||
|
before(function(done){
|
||||||
|
const prm = Gpgmejs.init();
|
||||||
|
prm.then(function(gpgmejs){
|
||||||
|
context = gpgmejs;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Successful encrypt and decrypt simple string', function (done) {
|
it('Successful encrypt and decrypt simple string', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
let data = inputvalues.encrypt.good.data;
|
||||||
prm.then(function (context) {
|
context.encrypt(data, good_fpr).then(function (answer) {
|
||||||
context.encrypt(
|
expect(answer).to.not.be.empty;
|
||||||
inputvalues.encrypt.good.data,
|
expect(answer.data).to.be.a('string');
|
||||||
inputvalues.encrypt.good.fingerprint).then(
|
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
||||||
function (answer) {
|
expect(answer.data).to.include('END PGP MESSAGE');
|
||||||
expect(answer).to.not.be.empty;
|
|
||||||
expect(answer.data).to.be.a('string');
|
context.decrypt(answer.data).then(function (result) {
|
||||||
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
expect(result).to.not.be.empty;
|
||||||
expect(answer.data).to.include('END PGP MESSAGE');
|
expect(result.data).to.be.a('string');
|
||||||
context.decrypt(answer.data).then(function (result) {
|
expect(result.data).to.equal(
|
||||||
expect(result).to.not.be.empty;
|
inputvalues.encrypt.good.data);
|
||||||
expect(result.data).to.be.a('string');
|
done();
|
||||||
expect(result.data).to.equal(
|
});
|
||||||
inputvalues.encrypt.good.data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Decrypt simple non-ascii', function (done) {
|
it('Decrypt simple non-ascii', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
let data = encryptedData;
|
||||||
prm.then(function (context) {
|
context.decrypt(data).then(function (result) {
|
||||||
let data = encryptedData;
|
expect(result).to.not.be.empty;
|
||||||
context.decrypt(data).then(
|
expect(result.data).to.be.a('string');
|
||||||
|
expect(result.data).to.equal(
|
||||||
|
'¡Äußerste µ€ før ñoquis@hóme! Добрый день\n');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).timeout(3000);
|
||||||
|
|
||||||
|
it('Trailing whitespace and different line endings', function (done) {
|
||||||
|
const data = 'Keks. \rKeks \n Keks \r\n';
|
||||||
|
context.encrypt(data, good_fpr).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('Random data, as string', function (done) {
|
||||||
|
let data = bigString(1000);
|
||||||
|
context.encrypt(data, good_fpr).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(3000);
|
||||||
|
|
||||||
|
it('Data, input as base64', function (done) {
|
||||||
|
let data = inputvalues.encrypt.good.data;
|
||||||
|
let b64data = btoa(data);
|
||||||
|
context.encrypt(b64data, good_fpr, true).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) {
|
function (result) {
|
||||||
expect(result).to.not.be.empty;
|
expect(result).to.not.be.empty;
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.data).to.equal(
|
expect(data).to.equal(data);
|
||||||
'¡Äußerste µ€ før ñoquis@hóme! Добрый день\n');
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).timeout(3000);
|
}).timeout(3000);
|
||||||
|
|
||||||
it('Roundtrip does not destroy trailing whitespace',
|
it('Random data, input as base64', function (done) {
|
||||||
function (done) {
|
let data = bigBoringString(0.001);
|
||||||
let prm = Gpgmejs.init();
|
let b64data = btoa(data);
|
||||||
prm.then(function (context) {
|
context.encrypt(b64data, good_fpr, true).then(function (answer) {
|
||||||
let data = 'Keks. \rKeks \n Keks \r\n';
|
expect(answer).to.not.be.empty;
|
||||||
context.encrypt(data,
|
expect(answer.data).to.be.a('string');
|
||||||
inputvalues.encrypt.good.fingerprint).then(
|
expect(answer.data).to.include(
|
||||||
function (answer) {
|
'BEGIN PGP MESSAGE');
|
||||||
expect(answer).to.not.be.empty;
|
expect(answer.data).to.include(
|
||||||
expect(answer.data).to.be.a('string');
|
'END PGP MESSAGE');
|
||||||
expect(answer.data).to.include(
|
context.decrypt(answer.data).then(
|
||||||
'BEGIN PGP MESSAGE');
|
function (result) {
|
||||||
expect(answer.data).to.include(
|
expect(result).to.not.be.empty;
|
||||||
'END PGP MESSAGE');
|
expect(result.data).to.be.a('string');
|
||||||
context.decrypt(answer.data).then(
|
expect(result.data).to.equal(b64data);
|
||||||
function (result) {
|
done();
|
||||||
expect(result).to.not.be.empty;
|
});
|
||||||
expect(result.data).to.be.a('string');
|
});
|
||||||
expect(result.data).to.equal(data);
|
}).timeout(3000);
|
||||||
done();
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).timeout(5000);
|
|
||||||
|
|
||||||
for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
|
for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
|
||||||
it('Roundtrip with >1MB non-ascii input meeting default chunksize (' +
|
it('Roundtrip with >1MB non-ascii input meeting default chunksize (' +
|
||||||
@ -95,105 +147,24 @@ describe('Encryption and Decryption', function () {
|
|||||||
function (done) {
|
function (done) {
|
||||||
let input = inputvalues.encrypt.good.data_nonascii_32[j];
|
let input = inputvalues.encrypt.good.data_nonascii_32[j];
|
||||||
expect(input).to.have.length(32);
|
expect(input).to.have.length(32);
|
||||||
let prm = Gpgmejs.init();
|
let data = '';
|
||||||
prm.then(function (context) {
|
for (let i=0; i < 34 * 1024; i++){
|
||||||
let data = '';
|
data += input;
|
||||||
for (let i=0; i < 34 * 1024; i++){
|
}
|
||||||
data += input;
|
context.encrypt(data,good_fpr).then(function (answer) {
|
||||||
}
|
expect(answer).to.not.be.empty;
|
||||||
context.encrypt(data,
|
expect(answer.data).to.be.a('string');
|
||||||
inputvalues.encrypt.good.fingerprint).then(
|
expect(answer.data).to.include(
|
||||||
function (answer) {
|
'BEGIN PGP MESSAGE');
|
||||||
expect(answer).to.not.be.empty;
|
expect(answer.data).to.include(
|
||||||
expect(answer.data).to.be.a('string');
|
'END PGP MESSAGE');
|
||||||
expect(answer.data).to.include(
|
context.decrypt(answer.data).then(function (result) {
|
||||||
'BEGIN PGP MESSAGE');
|
expect(result).to.not.be.empty;
|
||||||
expect(answer.data).to.include(
|
expect(result.data).to.be.a('string');
|
||||||
'END PGP MESSAGE');
|
expect(result.data).to.equal(data);
|
||||||
context.decrypt(answer.data).then(
|
done();
|
||||||
function (result) {
|
});
|
||||||
expect(result).to.not.be.empty;
|
|
||||||
expect(result.data).to.be.a('string');
|
|
||||||
expect(result.data).to.equal(data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).timeout(3000);
|
}).timeout(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Random data, as string', function (done) {
|
|
||||||
let data = bigString(1000);
|
|
||||||
let prm = Gpgmejs.init();
|
|
||||||
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(3000);
|
|
||||||
|
|
||||||
it('Data, input as base64', function (done) {
|
|
||||||
let data = inputvalues.encrypt.good.data;
|
|
||||||
let b64data = btoa(data);
|
|
||||||
let prm = Gpgmejs.init();
|
|
||||||
prm.then(function (context) {
|
|
||||||
context.encrypt(b64data,
|
|
||||||
inputvalues.encrypt.good.fingerprint, true).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(data).to.equal(data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).timeout(3000);
|
|
||||||
|
|
||||||
it('Random data, input as base64', function (done) {
|
|
||||||
let data = bigBoringString(0.001);
|
|
||||||
let b64data = btoa(data);
|
|
||||||
let prm = Gpgmejs.init();
|
|
||||||
prm.then(function (context) {
|
|
||||||
context.encrypt(b64data,
|
|
||||||
inputvalues.encrypt.good.fingerprint, true).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(b64data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).timeout(3000);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -21,134 +21,91 @@
|
|||||||
* Maximilian Krambach <mkrambach@intevation.de>
|
* Maximilian Krambach <mkrambach@intevation.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global describe, it, expect, Gpgmejs */
|
/* global describe, it, expect, before, Gpgmejs */
|
||||||
/* global inputvalues, fixedLengthString */
|
/* global inputvalues, fixedLengthString */
|
||||||
|
|
||||||
describe('Encryption', function () {
|
describe('Encryption', function () {
|
||||||
it('Successful encrypt', function (done) {
|
let context = null;
|
||||||
let prm = Gpgmejs.init();
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
prm.then(function (context) {
|
before(function(done){
|
||||||
context.encrypt(
|
const prm = Gpgmejs.init();
|
||||||
inputvalues.encrypt.good.data,
|
prm.then(function(gpgmejs){
|
||||||
inputvalues.encrypt.good.fingerprint).then(function (answer) {
|
context = gpgmejs;
|
||||||
expect(answer).to.not.be.empty;
|
done();
|
||||||
expect(answer.data).to.be.a('string');
|
|
||||||
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
|
||||||
expect(answer.data).to.include('END PGP MESSAGE');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Successful encrypt 5 MB', function (done) {
|
it('Successful encrypt', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = inputvalues.encrypt.good.data;
|
||||||
let data = fixedLengthString(5);
|
context.encrypt(data, good_fpr).then(function (answer) {
|
||||||
prm.then(function (context) {
|
expect(answer).to.not.be.empty;
|
||||||
context.encrypt(
|
expect(answer.data).to.be.a('string');
|
||||||
data,
|
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
||||||
inputvalues.encrypt.good.fingerprint).then(function (answer) {
|
expect(answer.data).to.include('END PGP MESSAGE');
|
||||||
expect(answer).to.not.be.empty;
|
done();
|
||||||
expect(answer.data).to.be.a('string');
|
|
||||||
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
|
||||||
expect(answer.data).to.include('END PGP MESSAGE');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).timeout(10000);
|
});
|
||||||
|
|
||||||
it('Successful encrypt 20 MB', function (done) {
|
const sizes = [5,20,50];
|
||||||
let prm = Gpgmejs.init();
|
for (let i=0; i < sizes.length; i++) {
|
||||||
let data = fixedLengthString(20);
|
it('Successful encrypt a ' + sizes[i] + 'MB message', function (done) {
|
||||||
prm.then(function (context) {
|
const data = fixedLengthString(sizes[i]);
|
||||||
context.encrypt(
|
context.encrypt(data, good_fpr).then(function (answer) {
|
||||||
data,
|
|
||||||
inputvalues.encrypt.good.fingerprint).then(function (answer) {
|
|
||||||
expect(answer).to.not.be.empty;
|
expect(answer).to.not.be.empty;
|
||||||
expect(answer.data).to.be.a('string');
|
expect(answer.data).to.be.a('string');
|
||||||
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
||||||
expect(answer.data).to.include('END PGP MESSAGE');
|
expect(answer.data).to.include('END PGP MESSAGE');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}).timeout(20000);
|
||||||
}).timeout(20000);
|
}
|
||||||
|
|
||||||
it('Successful encrypt 50 MB', function (done) {
|
|
||||||
let prm = Gpgmejs.init();
|
|
||||||
let data = fixedLengthString(50);
|
|
||||||
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');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).timeout(20000);
|
|
||||||
|
|
||||||
it('Sending encryption without keys fails', function (done) {
|
it('Sending encryption without keys fails', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = inputvalues.encrypt.good.data;
|
||||||
prm.then(function (context) {
|
context.encrypt(data,null).then(function (answer) {
|
||||||
context.encrypt(
|
expect(answer).to.be.undefined;
|
||||||
inputvalues.encrypt.good.data,
|
}, function(error){
|
||||||
null).then(function (answer) {
|
expect(error).to.be.an('Error');
|
||||||
expect(answer).to.be.undefined;
|
expect(error.code).to.equal('MSG_INCOMPLETE');
|
||||||
}, function(error){
|
done();
|
||||||
expect(error).to.be.an('Error');
|
|
||||||
expect(error.code).to.equal('MSG_INCOMPLETE');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sending encryption without data fails', function (done) {
|
it('Sending encryption without data fails', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
context.encrypt(null, good_fpr).then(function (answer) {
|
||||||
prm.then(function (context) {
|
expect(answer).to.be.undefined;
|
||||||
context.encrypt(
|
}, function (error) {
|
||||||
null, inputvalues.encrypt.good.keyid).then(function (answer) {
|
expect(error).to.be.an.instanceof(Error);
|
||||||
expect(answer).to.be.undefined;
|
expect(error.code).to.equal('MSG_INCOMPLETE');
|
||||||
}, function (error) {
|
done();
|
||||||
expect(error).to.be.an.instanceof(Error);
|
|
||||||
expect(error.code).to.equal('MSG_INCOMPLETE');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sending encryption with non existing keys fails', function (done) {
|
it('Sending encryption with non existing keys fails', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = inputvalues.encrypt.good.data;
|
||||||
prm.then(function (context) {
|
const bad_fpr = inputvalues.encrypt.bad.fingerprint;
|
||||||
context.encrypt(
|
context.encrypt(data, bad_fpr).then(function (answer) {
|
||||||
inputvalues.encrypt.good.data,
|
expect(answer).to.be.undefined;
|
||||||
inputvalues.encrypt.bad.fingerprint).then(function (answer) {
|
}, function(error){
|
||||||
expect(answer).to.be.undefined;
|
expect(error).to.be.an('Error');
|
||||||
}, function(error){
|
expect(error.code).to.not.be.undefined;
|
||||||
expect(error).to.be.an('Error');
|
expect(error.code).to.equal('GNUPG_ERROR');
|
||||||
expect(error.code).to.not.be.undefined;
|
done();
|
||||||
expect(error.code).to.equal('GNUPG_ERROR');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
|
|
||||||
it('Overly large message ( > 64MB) is rejected', function (done) {
|
it('Overly large message ( > 64MB) is rejected', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = fixedLengthString(65);
|
||||||
prm.then(function (context) {
|
context.encrypt(data, good_fpr).then(function (answer) {
|
||||||
context.encrypt(
|
expect(answer).to.be.undefined;
|
||||||
fixedLengthString(65),
|
}, function(error){
|
||||||
inputvalues.encrypt.good.fingerprint).then(function (answer) {
|
expect(error).to.be.an.instanceof(Error);
|
||||||
expect(answer).to.be.undefined;
|
// TODO: there is a 64 MB hard limit at least in chrome at:
|
||||||
}, function(error){
|
// chromium//extensions/renderer/messaging_util.cc:
|
||||||
expect(error).to.be.an.instanceof(Error);
|
// kMaxMessageLength
|
||||||
// TODO: there is a 64 MB hard limit at least in chrome at:
|
// The error will be a browser error, not from gnupg or from
|
||||||
// chromium//extensions/renderer/messaging_util.cc:
|
// this library
|
||||||
// kMaxMessageLength
|
done();
|
||||||
// The error will be a browser error, not from gnupg or from
|
|
||||||
// this library
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).timeout(8000);
|
}).timeout(8000);
|
||||||
|
|
||||||
|
@ -53,6 +53,39 @@ const inputvalues = {// eslint-disable-line no-unused-vars
|
|||||||
// bogus fingerprint)
|
// bogus fingerprint)
|
||||||
fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
|
fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signedMessage: {
|
||||||
|
good: '-----BEGIN PGP SIGNED MESSAGE-----\n' +
|
||||||
|
'Hash: SHA256\n' +
|
||||||
|
'\n' +
|
||||||
|
'Matschige Münsteraner Marshmallows\n' +
|
||||||
|
'-----BEGIN PGP SIGNATURE-----\n' +
|
||||||
|
'\n' +
|
||||||
|
'iQEzBAEBCAAdFiEE1Bc1uRI2/biCBIxaIwFjXu/wywUFAltRoiMACgkQIwFjXu/w\n' +
|
||||||
|
'ywUvagf6ApQbZbTPOROqfTfxAPdtzJsSDKHla6D0G5wom2gJbAVb0B2YS1c3Gjpq\n' +
|
||||||
|
'I4kTKT1W1RRkne0mK9cexf4sjb5DQcV8PLhfmmAJEpljDFei6i/E309BvW4CZ4rG\n' +
|
||||||
|
'jiurf8CkaNkrwn2fXJDaT4taVCX3V5FQAlgLxgOrm1zjiGA4mz98gi5zL4hvZXF9\n' +
|
||||||
|
'dHY0jLwtQMVUO99q+5XC1TJfPsnteWL9m4e/YYPfYJMZZso+/0ib/yX5vHCk7RXH\n' +
|
||||||
|
'CfhY40nMXSYdfl8mDOhvnKcCvy8qxetFv9uCX06OqepAamu/bvxslrzocRyJ/eq0\n' +
|
||||||
|
'T2JfzEN+E7Y3PB8UwLgp/ZRmG8zRrQ==\n' +
|
||||||
|
'=ioB6\n' +
|
||||||
|
'-----END PGP SIGNATURE-----\n',
|
||||||
|
bad: '-----BEGIN PGP SIGNED MESSAGE-----\n' +
|
||||||
|
'Hash: SHA256\n' +
|
||||||
|
'\n' +
|
||||||
|
'Matschige Münchener Marshmallows\n' +
|
||||||
|
'-----BEGIN PGP SIGNATURE-----\n' +
|
||||||
|
'\n' +
|
||||||
|
'iQEzBAEBCAAdFiEE1Bc1uRI2/biCBIxaIwFjXu/wywUFAltRoiMACgkQIwFjXu/w\n' +
|
||||||
|
'ywUvagf6ApQbZbTPOROqfTfxAPdtzJsSDKHla6D0G5wom2gJbAVb0B2YS1c3Gjpq\n' +
|
||||||
|
'I4kTKT1W1RRkne0mK9cexf4sjb5DQcV8PLhfmmAJEpljDFei6i/E309BvW4CZ4rG\n' +
|
||||||
|
'jiurf8CkaNkrwn2fXJDaT4taVCX3V5FQAlgLxgOrm1zjiGA4mz98gi5zL4hvZXF9\n' +
|
||||||
|
'dHY0jLwtQMVUO99q+5XC1TJfPsnteWL9m4e/YYPfYJMZZso+/0ib/yX5vHCk7RXH\n' +
|
||||||
|
'CfhY40nMXSYdfl8mDOhvnKcCvy8qxetFv9uCX06OqepAamu/bvxslrzocRyJ/eq0\n' +
|
||||||
|
'T2JfzEN+E7Y3PB8UwLgp/ZRmG8zRrQ==\n' +
|
||||||
|
'=ioB6\n' +
|
||||||
|
'-----END PGP SIGNATURE-----\n',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,7 +116,7 @@ function bigUint8(megabytes){// eslint-disable-line no-unused-vars
|
|||||||
let maxlength = 1024 * 1024 * megabytes;
|
let maxlength = 1024 * 1024 * megabytes;
|
||||||
let uint = new Uint8Array(maxlength);
|
let uint = new Uint8Array(maxlength);
|
||||||
for (let i= 0; i < maxlength; i++){
|
for (let i= 0; i < maxlength; i++){
|
||||||
uint[i] = Math.random() * Math.floor(256);
|
uint[i] = Math.floor(Math.random() * 256);
|
||||||
}
|
}
|
||||||
return uint;
|
return uint;
|
||||||
}
|
}
|
||||||
@ -125,6 +158,27 @@ function slightlyLessBoringString(megabytes, set){
|
|||||||
return string.join('');
|
return string.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Take a gpg looking string and destroy it a bit by changing random values
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function destroylegitimateGpg(string, mutations=5){
|
||||||
|
const allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/\n';
|
||||||
|
for (let i=0; i < mutations.length; i++){
|
||||||
|
// leave the first and last 35 chars (header/footer) intact
|
||||||
|
let position = Math.floor(Math.random() *(string.length - 70)) + 35;
|
||||||
|
let str0 = string.substring(0,position - 1);
|
||||||
|
let str1 = string.substring(position, position + 1);
|
||||||
|
let str2 = string.substring(position +1);
|
||||||
|
let success = false;
|
||||||
|
while (!success){
|
||||||
|
let newchar = Math.floor(Math.random() * allowed.length);
|
||||||
|
if (newchar !== str1){
|
||||||
|
string = str0 + newchar + str2;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Data encrypted with testKey
|
// Data encrypted with testKey
|
||||||
const encryptedData =// eslint-disable-line no-unused-vars
|
const encryptedData =// eslint-disable-line no-unused-vars
|
||||||
'-----BEGIN PGP MESSAGE-----\n' +
|
'-----BEGIN PGP MESSAGE-----\n' +
|
||||||
|
@ -20,61 +20,37 @@
|
|||||||
* Author(s):
|
* Author(s):
|
||||||
* Maximilian Krambach <mkrambach@intevation.de>
|
* Maximilian Krambach <mkrambach@intevation.de>
|
||||||
*/
|
*/
|
||||||
/* global describe, it, expect, Gpgmejs */
|
/* global describe, it, before, expect, Gpgmejs */
|
||||||
/* global bigString, inputvalues */
|
/* global bigString, inputvalues */
|
||||||
|
|
||||||
describe('Long running Encryption/Decryption', function () {
|
describe('Long running Encryption/Decryption', function () {
|
||||||
|
let context = null;
|
||||||
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
|
before(function(done){
|
||||||
|
const prm = Gpgmejs.init();
|
||||||
|
prm.then(function(gpgmejs){
|
||||||
|
context = gpgmejs;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
for (let i=0; i < 101; i++) {
|
for (let i=0; i < 101; i++) {
|
||||||
it('Successful encrypt/decrypt completely random data ' +
|
it('Successful encrypt/decrypt completely random data '
|
||||||
(i+1) + '/100', function (done) {
|
+ (i+1) + '/100', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = bigString(2*1024*1024);
|
||||||
let data = bigString(2*1024*1024);
|
context.encrypt(data,good_fpr).then(function (answer){
|
||||||
prm.then(function (context) {
|
expect(answer).to.not.be.empty;
|
||||||
context.encrypt(data,
|
expect(answer.data).to.be.a('string');
|
||||||
inputvalues.encrypt.good.fingerprint).then(
|
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
||||||
function (answer){
|
expect(answer.data).to.include('END PGP MESSAGE');
|
||||||
expect(answer).to.not.be.empty;
|
context.decrypt(answer.data).then(function(result){
|
||||||
expect(answer.data).to.be.a('string');
|
expect(result).to.not.be.empty;
|
||||||
expect(answer.data).to.include(
|
expect(result.data).to.be.a('string');
|
||||||
'BEGIN PGP MESSAGE');
|
expect(result.data).to.equal(data);
|
||||||
expect(answer.data).to.include(
|
done();
|
||||||
'END PGP MESSAGE');
|
});
|
||||||
context.decrypt(answer.data).then(
|
|
||||||
function(result){
|
|
||||||
expect(result).to.not.be.empty;
|
|
||||||
expect(result.data).to.be.a('string');
|
|
||||||
/*
|
|
||||||
if (result.data.length !== data.length) {
|
|
||||||
console.log('diff: ' +
|
|
||||||
(result.data.length - data.length));
|
|
||||||
for (let i=0; i < result.data.length; i++){
|
|
||||||
if (result.data[i] !== data[i]){
|
|
||||||
console.log('position: ' + i);
|
|
||||||
console.log('result : ' +
|
|
||||||
result.data.charCodeAt(i) +
|
|
||||||
result.data[i-2] +
|
|
||||||
result.data[i-1] +
|
|
||||||
result.data[i] +
|
|
||||||
result.data[i+1] +
|
|
||||||
result.data[i+2]);
|
|
||||||
console.log('original: ' +
|
|
||||||
data.charCodeAt(i) +
|
|
||||||
data[i-2] +
|
|
||||||
data[i-1] +
|
|
||||||
data[i] +
|
|
||||||
data[i+1] +
|
|
||||||
data[i+2]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
expect(result.data).to.equal(data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}).timeout(8000);
|
}).timeout(15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -21,42 +21,42 @@
|
|||||||
* Maximilian Krambach <mkrambach@intevation.de>
|
* Maximilian Krambach <mkrambach@intevation.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global describe, it, expect, Gpgmejs */
|
/* global describe, it, expect, before, Gpgmejs */
|
||||||
/* global bigString, inputvalues */
|
/* global bigString, inputvalues */
|
||||||
|
|
||||||
describe('Signing', function () {
|
describe('Signing', function () {
|
||||||
it('Sign a message', function (done) {
|
let context = null;
|
||||||
let prm = Gpgmejs.init();
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
prm.then(function (context) {
|
|
||||||
let data = bigString(100);
|
before(function(done){
|
||||||
context.sign(
|
const prm = Gpgmejs.init();
|
||||||
data,
|
prm.then(function(gpgmejs){
|
||||||
inputvalues.encrypt.good.fingerprint).then(function (answer) {
|
context = gpgmejs;
|
||||||
expect(answer).to.not.be.empty;
|
done();
|
||||||
expect(answer.data).to.be.a('string');
|
|
||||||
expect(answer.data).to.include('BEGIN PGP SIGNATURE');
|
|
||||||
expect(answer.data).to.include('END PGP SIGNATURE');
|
|
||||||
expect(answer.data).to.include(data);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Sign a message', function (done) {
|
||||||
|
const data = bigString(100);
|
||||||
|
context.sign(data, good_fpr).then(function (answer) {
|
||||||
|
expect(answer).to.not.be.empty;
|
||||||
|
expect(answer.data).to.be.a('string');
|
||||||
|
expect(answer.data).to.include('BEGIN PGP SIGNATURE');
|
||||||
|
expect(answer.data).to.include('END PGP SIGNATURE');
|
||||||
|
expect(answer.data).to.include(data);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Detached sign a message', function (done) {
|
it('Detached sign a message', function (done) {
|
||||||
let prm = Gpgmejs.init();
|
const data = bigString(100);
|
||||||
prm.then(function (context) {
|
context.sign(data,good_fpr, 'detached').then(function (answer) {
|
||||||
let data = bigString(100);
|
expect(answer).to.not.be.empty;
|
||||||
context.sign(
|
expect(answer.data).to.be.a('string');
|
||||||
data,
|
expect(answer.data).to.include(data);
|
||||||
inputvalues.encrypt.good.fingerprint,
|
expect(answer.signature).to.be.a('string');
|
||||||
'detached'
|
expect(answer.signature).to.be.a('string');
|
||||||
).then(function (answer) {
|
done();
|
||||||
expect(answer).to.not.be.empty;
|
|
||||||
expect(answer.data).to.be.a('string');
|
|
||||||
expect(answer.data).to.include(data);
|
|
||||||
expect(answer.signature).to.be.a('string');
|
|
||||||
expect(answer.signature).to.be.a('string');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,64 +21,63 @@
|
|||||||
* Maximilian Krambach <mkrambach@intevation.de>
|
* Maximilian Krambach <mkrambach@intevation.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global describe, it, expect, bigString, inputvalues, Gpgmejs */
|
/* global describe, it, expect, before, bigString, inputvalues, Gpgmejs */
|
||||||
|
|
||||||
let verifyData = {
|
|
||||||
signedMessage: '-----BEGIN PGP SIGNED MESSAGE-----\n' +
|
|
||||||
'Hash: SHA256\n' +
|
|
||||||
'\n' +
|
|
||||||
'Matschige Münsteraner Marshmallows\n' +
|
|
||||||
'-----BEGIN PGP SIGNATURE-----\n' +
|
|
||||||
'\n' +
|
|
||||||
'iQEzBAEBCAAdFiEE1Bc1uRI2/biCBIxaIwFjXu/wywUFAltRoiMACgkQIwFjXu/w\n' +
|
|
||||||
'ywUvagf6ApQbZbTPOROqfTfxAPdtzJsSDKHla6D0G5wom2gJbAVb0B2YS1c3Gjpq\n' +
|
|
||||||
'I4kTKT1W1RRkne0mK9cexf4sjb5DQcV8PLhfmmAJEpljDFei6i/E309BvW4CZ4rG\n' +
|
|
||||||
'jiurf8CkaNkrwn2fXJDaT4taVCX3V5FQAlgLxgOrm1zjiGA4mz98gi5zL4hvZXF9\n' +
|
|
||||||
'dHY0jLwtQMVUO99q+5XC1TJfPsnteWL9m4e/YYPfYJMZZso+/0ib/yX5vHCk7RXH\n' +
|
|
||||||
'CfhY40nMXSYdfl8mDOhvnKcCvy8qxetFv9uCX06OqepAamu/bvxslrzocRyJ/eq0\n' +
|
|
||||||
'T2JfzEN+E7Y3PB8UwLgp/ZRmG8zRrQ==\n' +
|
|
||||||
'=ioB6\n' +
|
|
||||||
'-----END PGP SIGNATURE-----\n'
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Verify data', function () {
|
|
||||||
|
describe('Verifying data', function () {
|
||||||
|
let context = null;
|
||||||
|
before(function(done){
|
||||||
|
const prm = Gpgmejs.init();
|
||||||
|
prm.then(function(gpgmejs){
|
||||||
|
context = gpgmejs;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it('Successful verify message', function (done) {
|
it('Successful verify message', function (done) {
|
||||||
let message = verifyData.signedMessage;
|
const message = inputvalues.signedMessage.good;
|
||||||
let prm = Gpgmejs.init();
|
context.verify(message).then(function(result){
|
||||||
prm.then(function (context) {
|
expect(result.data).to.be.a('string');
|
||||||
context.verify(message).then(function(result){
|
expect(result.all_valid).to.be.true;
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.count).to.equal(1);
|
||||||
expect(result.all_valid).to.be.true;
|
expect(result.signatures.good).to.be.an('array');
|
||||||
expect(result.count).to.equal(1);
|
expect(result.signatures.good.length).to.equal(1);
|
||||||
expect(result.signatures.good).to.be.an('array');
|
expect(result.signatures.good[0].fingerprint).to.be.a('string');
|
||||||
expect(result.signatures.good.length).to.equal(1);
|
expect(result.signatures.good[0].valid).to.be.true;
|
||||||
expect(result.signatures.good[0].fingerprint)
|
done();
|
||||||
.to.be.a('string');
|
});
|
||||||
expect(result.signatures.good[0].valid).to.be.true;
|
});
|
||||||
done();
|
|
||||||
});
|
it('Successfully recognize changed cleartext', function (done) {
|
||||||
|
const message = inputvalues.signedMessage.bad;
|
||||||
|
context.verify(message).then(function(result){
|
||||||
|
expect(result.data).to.be.a('string');
|
||||||
|
expect(result.all_valid).to.be.false;
|
||||||
|
expect(result.count).to.equal(1);
|
||||||
|
expect(result.signatures.bad).to.be.an('array');
|
||||||
|
expect(result.signatures.bad.length).to.equal(1);
|
||||||
|
expect(result.signatures.bad[0].fingerprint).to.be.a('string');
|
||||||
|
expect(result.signatures.bad[0].valid).to.be.false;
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Encrypt-Sign-Verify random message', function (done) {
|
it('Encrypt-Sign-Verify random message', function (done) {
|
||||||
let message = bigString(2000);
|
const message = bigString(2000);
|
||||||
let fpr = inputvalues.encrypt.good.fingerprint;
|
let fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
let prm = Gpgmejs.init();
|
context.encrypt(message, fpr).then(function(message_enc){
|
||||||
prm.then(function (context) {
|
context.sign(message_enc.data, fpr).then(function(message_encsign){
|
||||||
context.encrypt(message, fpr).then(function(message_enc){
|
context.verify(message_encsign.data).then(function(result){
|
||||||
context.sign(message_enc.data, fpr).then(function(message_encsign){
|
expect(result.data).to.equal(message_enc.data);
|
||||||
context.verify(message_encsign.data).then(function(result){
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.data).to.equal(message_enc.data);
|
expect(result.all_valid).to.be.true;
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.count).to.equal(1);
|
||||||
expect(result.all_valid).to.be.true;
|
expect(result.signatures.good).to.be.an('array');
|
||||||
expect(result.count).to.equal(1);
|
expect(result.signatures.good.length).to.equal(1);
|
||||||
expect(result.signatures.good).to.be.an('array');
|
expect(
|
||||||
expect(result.signatures.good.length).to.equal(1);
|
result.signatures.good[0].fingerprint).to.equal(fpr);
|
||||||
expect(result.signatures.good[0].fingerprint)
|
expect(result.signatures.good[0].valid).to.be.true;
|
||||||
.to.equal(fpr);
|
done();
|
||||||
expect(result.signatures.good[0].valid).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user