Elysia.js API with session-based auth (email/password + Google OAuth), role system (USER/ADMIN/SUPER_ADMIN), Prisma + PostgreSQL, React 19 with Mantine UI, TanStack Router, dark theme, and comprehensive test suite (unit, integration, E2E with Lightpanda). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
995 B
TypeScript
25 lines
995 B
TypeScript
import { test, expect, describe } from 'bun:test'
|
|
|
|
describe('Bun.password (bcrypt)', () => {
|
|
test('hash and verify correct password', async () => {
|
|
const hash = await Bun.password.hash('mypassword', { algorithm: 'bcrypt' })
|
|
expect(hash).toStartWith('$2')
|
|
const valid = await Bun.password.verify('mypassword', hash)
|
|
expect(valid).toBe(true)
|
|
})
|
|
|
|
test('reject wrong password', async () => {
|
|
const hash = await Bun.password.hash('mypassword', { algorithm: 'bcrypt' })
|
|
const valid = await Bun.password.verify('wrongpassword', hash)
|
|
expect(valid).toBe(false)
|
|
})
|
|
|
|
test('different hashes for same password', async () => {
|
|
const hash1 = await Bun.password.hash('same', { algorithm: 'bcrypt' })
|
|
const hash2 = await Bun.password.hash('same', { algorithm: 'bcrypt' })
|
|
expect(hash1).not.toBe(hash2) // bcrypt salt differs
|
|
expect(await Bun.password.verify('same', hash1)).toBe(true)
|
|
expect(await Bun.password.verify('same', hash2)).toBe(true)
|
|
})
|
|
})
|