CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
auth.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 06d5ffe | 1 | import { describe, it, expect } from "bun:test"; |
| 2 | import { | |
| 3 | hashPassword, | |
| 4 | verifyPassword, | |
| 5 | generateSessionToken, | |
| 6 | sessionExpiry, | |
| 7 | } from "../lib/auth"; | |
| 8 | ||
| 9 | describe("auth utilities", () => { | |
| 10 | it("should hash and verify passwords", async () => { | |
| 76581d3 | 11 | const password = `test${Math.random().toString(36).slice(2)}`; |
| 06d5ffe | 12 | const hash = await hashPassword(password); |
| 13 | ||
| 14 | expect(hash).toBeTruthy(); | |
| 15 | expect(hash).not.toBe(password); | |
| 16 | expect(await verifyPassword(password, hash)).toBe(true); | |
| 17 | expect(await verifyPassword("wrongpassword", hash)).toBe(false); | |
| 18 | }); | |
| 19 | ||
| 20 | it("should generate unique session tokens", () => { | |
| 21 | const token1 = generateSessionToken(); | |
| 22 | const token2 = generateSessionToken(); | |
| 23 | ||
| 24 | expect(token1).toBeTruthy(); | |
| 25 | expect(token1.length).toBe(64); // 32 bytes hex | |
| 26 | expect(token1).not.toBe(token2); | |
| 27 | }); | |
| 28 | ||
| 29 | it("should create future session expiry", () => { | |
| 30 | const expiry = sessionExpiry(); | |
| 31 | const now = new Date(); | |
| 32 | ||
| 33 | expect(expiry.getTime()).toBeGreaterThan(now.getTime()); | |
| 34 | // Should be ~30 days from now | |
| 35 | const diffDays = | |
| 36 | (expiry.getTime() - now.getTime()) / (1000 * 60 * 60 * 24); | |
| 37 | expect(diffDays).toBeGreaterThan(29); | |
| 38 | expect(diffDays).toBeLessThan(31); | |
| 39 | }); | |
| 76581d3 | 40 | }); |