add length test for random string generators

This commit is contained in:
Timo Hocker 2020-03-09 08:22:39 +01:00
parent e470b68ea5
commit c0ec49fd4b

View File

@ -29,6 +29,13 @@ test ('random_hex should refuse lenght smaller 1', (t) => {
t.is(error.message, 'invalid length');
});
test ('random_hex should always return correct length', (t)=>{
for (let i = 1; i < 32; i++) {
const hex = crypto.random_hex (i);
t.is (hex.length, i);
}
});
test ('random_string', (t) => {
const str = crypto.random_string (16);
t.is (str.length, 16);
@ -46,6 +53,14 @@ test ('random_string should refuse lenght smaller 1', (t) => {
t.is(error.message, 'invalid length');
});
test ('random_string should always return correct length', (t)=>{
for (let i = 1; i < 32; i++) {
const str = crypto.random_string (i);
t.is (str.length, i);
}
});
test ('hash_sha512', (t) => {
const hash = crypto.hash_sha512 ('a', 'b');
t.is (