Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / test / keys / keyImport.spec.js
blob932eea443003cabb237a27693c57fd194fc66c86
1 import { parseArmoredKeys, parseKeys } from '../../lib/keys';
3 const VALID_KEY =
4     '-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: ProtonMail\nComment: https://protonmail.com\n\nxcMGBFyrS04BCACBgtwInaHKPg/pOR4IsgSF4/z9iDgTTt7pTr407VFLUebR\niymA0m3Adx3OLKlwo/kDgYpaltwR1BPTOpVpIYrpE9zvlLNs6V1/Ub3CKumz\nhXSM2mQkWp51/C7/AwAER1aKukd34Iq/HiToBXxWlk2ajyr7O/LX2i8uoVrX\n35bly0Qaa+T9vHdNpJ4hL/GR8GXgX0dItipUT2Mp0RRZJ7hL8QzyXg53Voyy\nX4PpvoIeys9wtx/DH0r9q1UsKgpP1+VLlEXkr0YeokUcSvApf2IB7POYYZ9X\nxIs87+hsalX2uux6fPFpAfKo4lY4qlraM3K+gRVM9loJ/lhWCgmo+qlFABEB\nAAH+CQMIPyxNFMp7oRJgDDdUMEaqAavMzfG32SliGvRZevba9sS4/5h/3gHx\nyWLSDTJ7oeRP2ZV792nsfm7c0lCeQjNKfWRW1qKv3jjtOvbEoRLZ7TFJLu2n\nNkVtILnM5cF05mv4lVAq83iJJDQT61wmMrrOA/Ko8GtzHJN2/6hxdFkSSAFb\nKvi98IvqZxJoDbo/16FCSAXyLga4Zc+0D7cqHuVfcb7ql1Vii/xcSzFruRuQ\njXOf2/VI8fc0YWU8jk079nST52GTX0hW947pXI/PJ/EkJb3AxhMbCgb8Fsqi\necIXiVLEdV8QaVZmBcUssu6YhSYvtT1UPC7vvAVN/Wq8xjj8ripvoCe/cNgN\nthWGeY7coyNfjxD26jCr7Vnt9bcpJ5pp6INs9Wnz6oKtRWlFdw1zeZz/wtLu\nJ36oNojKBes9gRurMukE1+O5uipqHbsGFDrGrI+WPoqPfqCinUkpIxjnNYfG\n8kY4jRgymK/9B37IjrI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TS4\n0xR5r+r3/IXxmJzpAM8M/xzbS/I1DXOGDHD47fROnWqlnbHyPATua7iZ0JY4\nm6ezhgAj4qzNNeO29O7ac7lMbmEjP6W9Qh3MxCSXFDkN4UJnF9HseSSejRDN\n4mffNuU2wsBfBBgBCAAJBQJcq0tOAhsMAAoJECcG8nK79wxhlSYH/jglsWN6\nalN+ERyI7PNr1/hd8YfPNGedQC2zh1/Sbuj8sNWWQmjagTjmEGUHLSjZH1na\nPecujlUMGLRAkFjND/nplUk+pWvtX9j0902qsJh1sT0J1lCdaWlG1YuHw08H\nRBDpfbrE2H4pkcX+f6E5Idau9l/Wk2j5GB/0TvS1tnlY5+5ZTbYXCwHhRdY6\n4WOAOJijxyfaWPKlWgwbDIUSdlnOX1t5F3TrM2m8YgFXd9kE/QcjO9ib0nnq\nqTQ3ZTlRVsyftC/0htXiAGntAgZ8P4KLCMoM+03/fkih1H9qKgcTg5xPFqDY\nqxNXJd5vAkDBhT7GE3SynVm5htlqqP971VI=\n=1a6B\n-----END PGP PRIVATE KEY BLOCK-----';
6 const INVALID_KEY = `-----BEGIN PGP PRIVATE KEY BLOCK-----
7 Version: OpenPGP.js v4.2.2
8 Comment: https://openpgpjs.org
10 =twTO
11 -----END PGP PRIVATE KEY BLOCK-----`;
13 const KEY_DATA2 = `-----BEGIN PGP PRIVATE KEY BLOCK-----
14 Version: OpenPGP.js v4.2.2
15 Comment: https://openpgpjs.org
18 -----END PGP PRIVATE KEY BLOCK-----`;
20 describe('key import', () => {
21     it('should parse key', () => {
22         const parsedKeys = parseArmoredKeys(INVALID_KEY);
23         expect(parsedKeys).toEqual([INVALID_KEY]);
24     });
26     it('should parse multiple keys', () => {
27         const parsedKeys = parseArmoredKeys(`
28             ${INVALID_KEY}
30             random data
31             foo
32             ${KEY_DATA2}
33         `);
34         expect(parsedKeys).toEqual([INVALID_KEY, KEY_DATA2]);
35     });
37     it('should handle invalid keys', async () => {
38         const parsedKeys = await parseKeys([INVALID_KEY]);
39         expect(parsedKeys).toEqual([]);
40     });
42     it('should handle valid keys', async () => {
43         const parsedKeys = await parseKeys([VALID_KEY]);
44         expect(parsedKeys).toEqual([jasmine.any(Object)]);
45     });
46 });