0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
verdaccio/packages/core/htpasswd/tests/crypt3.test.ts
Juan Picado 3838d3d212 feat: relocate core packages (#1906)
* chore: clean lint warnings

* refactor: move core packages
2021-04-09 17:54:13 +02:00

31 lines
941 B
TypeScript

import { createSalt } from '../src/crypt3';
jest.mock('crypto', () => {
return {
randomBytes: (): { toString: () => string } => {
return {
toString: (): string => '/UEGzD0RxSNDZA==',
};
},
};
});
describe('createSalt', () => {
test('should match with the correct salt type', () => {
expect(createSalt('crypt')).toEqual('/UEGzD0RxSNDZA==');
expect(createSalt('md5')).toEqual('$1$/UEGzD0RxSNDZA==');
expect(createSalt('blowfish')).toEqual('$2a$/UEGzD0RxSNDZA==');
expect(createSalt('sha256')).toEqual('$5$/UEGzD0RxSNDZA==');
expect(createSalt('sha512')).toEqual('$6$/UEGzD0RxSNDZA==');
});
test('should fails on unkwon type', () => {
expect(function () {
createSalt('bad');
}).toThrow(/Unknown salt type at crypt3.createSalt: bad/);
});
test('should generate legacy crypt salt by default', () => {
expect(createSalt()).toEqual(createSalt('crypt'));
});
});