diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_node/crypto/crypto_cipher_test.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_cipher_test.ts b/tests/unit_node/crypto/crypto_cipher_test.ts index 91227cf00..ad424e5d4 100644 --- a/tests/unit_node/crypto/crypto_cipher_test.ts +++ b/tests/unit_node/crypto/crypto_cipher_test.ts @@ -246,6 +246,44 @@ Deno.test({ }); Deno.test({ + name: "createCipheriv - invalid inputs", + fn() { + assertThrows( + () => + crypto.createCipheriv("aes256", new Uint8Array(31), new Uint8Array(16)), + RangeError, + "Invalid key length", + ); + assertThrows( + () => + crypto.createCipheriv( + "aes-256-cbc", + new Uint8Array(31), + new Uint8Array(16), + ), + RangeError, + "Invalid key length", + ); + assertThrows( + () => + crypto.createCipheriv("aes256", new Uint8Array(32), new Uint8Array(15)), + TypeError, + "Invalid initialization vector", + ); + assertThrows( + () => + crypto.createCipheriv( + "aes-256-cbc", + new Uint8Array(32), + new Uint8Array(15), + ), + TypeError, + "Invalid initialization vector", + ); + }, +}); + +Deno.test({ name: "createDecipheriv - invalid algorithm", fn() { assertThrows( @@ -258,6 +296,52 @@ Deno.test({ }); Deno.test({ + name: "createDecipheriv - invalid inputs", + fn() { + assertThrows( + () => + crypto.createDecipheriv( + "aes256", + new Uint8Array(31), + new Uint8Array(16), + ), + RangeError, + "Invalid key length", + ); + assertThrows( + () => + crypto.createDecipheriv( + "aes-256-cbc", + new Uint8Array(31), + new Uint8Array(16), + ), + RangeError, + "Invalid key length", + ); + assertThrows( + () => + crypto.createDecipheriv( + "aes256", + new Uint8Array(32), + new Uint8Array(15), + ), + TypeError, + "Invalid initialization vector", + ); + assertThrows( + () => + crypto.createDecipheriv( + "aes-256-cbc", + new Uint8Array(32), + new Uint8Array(15), + ), + TypeError, + "Invalid initialization vector", + ); + }, +}); + +Deno.test({ name: "getCiphers", fn() { assertEquals(crypto.getCiphers().includes("aes-128-cbc"), true); |