Files
AndreaSlopFotografie/web/config/serverConfig.test.ts
T
SluijsensandClaude Opus 5.5 a8903c9641
Continuous Integration / check (pull_request) Failing after 6m13s
Continuous Integration / lighthouse (pull_request) Skipped
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Fixes CI test timeouts on the arm64 runner
The first render with axe takes up to 7 s on the Raspberry Pi runner,
above Vitest's 5 s default; the suite now allows 20 s per test. Also
silences the router warning in the test that crashes a page on purpose,
and makes the nginx test config return 404 instead of a redirect loop
(500) while the test folder is still empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 00:33:41 +02:00

77 lines
2.9 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
import { securityHeaders } from './securityHeaders';
import {
iisWebConfig,
nginxProxyConf,
nginxTestConf,
serverConfigFiles,
} from './serverConfig';
describe('serverconfiguratie', () => {
it.each(Object.entries(serverConfigFiles))(
'%s is gelijk aan de generator (draai anders pnpm server-config)',
(path, generate) => {
expect(readFileSync(path, 'utf8')).toBe(generate());
},
);
it('IIS en nginx zetten elke productieheader', () => {
const iis = iisWebConfig();
const nginx = nginxTestConf();
for (const [name, value] of Object.entries(
securityHeaders('production'),
)) {
expect(iis).toContain(
`<add name="${name}" value="${value.replace(/&/g, '&amp;')}" />`,
);
expect(nginx).toContain(`add_header ${name} "${value}" always;`);
}
});
it('IIS heeft een SPA-fallback en een HTTPS-redirect', () => {
const iis = iisWebConfig();
expect(iis).toContain('<action type="Rewrite" url="/index.html" />');
expect(iis).toContain('<add input="{HTTPS}" pattern="^OFF$" />');
});
it('de testsite wordt nooit geindexeerd', () => {
const nginx = nginxTestConf();
expect(nginx).toContain('X-Robots-Tag "noindex, nofollow"');
expect(nginx).toContain('Disallow: /');
expect(nginx).toContain('try_files $uri $uri/ /index.html =404;');
});
it('het testblok claimt nooit de standaardserver (WordPress op dezelfde Pi)', () => {
expect(nginxTestConf()).not.toMatch(/listen[^;]*default_server/);
});
it('houdt doorverwijzingen relatief achter de reverse proxy', () => {
expect(nginxTestConf()).toContain('absolute_redirect off;');
});
it('de proxy geeft de Host-header door en zet zelf geen security headers', () => {
const proxy = nginxProxyConf();
expect(proxy).toContain('proxy_set_header Host $host;');
expect(proxy).toContain('server_name test.andreaslop.nl;');
expect(proxy).not.toContain('add_header');
});
it('proxy en testblok gebruiken dezelfde hostname', () => {
// Alleen echte config-regels, geen commentaar
const name = /^\s*server_name ([^;]+);/m;
const proxyHost = nginxProxyConf().match(name)?.[1];
expect(proxyHost).toBe('test.andreaslop.nl');
expect(nginxTestConf().match(name)?.[1]).toBe(proxyHost);
});
it('elk nginx location-blok herhaalt de security headers', () => {
// nginx erft add_header niet als een location er zelf een zet
const blocks = nginxTestConf().split('location ').slice(1);
expect(blocks).toHaveLength(3);
for (const block of blocks) {
expect(block).toContain('Content-Security-Policy');
}
});
});