Timo Hocker
ecd0195aee
All checks were successful
continuous-integration/drone/push Build is passing
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const crypto = require ('../../index');
|
|
|
|
// eslint-disable-next-line max-lines-per-function
|
|
describe ('random', () => {
|
|
it ('random_hex', () => {
|
|
const hex = crypto.random_hex (16);
|
|
expect (hex.length)
|
|
.toEqual (16);
|
|
expect (hex)
|
|
.toMatch (/^[0-9a-f]+$/iu);
|
|
});
|
|
|
|
it ('random_hex with default length', () => {
|
|
const hex = crypto.random_hex ();
|
|
expect (hex.length)
|
|
.toEqual (8);
|
|
expect (hex)
|
|
.toMatch (/^[0-9a-f]+$/iu);
|
|
});
|
|
|
|
it ('random_hex should refuse length smaller 1', () => {
|
|
expect (
|
|
() => (crypto.random_hex (0))
|
|
)
|
|
.toThrowError ('invalid length');
|
|
});
|
|
|
|
it ('random_hex should always return correct length', () => {
|
|
for (let i = 1; i < 32; i++) {
|
|
const hex = crypto.random_hex (i);
|
|
expect (hex.length)
|
|
.toEqual (i);
|
|
}
|
|
});
|
|
|
|
it ('random_string', () => {
|
|
const str = crypto.random_string (16);
|
|
expect (str.length)
|
|
.toEqual (16);
|
|
});
|
|
|
|
it ('random_string with default length', () => {
|
|
const str = crypto.random_string ();
|
|
expect (str.length)
|
|
.toEqual (8);
|
|
});
|
|
|
|
it ('random_string should refuse length smaller 1', () => {
|
|
expect (
|
|
() => (crypto.random_string (0))
|
|
)
|
|
.toThrowError ('invalid length');
|
|
});
|
|
|
|
it ('random_string should always return correct length', () => {
|
|
for (let i = 1; i < 32; i++) {
|
|
const str = crypto.random_string (i);
|
|
expect (str.length)
|
|
.toEqual (i);
|
|
}
|
|
});
|
|
|
|
it ('create_salt', () => {
|
|
const salt = crypto.create_salt ();
|
|
expect (salt.length)
|
|
.toEqual (64);
|
|
expect (salt)
|
|
.toMatch (/^[0-9a-f]+$/iu);
|
|
});
|
|
});
|