Initial commit: full-stack Bun + Elysia + React template
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>
This commit is contained in:
24
tests/unit/password.test.ts
Normal file
24
tests/unit/password.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user