Fix decryption tests
This commit is contained in:
parent
de360e200c
commit
14f244a80f
|
@ -806,13 +806,15 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.decryptKey({
|
return openpgp.decryptKey({
|
||||||
privateKey: privateKey.keys[0],
|
privateKey: privateKey.keys[0],
|
||||||
passphrase: 'incorrect'
|
passphrase: 'incorrect'
|
||||||
|
}).then(function() {
|
||||||
|
throw new Error('Should not decrypt with incorrect passphrase');
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
expect(error.message).to.match(/Incorrect key passphrase/);
|
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 = {
|
const encOpt = {
|
||||||
message: openpgp.message.fromText(plaintext),
|
message: openpgp.message.fromText(plaintext),
|
||||||
publicKeys: publicKey.keys
|
publicKeys: publicKey.keys
|
||||||
|
@ -820,12 +822,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
const decOpt = {
|
const decOpt = {
|
||||||
privateKeys: privateKey.keys[0]
|
privateKeys: privateKey.keys[0]
|
||||||
};
|
};
|
||||||
return openpgp.encrypt(encOpt).then(async function(encrypted) {
|
const encrypted = await openpgp.encrypt(encOpt);
|
||||||
decOpt.message = await openpgp.message.readArmored(encrypted.data);
|
decOpt.message = await openpgp.message.readArmored(encrypted.data);
|
||||||
return openpgp.decrypt(decOpt);
|
await expect(openpgp.decrypt(decOpt)).to.be.rejectedWith('Error decrypting message: Private key is not decrypted.');
|
||||||
}).catch(function(error) {
|
|
||||||
expect(error.message).to.match(/not decrypted/);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('CFB mode (asm.js)', tests, {
|
tryTests('CFB mode (asm.js)', tests, {
|
||||||
|
@ -942,6 +941,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.decryptSessionKeys({
|
return openpgp.decryptSessionKeys({
|
||||||
message: encrypted.message,
|
message: encrypted.message,
|
||||||
privateKeys: invalidPrivateKey
|
privateKeys: invalidPrivateKey
|
||||||
|
}).then(() => {
|
||||||
|
throw new Error('Should not decrypt with invalid key');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
expect(error.message).to.match(/Error decrypting session keys: Session key decryption failed./);
|
expect(error.message).to.match(/Error decrypting session keys: Session key decryption failed./);
|
||||||
});
|
});
|
||||||
|
@ -2402,7 +2403,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.encrypt({
|
return openpgp.encrypt({
|
||||||
message: openpgp.message.fromText(plaintext),
|
message: openpgp.message.fromText(plaintext),
|
||||||
publicKeys: revKey.publicKey
|
publicKeys: revKey.publicKey
|
||||||
}).then(function(encrypted) {
|
}).then(function() {
|
||||||
throw new Error('Should not encrypt with revoked key');
|
throw new Error('Should not encrypt with revoked key');
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
expect(error.message).to.match(/Error encrypting message: Primary key is revoked/);
|
expect(error.message).to.match(/Error encrypting message: Primary key is revoked/);
|
||||||
|
@ -2419,7 +2420,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.encrypt({
|
return openpgp.encrypt({
|
||||||
message: openpgp.message.fromText(plaintext),
|
message: openpgp.message.fromText(plaintext),
|
||||||
publicKeys: pubKeyDE
|
publicKeys: pubKeyDE
|
||||||
}).then(function(encrypted) {
|
}).then(function() {
|
||||||
throw new Error('Should not encrypt with revoked subkey');
|
throw new Error('Should not encrypt with revoked subkey');
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
expect(error.message).to.match(/Could not find valid encryption key packet/);
|
expect(error.message).to.match(/Could not find valid encryption key packet/);
|
||||||
|
@ -2526,11 +2527,9 @@ amnR6g==
|
||||||
return openpgp.encrypt({
|
return openpgp.encrypt({
|
||||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
|
||||||
passwords: null
|
passwords: null
|
||||||
})
|
}).then(function() {
|
||||||
.then(function() {
|
|
||||||
throw new Error('Error expected.');
|
throw new Error('Error expected.');
|
||||||
})
|
}).catch(function(error) {
|
||||||
.catch(function(error) {
|
|
||||||
expect(error.message).to.match(/No keys, passwords, or session key provided/);
|
expect(error.message).to.match(/No keys, passwords, or session key provided/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user