Prisma models per data-model.md: users (status enum, site-admin flag), user_identities (password provider now, OIDC later — subject is the stable user id), sessions (hashed ids), auth_tokens (hashed, single- use), plus rate_limits and mail_outbox for the upcoming M1 stories. UsersService creates accounts transactionally with Argon2id-hashed password identities (OWASP parameters, rehash detection) and maps uniqueness violations to field-level conflicts. Database-backed suites run when TEST_DATABASE_URL is set — locally against the dev db, in CI via a new postgres service container; shared auth schemas (username, password policy incl. common-password blocklist) ship with tests. Closes #10 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { passwordSchema, signupInputSchema, usernameSchema } from './auth';
|
|
|
|
describe('auth schemas', () => {
|
|
it('accepts sensible usernames and rejects unsafe ones', () => {
|
|
expect(usernameSchema.safeParse('stefan-w').success).toBe(true);
|
|
expect(usernameSchema.safeParse('ab').success).toBe(false);
|
|
expect(usernameSchema.safeParse('-leading').success).toBe(false);
|
|
expect(usernameSchema.safeParse('has space').success).toBe(false);
|
|
});
|
|
|
|
it('enforces password length and the common-password blocklist', () => {
|
|
expect(passwordSchema.safeParse('korrekt pferd batterie').success).toBe(true);
|
|
expect(passwordSchema.safeParse('short').success).toBe(false);
|
|
expect(passwordSchema.safeParse('Password123').success).toBe(false);
|
|
});
|
|
|
|
it('parses a complete signup payload with locale default', () => {
|
|
const parsed = signupInputSchema.parse({
|
|
username: 'uma',
|
|
email: 'uma@example.org',
|
|
displayName: 'Uma',
|
|
password: 'ein sehr gutes passwort',
|
|
});
|
|
expect(parsed.locale).toBe('en');
|
|
});
|
|
});
|