0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/auth/test/legacy-token.spec.ts
Juan Picado e367c3f1e0 feat: improve legacy token signature by removing deprecated crypto.cr… (#1953)
* feat: improve legacy token signature by removing deprecated crypto.createDecipher

* fix: wrong reference

* chore: add debug
2021-04-09 17:54:21 +02:00

19 lines
622 B
TypeScript

import { aesDecrypt, aesEncrypt } from '../src/legacy-token';
describe('test crypto utils', () => {
test('decrypt payload flow', () => {
const secret = 'f5bb945cc57fea2f25961e1bd6fb3c89';
const payload = 'juan:password';
const token = aesEncrypt(payload, secret) as string;
const data = aesDecrypt(token, secret);
expect(payload).toEqual(data);
});
test('crypt fails if secret is incorrect', () => {
const secret = 'f5bb945cc57fea2f25961e1bd6fb3c89_TO_LONG';
const payload = 'juan';
const token = aesEncrypt(payload, secret) as string;
expect(token).toBeUndefined();
});
});