Skip to content

Commit

Permalink
Fix decryption tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Jul 17, 2020
1 parent de360e2 commit 14f244a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions test/general/openpgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,26 +806,25 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decryptKey({
privateKey: privateKey.keys[0],
passphrase: 'incorrect'
}).then(function() {
throw new Error('Should not decrypt with incorrect passphrase');
}).catch(function(error){
expect(error.message).to.match(/Incorrect key passphrase/);
});
});
});

it('Calling decrypt with not decrypted key leads to exception', function() {
it('Calling decrypt with not decrypted key leads to exception', async function() {
const encOpt = {
message: openpgp.message.fromText(plaintext),
publicKeys: publicKey.keys
};
const decOpt = {
privateKeys: privateKey.keys[0]
};
return openpgp.encrypt(encOpt).then(async function(encrypted) {
decOpt.message = await openpgp.message.readArmored(encrypted.data);
return openpgp.decrypt(decOpt);
}).catch(function(error) {
expect(error.message).to.match(/not decrypted/);
});
const encrypted = await openpgp.encrypt(encOpt);
decOpt.message = await openpgp.message.readArmored(encrypted.data);
await expect(openpgp.decrypt(decOpt)).to.be.rejectedWith('Error decrypting message: Private key is not decrypted.');
});

tryTests('CFB mode (asm.js)', tests, {
Expand Down Expand Up @@ -942,6 +941,8 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.decryptSessionKeys({
message: encrypted.message,
privateKeys: invalidPrivateKey
}).then(() => {
throw new Error('Should not decrypt with invalid key');
}).catch(error => {
expect(error.message).to.match(/Error decrypting session keys: Session key decryption failed./);
});
Expand Down Expand Up @@ -2402,7 +2403,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.encrypt({
message: openpgp.message.fromText(plaintext),
publicKeys: revKey.publicKey
}).then(function(encrypted) {
}).then(function() {
throw new Error('Should not encrypt with revoked key');
}).catch(function(error) {
expect(error.message).to.match(/Error encrypting message: Primary key is revoked/);
Expand All @@ -2419,7 +2420,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.encrypt({
message: openpgp.message.fromText(plaintext),
publicKeys: pubKeyDE
}).then(function(encrypted) {
}).then(function() {
throw new Error('Should not encrypt with revoked subkey');
}).catch(function(error) {
expect(error.message).to.match(/Could not find valid encryption key packet/);
Expand Down Expand Up @@ -2526,11 +2527,9 @@ amnR6g==
return openpgp.encrypt({
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
passwords: null
})
.then(function() {
}).then(function() {
throw new Error('Error expected.');
})
.catch(function(error) {
}).catch(function(error) {
expect(error.message).to.match(/No keys, passwords, or session key provided/);
});
});
Expand Down

0 comments on commit 14f244a

Please sign in to comment.