mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
0c7b19b192
* 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
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import { isNodeVersionGreaterThan21 } from '@verdaccio/config';
|
|
|
|
import {
|
|
aesDecryptDeprecated,
|
|
aesEncryptDeprecated,
|
|
generateRandomSecretKeyDeprecated,
|
|
} from '../src';
|
|
|
|
const itdescribe = (condition) => (condition ? describe : describe.skip);
|
|
|
|
itdescribe(isNodeVersionGreaterThan21() === false)('test deprecated crypto utils', () => {
|
|
test('generateRandomSecretKeyDeprecated', () => {
|
|
expect(generateRandomSecretKeyDeprecated()).toHaveLength(12);
|
|
});
|
|
|
|
test('decrypt payload flow', () => {
|
|
const secret = '4b4512c6ce20';
|
|
const payload = 'juan:password';
|
|
const token = aesEncryptDeprecated(Buffer.from(payload), secret);
|
|
|
|
expect(token.toString('base64')).toEqual('auizc1j3lSEd2wEB5CyGbQ==');
|
|
const data = aesDecryptDeprecated(token, secret);
|
|
|
|
expect(data.toString()).toEqual(payload.toString());
|
|
});
|
|
|
|
test('crypt fails if secret is incorrect', () => {
|
|
const payload = 'juan:password';
|
|
expect(aesEncryptDeprecated(Buffer.from(payload), 'fake_token').toString()).not.toEqual(
|
|
Buffer.from(payload)
|
|
);
|
|
});
|
|
});
|