2020-05-12 14:30:44 -04:00
|
|
|
import * as fs from 'fs';
|
2020-05-04 10:17:14 -04:00
|
|
|
import * as openpgp from '../src/openpgp';
|
2020-05-03 14:46:05 -04:00
|
|
|
|
|
|
|
const userInfo = {
|
2020-05-12 14:30:44 -04:00
|
|
|
pgp: fs.readFileSync('.github/test-key.pgp', {
|
|
|
|
encoding: 'utf8',
|
|
|
|
flag: 'r'
|
|
|
|
}),
|
2020-05-18 11:31:00 -04:00
|
|
|
pgp_base64: fs.readFileSync('.github/test-key-base64.pgp', {
|
|
|
|
encoding: 'utf8',
|
|
|
|
flag: 'r'
|
|
|
|
}),
|
2020-05-12 14:30:44 -04:00
|
|
|
passphrase: fs.readFileSync('.github/test-key.pass', {
|
|
|
|
encoding: 'utf8',
|
|
|
|
flag: 'r'
|
|
|
|
}),
|
2020-05-03 14:46:05 -04:00
|
|
|
name: 'Joe Tester',
|
|
|
|
email: 'joe@foo.bar',
|
|
|
|
keyID: 'D523BD50DD70B0BA',
|
|
|
|
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
|
2020-05-12 14:30:44 -04:00
|
|
|
keygrip: '3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627'
|
2020-05-03 14:46:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('openpgp', () => {
|
|
|
|
describe('readPrivateKey', () => {
|
2020-05-13 08:10:12 -04:00
|
|
|
it('returns a PGP private key from an armored string', async () => {
|
2020-05-04 10:17:14 -04:00
|
|
|
await openpgp.readPrivateKey(userInfo.pgp).then(privateKey => {
|
2020-05-03 14:46:05 -04:00
|
|
|
expect(privateKey.keyID).toEqual(userInfo.keyID);
|
2020-05-05 14:01:45 -04:00
|
|
|
expect(privateKey.name).toEqual(userInfo.name);
|
|
|
|
expect(privateKey.email).toEqual(userInfo.email);
|
2020-05-03 14:46:05 -04:00
|
|
|
expect(privateKey.fingerprint).toEqual(userInfo.fingerprint);
|
|
|
|
});
|
|
|
|
});
|
2020-05-13 08:10:12 -04:00
|
|
|
it('returns a PGP private key from a base64 armored string', async () => {
|
2020-05-18 11:31:00 -04:00
|
|
|
await openpgp.readPrivateKey(userInfo.pgp_base64).then(privateKey => {
|
2020-05-13 08:10:12 -04:00
|
|
|
expect(privateKey.keyID).toEqual(userInfo.keyID);
|
|
|
|
expect(privateKey.name).toEqual(userInfo.name);
|
|
|
|
expect(privateKey.email).toEqual(userInfo.email);
|
|
|
|
expect(privateKey.fingerprint).toEqual(userInfo.fingerprint);
|
|
|
|
});
|
|
|
|
});
|
2020-05-03 14:46:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('generateKeyPair', () => {
|
|
|
|
it('generates a PGP key pair', async () => {
|
2020-05-04 10:17:14 -04:00
|
|
|
await openpgp.generateKeyPair(userInfo.name, userInfo.email, userInfo.passphrase).then(keyPair => {
|
2020-05-03 14:46:05 -04:00
|
|
|
expect(keyPair).not.toBeUndefined();
|
|
|
|
expect(keyPair.publicKey).not.toBeUndefined();
|
|
|
|
expect(keyPair.privateKey).not.toBeUndefined();
|
|
|
|
});
|
|
|
|
}, 30000);
|
|
|
|
});
|
2020-05-18 11:31:00 -04:00
|
|
|
|
|
|
|
describe('isArmored', () => {
|
|
|
|
it('returns true for armored key string', async () => {
|
|
|
|
await openpgp.isArmored(userInfo.pgp).then(armored => {
|
|
|
|
expect(armored).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns false for base64 key string', async () => {
|
|
|
|
await openpgp.isArmored(userInfo.pgp_base64).then(armored => {
|
|
|
|
expect(armored).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-03 14:46:05 -04:00
|
|
|
});
|