Phase1
This commit is contained in:
25
packages/auth/src/tokens.test.ts
Normal file
25
packages/auth/src/tokens.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user