openpgpjs/test/general/decompression.js
larabr ae4ed1fbf3 Tests: explicitly share openpgp instance used in tests
Also, init config before any code is run in tests
2023-10-25 12:53:10 +02:00

60 lines
1.6 KiB
JavaScript

import { use as chaiUse, expect } from 'chai';
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
chaiUse(chaiAsPromised);
import openpgp from '../initOpenpgp.js';
const password = 'I am a password';
const tests = {
zip: {
input: `-----BEGIN PGP MESSAGE-----
jA0ECQMC5rhAA7l3jOzk0kwBTMc07y+1NME5RCUQ2EOlSofbh1KARLC5B1NMeBlq
jS917VBeCW3R21xG+0ZJ6Z5iWwdQD7XBtg19doWOqExSmXBWWW/6vSaD81ox
=Gw9+
-----END PGP MESSAGE-----`,
output: 'Hello world! With zip.'
},
zlib: {
input: `-----BEGIN PGP MESSAGE-----
jA0ECQMC8Qfig2+Tygnk0lMB++5JoyZUcpUy5EJqcxBuy93tXw+BSk7OhFhda1Uo
JuQlKv27HlyUaA55tMJsFYPypGBLEXW3k0xi3Cs87RrLqmVGTZSqNhHOVNE28lVe
W40mpQ==
=z0we
-----END PGP MESSAGE-----`,
output: 'Hello world! With zlib.'
},
bzip2: {
input: `-----BEGIN PGP MESSAGE-----
jA0ECQMC97w+wp7u9/Xk0oABBfapJBuuxGBiHDfNmVgsRzbjLDBWTJ3LD4UtxEku
qu6hwp5JXB0TgI/XQ3tKobSqHv1wSJ9SVxtWZq6WvWulu+j9GtzIVC3mbDA/qRA3
41sUEMdAFC6I7BYLYGEiUAVNpjbvGOmJWptDyawjRgEuZeTzKyTI/UcMc/rLy9Pz
Xg==
=6ek1
-----END PGP MESSAGE-----`,
output: 'Hello world! With bzip2.'
}
};
export default () => describe('Decrypt and decompress message tests', function () {
function runTest(key, test) {
it(`Decrypts message compressed with ${key}`, async function () {
const message = await openpgp.readMessage({ armoredMessage: test.input });
const options = {
passwords: password,
message
};
return openpgp.decrypt(options).then(function (decrypted) {
expect(decrypted.data).to.equal(test.output + '\n');
});
});
}
Object.keys(tests).forEach(key => runTest(key, tests[key]));
});