Run tests both with and without web worker
This commit is contained in:
parent
ee07b77320
commit
227a412ca0
|
@ -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;
|
openpgp.config.useNative = true;
|
||||||
var opt = {
|
var opt = {
|
||||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||||
|
@ -337,10 +337,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
|
|
||||||
var privateKey, publicKey;
|
var privateKey, publicKey;
|
||||||
|
|
||||||
before(function() {
|
|
||||||
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
publicKey = openpgp.key.readArmored(pub_key);
|
publicKey = openpgp.key.readArmored(pub_key);
|
||||||
expect(publicKey.keys).to.have.length(1);
|
expect(publicKey.keys).to.have.length(1);
|
||||||
|
@ -350,10 +346,6 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
expect(privateKey.err).to.not.exist;
|
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 () {
|
it('Decrypting key with wrong passphrase returns false', function () {
|
||||||
expect(privateKey.keys[0].decrypt('wrong passphrase')).to.be.false;
|
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;
|
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
function testHelper(encOpt, decOpt, dontUnlock) {
|
function testHelper(encOpt, decOpt) {
|
||||||
if (!dontUnlock) {
|
|
||||||
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
|
|
||||||
}
|
|
||||||
return openpgp.encrypt(encOpt).then(function(encrypted) {
|
return openpgp.encrypt(encOpt).then(function(encrypted) {
|
||||||
expect(encrypted.data).to.exist;
|
expect(encrypted.data).to.exist;
|
||||||
var msg = openpgp.message.readArmored(encrypted.data);
|
var msg = openpgp.message.readArmored(encrypted.data);
|
||||||
|
@ -376,108 +365,130 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Calling decrypt with not decrypted key leads to exception', function (done) {
|
describe('without Worker', tests);
|
||||||
var encOpt = {
|
describe('with Worker', function() {
|
||||||
data: plaintext,
|
before(function() {
|
||||||
publicKeys: publicKey.keys,
|
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||||
};
|
});
|
||||||
var decOpt = {
|
|
||||||
privateKey: privateKey.keys[0]
|
tests();
|
||||||
};
|
|
||||||
testHelper(encOpt, decOpt, true).catch(function(error) {
|
after(function() {
|
||||||
expect(error.message).to.match(/not decrypted/);
|
openpgp.destroyWorker(); // cleanup worker in case of failure
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encrypt then decrypt with pgp key pair', function(done) {
|
function tests() {
|
||||||
var encOpt = {
|
it('Calling decrypt with not decrypted key leads to exception', function (done) {
|
||||||
data: plaintext,
|
var encOpt = {
|
||||||
publicKeys: publicKey.keys,
|
data: plaintext,
|
||||||
};
|
publicKeys: publicKey.keys,
|
||||||
var decOpt = {
|
};
|
||||||
privateKey: privateKey.keys[0]
|
var decOpt = {
|
||||||
};
|
privateKey: privateKey.keys[0]
|
||||||
testHelper(encOpt, decOpt).then(function(decrypted) {
|
};
|
||||||
expect(decrypted.data).to.equal(plaintext);
|
testHelper(encOpt, decOpt).catch(function(error) {
|
||||||
expect(decrypted.signatures).to.not.exist;
|
expect(error.message).to.match(/not decrypted/);
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should encrypt/sign and decrypt/verify with pgp key pair', function(done) {
|
describe('with unlocked key', function() {
|
||||||
var encOpt = {
|
beforeEach(function() {
|
||||||
data: plaintext,
|
expect(privateKey.keys[0].decrypt(passphrase)).to.be.true;
|
||||||
publicKeys: publicKey.keys,
|
});
|
||||||
privateKeys: privateKey.keys
|
|
||||||
};
|
it('should encrypt then decrypt with pgp key pair', function(done) {
|
||||||
var decOpt = {
|
var encOpt = {
|
||||||
privateKey: privateKey.keys[0],
|
data: plaintext,
|
||||||
publicKeys: publicKey.keys
|
publicKeys: publicKey.keys,
|
||||||
};
|
};
|
||||||
testHelper(encOpt, decOpt).then(function(decrypted) {
|
var decOpt = {
|
||||||
expect(decrypted.data).to.equal(plaintext);
|
privateKey: privateKey.keys[0]
|
||||||
expect(decrypted.signatures[0].valid).to.be.true;
|
};
|
||||||
done();
|
testHelper(encOpt, decOpt).then(function(decrypted) {
|
||||||
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
|
expect(decrypted.signatures).to.not.exist;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should encrypt/sign and decrypt/verify with pgp key pair', function(done) {
|
||||||
|
var encOpt = {
|
||||||
|
data: plaintext,
|
||||||
|
publicKeys: publicKey.keys,
|
||||||
|
privateKeys: privateKey.keys
|
||||||
|
};
|
||||||
|
var decOpt = {
|
||||||
|
privateKey: privateKey.keys[0],
|
||||||
|
publicKeys: publicKey.keys
|
||||||
|
};
|
||||||
|
testHelper(encOpt, decOpt).then(function(decrypted) {
|
||||||
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
|
expect(decrypted.signatures[0].valid).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to verify with wrong public pgp key', function(done) {
|
||||||
|
var wrong_pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
||||||
|
'Version: OpenPGP.js v0.9.0\r\n' +
|
||||||
|
'Comment: Hoodiecrow - https://hoodiecrow.com\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
||||||
|
'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\r\n' +
|
||||||
|
'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\r\n' +
|
||||||
|
'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\r\n' +
|
||||||
|
'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\r\n' +
|
||||||
|
'=6XMW\r\n' +
|
||||||
|
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n';
|
||||||
|
|
||||||
|
var encOpt = {
|
||||||
|
data: plaintext,
|
||||||
|
publicKeys: publicKey.keys,
|
||||||
|
privateKeys: privateKey.keys
|
||||||
|
};
|
||||||
|
var decOpt = {
|
||||||
|
privateKey: privateKey.keys[0],
|
||||||
|
publicKeys: openpgp.key.readArmored(wrong_pubkey).keys
|
||||||
|
};
|
||||||
|
testHelper(encOpt, decOpt).then(function(decrypted) {
|
||||||
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
|
expect(decrypted.signatures[0].valid).to.be.null;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to verify with wrong public pgp key', function(done) {
|
it('should encrypt and decrypt with one password', function(done) {
|
||||||
var wrong_pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
var encOpt = {
|
||||||
'Version: OpenPGP.js v0.9.0\r\n' +
|
data: plaintext,
|
||||||
'Comment: Hoodiecrow - https://hoodiecrow.com\r\n' +
|
passwords: password1
|
||||||
'\r\n' +
|
};
|
||||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
var decOpt = {
|
||||||
'RVGvbK88unV3cU/1tOYdNsXI6pSp/Ztjyv7vbBUAEQEAAc0pV2hpdGVvdXQg\r\n' +
|
password: password1
|
||||||
'VXNlciA8d2hpdGVvdXQudGVzdEB0LW9ubGluZS5kZT7CXAQQAQgAEAUCUlhM\r\n' +
|
};
|
||||||
'vQkQ9vYOm0LN/0wAAAW4Af9C+kYW1AvNWmivdtr0M0iYCUjM9DNOQH1fcvXq\r\n' +
|
testHelper(encOpt, decOpt).then(function(decrypted) {
|
||||||
'IiN602mWrkd8jcEzLsW5IUNzVPLhrFIuKyBDTpLnC07Loce1\r\n' +
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
'=6XMW\r\n' +
|
done();
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n';
|
});
|
||||||
|
|
||||||
var encOpt = {
|
|
||||||
data: plaintext,
|
|
||||||
publicKeys: publicKey.keys,
|
|
||||||
privateKeys: privateKey.keys
|
|
||||||
};
|
|
||||||
var decOpt = {
|
|
||||||
privateKey: privateKey.keys[0],
|
|
||||||
publicKeys: openpgp.key.readArmored(wrong_pubkey).keys
|
|
||||||
};
|
|
||||||
testHelper(encOpt, decOpt).then(function(decrypted) {
|
|
||||||
expect(decrypted.data).to.equal(plaintext);
|
|
||||||
expect(decrypted.signatures[0].valid).to.be.null;
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should encrypt and decrypt with one password', function(done) {
|
it('should encrypt and decrypt with two password2', function(done) {
|
||||||
var encOpt = {
|
var encOpt = {
|
||||||
data: plaintext,
|
data: plaintext,
|
||||||
passwords: password1
|
passwords: [password1, password2]
|
||||||
};
|
};
|
||||||
var decOpt = {
|
var decOpt = {
|
||||||
password: password1
|
password: password2
|
||||||
};
|
};
|
||||||
testHelper(encOpt, decOpt).then(function(decrypted) {
|
testHelper(encOpt, decOpt).then(function(decrypted) {
|
||||||
expect(decrypted.data).to.equal(plaintext);
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
it('should encrypt and decrypt with two password2', function(done) {
|
|
||||||
var encOpt = {
|
|
||||||
data: plaintext,
|
|
||||||
passwords: [password1, password2]
|
|
||||||
};
|
|
||||||
var decOpt = {
|
|
||||||
password: password2
|
|
||||||
};
|
|
||||||
testHelper(encOpt, decOpt).then(function(decrypted) {
|
|
||||||
expect(decrypted.data).to.equal(plaintext);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user