- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres (zonder configuratie ongewijzigd gedrag) - Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007) - Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability) met bijbehorende tests - Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina - CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED - Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
import { http, HttpResponse } from 'msw';
|
|
import type { SetupStatus } from '@/features/setup/services/types';
|
|
import { API_BASE } from '@/features/auth/mocks/fixtures';
|
|
|
|
/** Setup status mock (used by public bootstrap guards). */
|
|
export const setupHandlers = [
|
|
http.get(`${API_BASE}/api/v1/Setup/status`, () =>
|
|
HttpResponse.json<SetupStatus>({ initialized: true }),
|
|
),
|
|
|
|
http.post(`${API_BASE}/api/v1/Setup/owner`, async ({ request }) => {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const body = await request.json() as any;
|
|
if (!body.email || !body.password || !body.name) {
|
|
return HttpResponse.json(
|
|
{
|
|
type: 'about:blank',
|
|
title: 'Bad Request',
|
|
status: 400,
|
|
detail: 'Missing required fields'
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
return HttpResponse.json(
|
|
{
|
|
message: 'System initialized',
|
|
user: {
|
|
id: '1',
|
|
name: body.name,
|
|
email: body.email,
|
|
role: 'Owner'
|
|
}
|
|
},
|
|
{ status: 201 }
|
|
);
|
|
}),
|
|
];
|
|
|
|
/** Override: simulates network error on setup status — backend unreachable. */
|
|
export const setupNetworkErrorHandlers = [
|
|
http.get(`${API_BASE}/api/v1/Setup/status`, () => HttpResponse.error()),
|
|
];
|
|
|
|
/** Override: returns not-initialized status — use in tests for InitGuard. */
|
|
export const setupUninitializedHandlers = [
|
|
http.get(`${API_BASE}/api/v1/Setup/status`, () =>
|
|
HttpResponse.json<SetupStatus>({ initialized: false }),
|
|
),
|
|
];
|
|
|
|
/** Override: setup requires the token; only 'correct-token' is accepted (401 otherwise, like the host). */
|
|
export const setupTokenRequiredHandlers = [
|
|
http.get(`${API_BASE}/api/v1/Setup/status`, () =>
|
|
HttpResponse.json<SetupStatus>({ initialized: false, tokenRequired: true }),
|
|
),
|
|
http.post(`${API_BASE}/api/v1/Setup/owner`, ({ request }) => {
|
|
if (request.headers.get('X-Setup-Token') !== 'correct-token') {
|
|
return HttpResponse.json(
|
|
{ title: 'Setup token ontbreekt of is onjuist.', status: 401 },
|
|
{ status: 401 },
|
|
);
|
|
}
|
|
return HttpResponse.json({ message: 'System initialized' }, { status: 201 });
|
|
}),
|
|
];
|
|
|
|
/** Override: POST /Setup/owner returns 409 — system already initialized. */
|
|
export const setupConflictHandlers = [
|
|
...setupUninitializedHandlers,
|
|
http.post(`${API_BASE}/api/v1/Setup/owner`, () =>
|
|
HttpResponse.json(
|
|
{ title: 'Conflict', detail: 'System has already been initialized.', status: 409 },
|
|
{ status: 409 },
|
|
),
|
|
),
|
|
];
|