Public Access
/reset-password page for the email request and the new password, ChangePasswordCard in settings, password reset button on the admin users page, 'Forgot password?' link on the login page, de/en texts.
73 lines
3.1 KiB
JavaScript
73 lines
3.1 KiB
JavaScript
import {describe, expect, it} from 'vitest';
|
|
import {changePasswordSchema, confirmEmailSchema, registrationSchema, settingsSchema} from './validation.js';
|
|
|
|
const settings = () => ({useDarkTheme: true, language: 'de'});
|
|
|
|
describe('Steam ID', () => {
|
|
it('is no form field any more: it comes only from "Sign in through Steam"', () => {
|
|
expect(settingsSchema.parse({...settings(), steamId: '76561198005679788'})).not.toHaveProperty('steamId');
|
|
expect(registrationSchema.parse({
|
|
email: 'a@b.de',
|
|
steamId: '76561198005679788',
|
|
})).not.toHaveProperty('steamId');
|
|
});
|
|
});
|
|
|
|
describe('displayName validation', () => {
|
|
const withName = (displayName) => ({...settings(), displayName});
|
|
|
|
it('turns an empty field into null (no display name)', () => {
|
|
expect(settingsSchema.parse(withName(' ')).displayName).toBeNull();
|
|
});
|
|
|
|
it('trims and keeps a valid name', () => {
|
|
expect(settingsSchema.parse(withName(' Lobo Corp_1 ')).displayName).toBe('Lobo Corp_1');
|
|
});
|
|
|
|
it.each(['ab', '<script>', 'a'.repeat(25)])('rejects %j', (displayName) => {
|
|
expect(settingsSchema.safeParse(withName(displayName)).success).toBe(false);
|
|
});
|
|
});
|
|
|
|
|
|
describe('confirm page password', () => {
|
|
it('rejects a password over 72 UTF-8 bytes, as Auth does', () => {
|
|
const password = 'é'.repeat(37);
|
|
expect(confirmEmailSchema.safeParse({password, passwordConfirmation: password}).success).toBe(false);
|
|
});
|
|
|
|
it('rejects a short password and one that differs from its repeat', () => {
|
|
expect(confirmEmailSchema.safeParse({password: 'short', passwordConfirmation: 'short'}).success).toBe(false);
|
|
expect(confirmEmailSchema.safeParse({password: 'password1', passwordConfirmation: 'password2'}).success).toBe(false);
|
|
});
|
|
|
|
it('takes a good password', () => {
|
|
expect(confirmEmailSchema.safeParse({password: 'password1', passwordConfirmation: 'password1'}).success).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('changePasswordSchema', () => {
|
|
const valid = {currentPassword: 'old', password: 'password1', passwordConfirmation: 'password1'};
|
|
|
|
it('takes a current password and a good new one', () => {
|
|
expect(changePasswordSchema.safeParse(valid).success).toBe(true);
|
|
});
|
|
|
|
it('requires the current password', () => {
|
|
expect(changePasswordSchema.safeParse({...valid, currentPassword: ''}).success).toBe(false);
|
|
});
|
|
|
|
it('applies the rules of the new password and the repeat', () => {
|
|
expect(changePasswordSchema.safeParse({...valid, password: 'short', passwordConfirmation: 'short'}).success).toBe(false);
|
|
expect(changePasswordSchema.safeParse({...valid, passwordConfirmation: 'password2'}).success).toBe(false);
|
|
const long = 'é'.repeat(37);
|
|
expect(changePasswordSchema.safeParse({...valid, password: long, passwordConfirmation: long}).success).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('registration', () => {
|
|
it('has no password field', () => {
|
|
expect(registrationSchema.parse({email: 'a@b.de', password: 'password1'})).not.toHaveProperty('password');
|
|
});
|
|
});
|