summaryrefslogtreecommitdiff
path: root/tests/unit_node/crypto/crypto_key_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-06-21 12:25:07 +0200
committerGitHub <noreply@github.com>2024-06-21 10:25:07 +0000
commite6756c3e666e33aa9ee650b7a348a41d29cb3160 (patch)
tree8d5f54e03f34e118762d447775a5acf3eae2895e /tests/unit_node/crypto/crypto_key_test.ts
parent5683ca40707ae98bba6b58c710b9ff31e9f41944 (diff)
fix(ext/node): don't panic on invalid utf-8 in pem (#24303)
Diffstat (limited to 'tests/unit_node/crypto/crypto_key_test.ts')
-rw-r--r--tests/unit_node/crypto/crypto_key_test.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_key_test.ts b/tests/unit_node/crypto/crypto_key_test.ts
index 013601572..d3a43b3b8 100644
--- a/tests/unit_node/crypto/crypto_key_test.ts
+++ b/tests/unit_node/crypto/crypto_key_test.ts
@@ -415,3 +415,27 @@ Deno.test("generate rsa export public key", async function () {
const der = publicKey.export({ format: "der", type: "spki" });
assert(der instanceof Uint8Array);
});
+
+Deno.test("create public key with invalid utf-8 string", function () {
+ // This is an invalid UTF-8 string because it contains a lone utf-16 surrogate.
+ const invalidPem = Buffer.from(new Uint8Array([0xE2, 0x28, 0xA1]));
+ assertThrows(
+ () => {
+ createPublicKey(invalidPem);
+ },
+ Error,
+ "not valid utf8",
+ );
+});
+
+Deno.test("create private key with invalid utf-8 string", function () {
+ // This is an invalid UTF-8 string because it contains a lone utf-16 surrogate.
+ const invalidPem = Buffer.from(new Uint8Array([0xE2, 0x28, 0xA1]));
+ assertThrows(
+ () => {
+ createPrivateKey(invalidPem);
+ },
+ Error,
+ "not valid utf8",
+ );
+});