mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
3838d3d212
* chore: clean lint warnings * refactor: move core packages
31 lines
941 B
TypeScript
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'));
|
|
});
|
|
});
|