argon2.test.ts

1.2 KB · raw

1import { describe, expect, it } from "vitest";23import { deriveKey, generateSalt } from "./argon2";45describe("crypto argon2", () => {6  it("deriveKey is deterministic for the same password and salt", async () => {7    const salt = generateSalt();89    const first = await deriveKey("correct-pass-12345", salt);10    const second = await deriveKey("correct-pass-12345", salt);1112    expect(first).toEqual(second);13  });1415  it("deriveKey changes when the salt changes", async () => {16    const first = await deriveKey("correct-pass-12345", generateSalt());17    const second = await deriveKey("correct-pass-12345", generateSalt());1819    expect(first).not.toEqual(second);20  });2122  it("deriveKey changes when the password changes", async () => {23    const salt = generateSalt();2425    const first = await deriveKey("correct-pass-12345", salt);26    const second = await deriveKey("wrong-pass-67890", salt);2728    expect(first).not.toEqual(second);29  });3031  it("generateSalt returns 16 bytes", () => {32    expect(generateSalt()).toHaveLength(16);33  });3435  it("generateSalt returns different values across calls", () => {36    expect(generateSalt()).not.toEqual(generateSalt());37  });38});