summaryrefslogtreecommitdiff
path: root/tests/unit_node
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_node')
-rw-r--r--tests/unit_node/crypto/crypto_hash_test.ts26
-rw-r--r--tests/unit_node/crypto/crypto_misc_test.ts18
2 files changed, 26 insertions, 18 deletions
diff --git a/tests/unit_node/crypto/crypto_hash_test.ts b/tests/unit_node/crypto/crypto_hash_test.ts
index 74223067e..96bc1d51b 100644
--- a/tests/unit_node/crypto/crypto_hash_test.ts
+++ b/tests/unit_node/crypto/crypto_hash_test.ts
@@ -1,11 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-import {
- createHash,
- createHmac,
- getHashes,
- randomFillSync,
- randomUUID,
-} from "node:crypto";
+import { createHash, createHmac, getHashes } from "node:crypto";
import { Buffer } from "node:buffer";
import { Readable } from "node:stream";
import { assert, assertEquals } from "@std/assert/mod.ts";
@@ -123,17 +117,13 @@ Deno.test("[node/crypto.getHashes]", () => {
}
});
-Deno.test("[node/crypto.getRandomUUID] works the same way as Web Crypto API", () => {
- assertEquals(randomUUID().length, crypto.randomUUID().length);
- assertEquals(typeof randomUUID(), typeof crypto.randomUUID());
+Deno.test("[node/crypto.hash] supports buffer args", () => {
+ const buffer = Buffer.from("abc");
+ const d = createHash("sha1").update(buffer).digest("hex");
+ assertEquals(d, "a9993e364706816aba3e25717850c26c9cd0d89d");
});
-Deno.test("[node/crypto.randomFillSync] supported arguments", () => {
- const buf = new Uint8Array(10);
-
- assert(randomFillSync(buf));
- assert(randomFillSync(buf, 0));
- // @ts-ignore: arraybuffer arguments are valid.
- assert(randomFillSync(buf.buffer));
- assert(randomFillSync(new DataView(buf.buffer)));
+Deno.test("[node/crypto.hash] does not leak", () => {
+ const hasher = createHash("sha1");
+ hasher.update("abc");
});
diff --git a/tests/unit_node/crypto/crypto_misc_test.ts b/tests/unit_node/crypto/crypto_misc_test.ts
new file mode 100644
index 000000000..8132f2e99
--- /dev/null
+++ b/tests/unit_node/crypto/crypto_misc_test.ts
@@ -0,0 +1,18 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+import { randomFillSync, randomUUID } from "node:crypto";
+import { assert, assertEquals } from "../../unit/test_util.ts";
+
+Deno.test("[node/crypto.getRandomUUID] works the same way as Web Crypto API", () => {
+ assertEquals(randomUUID().length, crypto.randomUUID().length);
+ assertEquals(typeof randomUUID(), typeof crypto.randomUUID());
+});
+
+Deno.test("[node/crypto.randomFillSync] supported arguments", () => {
+ const buf = new Uint8Array(10);
+
+ assert(randomFillSync(buf));
+ assert(randomFillSync(buf, 0));
+ // @ts-ignore: arraybuffer arguments are valid.
+ assert(randomFillSync(buf.buffer));
+ assert(randomFillSync(new DataView(buf.buffer)));
+});