Run tests both with and without web worker

This commit is contained in:
Tankred Hase 2016-02-09 07:53:31 +07:00
parent ee07b77320
commit 227a412ca0

View File

@ -247,7 +247,7 @@ describe('OpenPGP.js public api tests', function() {
});
});
it('should work in JS (use native)', function(done) {
it('should work in with native crypto', function(done) {
openpgp.config.useNative = true;
var opt = {
userIds: [{ name: 'Test User', email: 'text@example.com' }],
@ -337,10 +337,6 @@ describe('OpenPGP.js public api tests', function() {
var privateKey, publicKey;
before(function() {
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
});
beforeEach(function() {
publicKey = openpgp.key.readArmored(pub_key);
expect(publicKey.keys).to.have.length(1);
@ -350,10 +346,6 @@ describe('OpenPGP.js public api tests', function() {
expect(privateKey.err).to.not.exist;
});
after(function() {
openpgp.destroyWorker(); // cleanup worker in case of failure
});
it('Decrypting key with wrong passphrase returns false', function () {
expect(privateKey.keys[0].decrypt('wrong passphrase')).to.be.false;
});
@ -362,10 +354,7 @@ describe('OpenPGP.js public api tests', function() {
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
});
function testHelper(encOpt, decOpt, dontUnlock) {
if (!dontUnlock) {
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
}
function testHelper(encOpt, decOpt) {
return openpgp.encrypt(encOpt).then(function(encrypted) {
expect(encrypted.data).to.exist;
var msg = openpgp.message.readArmored(encrypted.data);
@ -376,6 +365,20 @@ describe('OpenPGP.js public api tests', function() {
});
}
describe('without Worker', tests);
describe('with Worker', function() {
before(function() {
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
});
tests();
after(function() {
openpgp.destroyWorker(); // cleanup worker in case of failure
});
});
function tests() {
it('Calling decrypt with not decrypted key leads to exception', function (done) {
var encOpt = {
data: plaintext,
@ -384,12 +387,17 @@ describe('OpenPGP.js public api tests', function() {
var decOpt = {
privateKey: privateKey.keys[0]
};
testHelper(encOpt, decOpt, true).catch(function(error) {
testHelper(encOpt, decOpt).catch(function(error) {
expect(error.message).to.match(/not decrypted/);
done();
});
});
describe('with unlocked key', function() {
beforeEach(function() {
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
});
it('should encrypt then decrypt with pgp key pair', function(done) {
var encOpt = {
data: plaintext,
@ -450,6 +458,7 @@ describe('OpenPGP.js public api tests', function() {
done();
});
});
});
it('should encrypt and decrypt with one password', function(done) {
var encOpt = {
@ -478,6 +487,8 @@ describe('OpenPGP.js public api tests', function() {
done();
});
});
}
});
});