Files
O96u bc4cba7e52 release: PicHost v1.0.0
Multi-user image hosting with RBAC, upload preferences, and admin settings.
2026-08-22 14:36:57 +08:00

23 lines
793 B
TypeScript

import { describe, expect, it } from 'vitest'
import { hashPassword, isValidPassword, isValidUsername, verifyPassword } from './auth'
describe('auth password', () => {
it('hashes and verifies a password', () => {
const hash = hashPassword('test-password-123')
expect(hash.startsWith('scrypt$')).toBe(true)
expect(verifyPassword('test-password-123', hash)).toBe(true)
expect(verifyPassword('wrong-password', hash)).toBe(false)
})
it('rejects invalid passwords', () => {
expect(isValidPassword('short')).toBe(false)
expect(isValidPassword('long-enough')).toBe(true)
})
it('validates usernames', () => {
expect(isValidUsername('ab')).toBe(false)
expect(isValidUsername('user_1')).toBe(true)
expect(isValidUsername('bad name')).toBe(false)
})
})