diff options
author | 2023-03-07 12:22:34 -0800 | |
---|---|---|
committer | 2023-03-07 12:22:34 -0800 | |
commit | f7e4eb83694aa007a492ef66c28ffbe6a2dae791 (patch) | |
tree | 7af25aa5c42a2e1b2b47ba1df35f8caa9054cbeb /test/js/node/crypto/node-crypto.test.js | |
parent | 36275a44ce7a33587bd26aad120042ab95470ff3 (diff) | |
download | bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.gz bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.zst bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.zip |
Reorganize tests (#2332)
Diffstat (limited to 'test/js/node/crypto/node-crypto.test.js')
-rw-r--r-- | test/js/node/crypto/node-crypto.test.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js new file mode 100644 index 000000000..f148f4fe9 --- /dev/null +++ b/test/js/node/crypto/node-crypto.test.js @@ -0,0 +1,29 @@ +import { it, expect } from "bun:test"; + +import crypto from "node:crypto"; + +it("crypto.randomBytes should return a Buffer", () => { + expect(crypto.randomBytes(1) instanceof Buffer).toBe(true); + expect(Buffer.isBuffer(crypto.randomBytes(1))).toBe(true); +}); + +// https://github.com/oven-sh/bun/issues/1839 +it("crypto.createHash ", () => { + function fn() { + crypto.createHash("sha1").update(Math.random(), "ascii").digest("base64"); + } + + for (let i = 0; i < 10; i++) fn(); +}); + +it("crypto.createHmac", () => { + const result = crypto.createHmac("sha256", "key").update("message").digest("base64"); + + expect(result).toBe("bp7ym3X//Ft6uuUn1Y/a2y/kLnIZARl2kXNDBl9Y7Uo="); +}); + +it("web crypto", async () => { + let bytes = new Uint8Array(32); + crypto.getRandomValues(bytes); + await crypto.subtle.digest("SHA-256", bytes); +}); |