26 lines
664 B
TypeScript
26 lines
664 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
generateSecureToken,
|
|
hashToken,
|
|
verifyTokenHash,
|
|
} from "./tokens";
|
|
|
|
describe("tokens", () => {
|
|
it("produces consistent hashes for the same token", () => {
|
|
const token = generateSecureToken();
|
|
const firstHash = hashToken(token);
|
|
const secondHash = hashToken(token);
|
|
|
|
expect(firstHash).toBe(secondHash);
|
|
expect(verifyTokenHash(token, firstHash)).toBe(true);
|
|
});
|
|
|
|
it("rejects tokens that do not match the hash", () => {
|
|
const token = generateSecureToken();
|
|
const hashed = hashToken(token);
|
|
|
|
expect(verifyTokenHash("different-token", hashed)).toBe(false);
|
|
});
|
|
});
|