Setup-pagina verschijnt niet meer als de setup-status niet te lezen is

De route-guard las elke fout (429, 500, 503, 404) als 'niet geinitialiseerd' en stuurde naar de
setup-pagina. Nu geen gok: bij een onleesbare status geen doorverwijzing. De statuslezing valt onder de
ruimere limiter in plaats van de strikte login-limiter (die 5 per minuut deelt met echte inlogpogingen).
De loginpagina meldt als het CMS uitgeschakeld of in onderhoud is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 08:53:37 +01:00
co-authored by Claude Sonnet 5.5
parent 701091f179
commit ff94719455
9 changed files with 188 additions and 4 deletions
@@ -11,6 +11,7 @@ import { useAuth } from '@/features/auth/context/auth-context';
import { NetworkError, ProblemDetailsError } from '@/lib/api-client';
import { loginFormSchema, type LoginFormData } from '@/features/auth/schemas/auth';
import { useSystemCapabilities } from '@/features/system/services/useSystemCapabilities';
import { useAvailabilityStatus } from '@/features/availability/services/useAvailability';
import { Link } from '@tanstack/react-router';
export function LoginPage() {
@@ -20,6 +21,8 @@ export function LoginPage() {
const search = useSearch({ strict: false }) as { redirect?: string };
const [serverError, setServerError] = useState<string | null>(null);
const { data: capabilities } = useSystemCapabilities();
const { data: availability } = useAvailabilityStatus();
const cmsOff = availability !== undefined && availability.status !== 'Available';
const {
register,
@@ -55,6 +58,19 @@ export function LoginPage() {
<CardDescription>{t('login.subtitle')}</CardDescription>
</CardHeader>
<CardContent>
{cmsOff && (
<div
role="status"
data-testid="login-cms-off"
className="mb-4 rounded-md border border-amber-400/50 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:bg-amber-950 dark:text-amber-200"
>
<p className="font-medium">
{availability.status === 'Maintenance' ? t('login.cmsMaintenance') : t('login.cmsDisabled')}
</p>
{availability.message ? <p>{availability.message}</p> : null}
<p>{t('login.cmsOffAdminsOnly')}</p>
</div>
)}
<form onSubmit={onSubmit} noValidate className="space-y-4">
{serverError !== null && (
<div
@@ -0,0 +1,88 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import { http, HttpResponse } from 'msw';
import { renderApp, mockGuest } from '@/test/utils';
import { server } from '@/mocks/server';
import { API_BASE } from '@/features/auth/mocks/fixtures';
import { _resetSetupStatusCache } from '@/router';
beforeEach(() => {
_resetSetupStatusCache();
});
const STATUS = `${API_BASE}/api/v1/Setup/status`;
const AVAILABILITY = `${API_BASE}/api/v1/Availability/status`;
describe('a setup status that cannot be read never sends anybody to the setup page', () => {
it.each([
['429 (rate limited)', () => HttpResponse.json({ status: 429, title: 'Too Many Requests' }, { status: 429 })],
['500', () => HttpResponse.json({ status: 500 }, { status: 500 })],
['503 (service unavailable)', () => HttpResponse.json({ status: 503, title: 'Service Unavailable' }, { status: 503 })],
['404', () => new HttpResponse(null, { status: 404 })],
['an empty 200', () => new HttpResponse(null, { status: 200 })],
['a network failure', () => HttpResponse.error()],
])('%s: the login page is shown, not the setup page', async (_label, respond) => {
mockGuest();
server.use(http.get(STATUS, respond));
renderApp('/dashboard');
expect(await screen.findByTestId('login-form-submit-button', {}, { timeout: 10000 })).toBeInTheDocument();
expect(screen.queryByTestId('setup-form')).not.toBeInTheDocument();
});
it('an unreadable status does not move a visitor who is already on the setup page either', async () => {
mockGuest();
server.use(http.get(STATUS, () => HttpResponse.json({ status: 503 }, { status: 503 })));
renderApp('/setup');
// Nothing can be said about the system, so the router leaves the page where it is.
expect(await screen.findByTestId('setup-form', {}, { timeout: 10000 })).toBeInTheDocument();
});
it('a readable "not initialized" still leads to the setup page (the real first-run case)', async () => {
mockGuest();
server.use(http.get(STATUS, () => HttpResponse.json({ initialized: false })));
renderApp('/dashboard');
expect(await screen.findByTestId('setup-form', {}, { timeout: 10000 })).toBeInTheDocument();
});
});
describe('the login page of a CMS that is switched off', () => {
function availability(status: 'Available' | 'Maintenance' | 'NotAvailable', message = '') {
server.use(
http.get(AVAILABILITY, () =>
HttpResponse.json({ status, checkedAt: '2026-11-09T00:00:00Z', message, isMasterControlled: false }),
),
);
}
it('says so, with the message, and still offers the login form (administrators pass)', async () => {
mockGuest();
availability('NotAvailable', 'Uitgeschakeld door de master');
renderApp('/login');
const notice = await screen.findByTestId('login-cms-off', {}, { timeout: 10000 });
expect(notice).toHaveTextContent(/disabled/i);
expect(notice).toHaveTextContent('Uitgeschakeld door de master');
expect(notice).toHaveTextContent(/only administrators/i);
expect(screen.getByTestId('login-form-submit-button')).toBeInTheDocument();
});
it('names maintenance as maintenance', async () => {
mockGuest();
availability('Maintenance');
renderApp('/login');
expect(await screen.findByTestId('login-cms-off', {}, { timeout: 10000 })).toHaveTextContent(/maintenance/i);
});
it('shows nothing extra while the CMS is available', async () => {
mockGuest();
availability('Available');
renderApp('/login');
await screen.findByTestId('login-form-submit-button', {}, { timeout: 10000 });
expect(screen.queryByTestId('login-cms-off')).not.toBeInTheDocument();
});
});