Files
Gabriel20xx 817236f349
Security / Secrets (gitleaks) (push) Successful in 1m29s
Lint / Lint (push) Successful in 1m43s
Security / Dependencies (Trivy) (push) Successful in 1m59s
Security / Code (Semgrep) (push) Successful in 3m34s
Tests / Dashboard checks (push) Successful in 1m2s
Tests / Go backend (push) Successful in 3m13s
Docker / Docker Build & Push (push) Successful in 8m15s
feat: improve navigation and add security scans
- Hide the lone navigation tab and show mobile menus as overlays
- Add secret, code, and dependency scanning to CI
- Update test workflows and remove an unused frontend dependency
2026-10-27 09:54:10 +00:00

69 lines
2.6 KiB
TypeScript

import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/svelte';
import { afterEach, describe, expect, it, vi } from 'vitest';
import ProfileDialog from '../src/lib/components/ProfileDialog.svelte';
afterEach(cleanup);
const fieldLabels: Record<string, string> = {
username: 'Username',
email: 'Email',
password: 'New password',
confirmPassword: 'Confirm new password',
currentPassword: 'Current password',
totpToken: 'Current authenticator code',
};
const field = (name: string): HTMLInputElement => screen.getByLabelText(fieldLabels[name]) as HTMLInputElement;
async function fill(name: string, value: string): Promise<void> {
await fireEvent.input(field(name), { target: { value } });
}
async function submit(): Promise<void> {
const form = document.querySelector('form');
if (!form) throw new Error('no form');
await fireEvent.submit(form);
}
describe('ProfileDialog password changes', () => {
it('requires current password and a current TOTP code when enabled', async () => {
const onSave = vi.fn().mockResolvedValue(undefined);
render(ProfileDialog, { props: { open: true, onSave, totpEnabled: true } });
await fill('username', 'alice');
await fill('email', 'alice@example.com');
await fill('password', 'new-password');
await fill('confirmPassword', 'new-password');
await submit();
expect(onSave).not.toHaveBeenCalled();
expect(screen.getByText('Enter your current password to change your email or password.')).toBeTruthy();
await fill('currentPassword', 'old-password');
await submit();
expect(onSave).not.toHaveBeenCalled();
expect(screen.getByText('Enter a current authenticator code to change your email or password.')).toBeTruthy();
await fill('totpToken', '123456');
await submit();
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
expect(onSave).toHaveBeenCalledWith({
username: 'alice',
email: 'alice@example.com',
password: 'new-password',
currentPassword: 'old-password',
totpToken: '123456',
});
});
it('does not ask for password proof when only profile fields change', async () => {
const onSave = vi.fn().mockResolvedValue(undefined);
render(ProfileDialog, { props: { open: true, onSave, totpEnabled: true } });
await fill('username', 'alice');
await fill('email', 'alice@example.com');
await submit();
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
expect(onSave).toHaveBeenCalledWith({ username: 'alice', email: 'alice@example.com' });
expect(screen.queryByLabelText('Current password')).toBeNull();
});
});