diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-09-11 13:27:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-11 13:27:07 +0900 |
commit | ef2d98fe11ffe467a31d2e30e3ae9738147b74e9 (patch) | |
tree | cfbf1b93aaa447833f2e3c789625091bbcae2e1a /tests | |
parent | 1521adf5ed640832755e362abc64b32afd7dcc7d (diff) |
fix(ext/node): validate input lengths in `Cipheriv` and `Decipheriv` (#25570)
addresses the first part of #25279
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); |