emailpassword.test.ts28 lines · main
1import { describe, expect, test } from 'bun:test';
2
3import { hashPassword, verifyPassword } from './emailpassword.js';
4
5describe('briven-engine password hash (Phase 2)', () => {
6 test('hashes and verifies correct password', () => {
7 const { hash } = hashPassword('Step2Test!Pass99');
8 expect(hash.includes(':')).toBe(true);
9 expect(verifyPassword('Step2Test!Pass99', hash)).toBe(true);
10 });
11
12 test('rejects wrong password', () => {
13 const { hash } = hashPassword('correct-horse');
14 expect(verifyPassword('wrong-battery', hash)).toBe(false);
15 });
16
17 test('same salt is deterministic', () => {
18 const salt = 'a'.repeat(32);
19 const a = hashPassword('same', salt);
20 const b = hashPassword('same', salt);
21 expect(a.hash).toBe(b.hash);
22 });
23
24 test('malformed stored hash fails closed', () => {
25 expect(verifyPassword('x', 'not-a-hash')).toBe(false);
26 expect(verifyPassword('x', '')).toBe(false);
27 });
28});