2024-08-03 12:39:22 -05:00
|
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
|
2023-02-26 07:19:22 -05:00
|
|
|
import { aesDecrypt, aesEncrypt } from '../src';
|
2020-10-03 07:47:04 -05:00
|
|
|
|
|
|
|
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';
|
2024-05-03 01:59:29 -05:00
|
|
|
expect(() => aesEncrypt(payload, secret)).toThrow('Invalid secret key length');
|
2020-10-03 07:47:04 -05:00
|
|
|
});
|
|
|
|
});
|