From c0ec49fd4b3720871bccac4cf20947760e120e5c Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Mon, 9 Mar 2020 08:22:39 +0100 Subject: [PATCH] add length test for random string generators --- test/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/index.js b/test/index.js index c56ef71..2f0985f 100644 --- a/test/index.js +++ b/test/index.js @@ -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 (