karbe/tests/lib/password.test.ts
Claude Integration 14fd9a5940
Some checks failed
CI / test (pull_request) Failing after 2m13s
feat(p2): vitest + 27 tests + /api/health enrichi + /api/metrics + workflow CI
2026-06-01 02:27:14 +00:00

27 lines
958 B
TypeScript

import { describe, it, expect } from "vitest";
import { hashPassword, verifyPassword } from "@/lib/password";
describe("password hashing", () => {
it("round-trips a correct password", async () => {
const plain = "correct horse battery staple";
const hash = await hashPassword(plain);
expect(hash).not.toEqual(plain);
expect(hash.startsWith("$2")).toBe(true);
expect(await verifyPassword(plain, hash)).toBe(true);
});
it("rejects incorrect password", async () => {
const hash = await hashPassword("rightpass123");
expect(await verifyPassword("wrongpass", hash)).toBe(false);
});
it("produces different hashes for the same plaintext (salted)", async () => {
const plain = "samepw";
const a = await hashPassword(plain);
const b = await hashPassword(plain);
expect(a).not.toEqual(b);
expect(await verifyPassword(plain, a)).toBe(true);
expect(await verifyPassword(plain, b)).toBe(true);
});
});