29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { hashPassword, verifyPassword } from "../src/auth/password";
|
|
|
|
describe("hashPassword / verifyPassword (argon2id)", () => {
|
|
it("roundtrip", async () => {
|
|
const hash = await hashPassword("correct horse battery staple");
|
|
expect(hash).toMatch(/^\$argon2id\$/);
|
|
expect(await verifyPassword(hash, "correct horse battery staple")).toBe(true);
|
|
});
|
|
|
|
it("mauvais mot de passe → false", async () => {
|
|
const hash = await hashPassword("correct horse battery staple");
|
|
expect(await verifyPassword(hash, "nope")).toBe(false);
|
|
});
|
|
|
|
it("hash invalide → false (jamais d'exception)", async () => {
|
|
expect(await verifyPassword("$argon2id$garbage", "x")).toBe(false);
|
|
expect(await verifyPassword("", "x")).toBe(false);
|
|
});
|
|
|
|
it("salé : même mot de passe → hashes différents", async () => {
|
|
const a = await hashPassword("même mot de passe");
|
|
const b = await hashPassword("même mot de passe");
|
|
expect(a).not.toBe(b);
|
|
expect(await verifyPassword(a, "même mot de passe")).toBe(true);
|
|
expect(await verifyPassword(b, "même mot de passe")).toBe(true);
|
|
});
|
|
});
|