Test CFB, GCM, worker, asm.js, native cases

This commit is contained in:
Tankred Hase 2016-03-24 13:25:35 +08:00
parent f4fc274f14
commit da3fbf8965
3 changed files with 56 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* globals tryWorker: true */ /* globals tryTests: true */
'use strict'; 'use strict';
@ -403,7 +403,7 @@ describe('OpenPGP.js public api tests', function() {
}); });
describe('encrypt, decrypt, sign, verify - integration tests', function() { describe('encrypt, decrypt, sign, verify - integration tests', function() {
var privateKey, publicKey, zeroCopyVal, useNativeVal; var privateKey, publicKey, zeroCopyVal, useNativeVal, aead_protectVal;
beforeEach(function() { beforeEach(function() {
publicKey = openpgp.key.readArmored(pub_key); publicKey = openpgp.key.readArmored(pub_key);
@ -414,11 +414,13 @@ describe('OpenPGP.js public api tests', function() {
expect(privateKey.err).to.not.exist; expect(privateKey.err).to.not.exist;
zeroCopyVal = openpgp.config.zeroCopy; zeroCopyVal = openpgp.config.zeroCopy;
useNativeVal = openpgp.config.useNative; useNativeVal = openpgp.config.useNative;
aead_protectVal = openpgp.config.aead_protect;
}); });
afterEach(function() { afterEach(function() {
openpgp.config.zeroCopy = zeroCopyVal; openpgp.config.zeroCopy = zeroCopyVal;
openpgp.config.useNative = useNativeVal; openpgp.config.useNative = useNativeVal;
openpgp.config.aead_protect = aead_protectVal;
}); });
it('Decrypting key with wrong passphrase returns false', function () { it('Decrypting key with wrong passphrase returns false', function () {
@ -429,13 +431,42 @@ describe('OpenPGP.js public api tests', function() {
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true; expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
}); });
describe('without Worker', tests); tryTests('CFB mode (asm.js)', tests, {
if: true,
tryWorker('with Worker', tests, function() { beforeEach: function() {
openpgp.config.useNative = false; openpgp.config.useNative = false;
openpgp.config.aead_protect = false;
}
});
tryTests('CFB mode (asm.js, worker)', tests, {
if: typeof window !== 'undefined' && window.Worker,
before: function() {
openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
}, function() { },
openpgp.destroyWorker(); // cleanup worker in case of failure beforeEach: function() {
openpgp.config.useNative = false;
openpgp.config.aead_protect = false;
},
after: function() {
openpgp.destroyWorker();
}
});
tryTests('GCM mode (asm.js)', tests, {
if: true,
beforeEach: function() {
openpgp.config.useNative = false;
openpgp.config.aead_protect = true;
}
});
tryTests('GCM mode (native)', tests, {
if: openpgp.util.getWebCrypto(),
beforeEach: function() {
openpgp.config.useNative = true;
openpgp.config.aead_protect = true;
}
}); });
function tests() { function tests() {

View File

@ -6,17 +6,19 @@
return new Promise(function(res, rej) { rej(val); }); return new Promise(function(res, rej) { rej(val); });
}; };
(typeof window !== 'undefined' ? window : global).tryWorker = function(name, tests, beforeFn, afterFn) { (typeof window !== 'undefined' ? window : global).tryTests = function(name, tests, options) {
if (typeof window !== 'undefined' && window.Worker) { if (options.if) {
describe(name, function() { describe(name, function() {
before(beforeFn); if (options.before) { before(options.before); }
if (options.beforeEach) { beforeEach(options.beforeEach); }
tests(); tests();
after(afterFn); if (options.afterEach) { afterEach(options.afterEach); }
if (options.after) { after(options.after); }
}); });
} else { } else {
describe.skip(name + ' (No Web Worker support --> skipping tests)', tests); describe.skip(name + ' (no support --> skipping tests)', tests);
} }
}; };

View File

@ -1,4 +1,4 @@
/* globals tryWorker: true */ /* globals tryTests: true */
'use strict'; 'use strict';
@ -35,11 +35,15 @@ var pub_key =
var plaintext = 'short message\nnext line\n한국어/조선말'; var plaintext = 'short message\nnext line\n한국어/조선말';
var pubKey; var pubKey;
tryWorker('Async Proxy', tests, function() { tryTests('Async Proxy', tests, {
if: typeof window !== 'undefined' && window.Worker,
before: function() {
openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
pubKey = openpgp.key.readArmored(pub_key).keys[0]; pubKey = openpgp.key.readArmored(pub_key).keys[0];
}, function() { },
after: function() {
openpgp.destroyWorker(); openpgp.destroyWorker();
}
}); });
function tests() { function tests() {