import { describe, expect, it } from 'vitest' import { hashPassword, verifyPassword } from './password.ts' describe('password hashing', () => { it('verifies the right password and rejects the wrong one', async () => { const hash = await hashPassword('correct horse battery') expect(hash).toMatch(/^scrypt\$32768\$8\$3\$/) expect(await verifyPassword('correct horse battery', hash)).toBe(true) expect(await verifyPassword('wrong horse battery', hash)).toBe(false) }) it('salts each hash', async () => { expect(await hashPassword('same password')).not.toBe(await hashPassword('same password')) }) it('rejects malformed hashes', async () => { expect(await verifyPassword('anything', 'not-a-hash')).toBe(false) }) })