0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/signature/test/legacy-token.spec.ts
Juan Picado 0c7b19b192
chore: migrate vitest packages (#4777)
* chore: migrate core to vitest

* chore: migrate url module

* chore: migrate tarball package

* chore: migrate loader package

* chore: migrate hook package

* chore: migrate signature package

* chore: migrate utils package
2024-08-03 19:39:22 +02:00

20 lines
651 B
TypeScript

import { describe, expect, test } from 'vitest';
import { aesDecrypt, aesEncrypt } from '../src';
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';
expect(() => aesEncrypt(payload, secret)).toThrow('Invalid secret key length');
});
});