aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/node-crypto.test.js
blob: 151a06198b688a00a354f7fc65d38ca60eecace3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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=");
});