Pages now map to their html file, other forms get one redirect, unknown URLs get a real 404 and responses are compressed. A browser-free test suite runs the rules against a real nginx, in CI only so far. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
4.0 KiB
TypeScript
103 lines
4.0 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { monitoringFor } from '../src/monitoring/config';
|
|
import { securityHeaders } from './securityHeaders';
|
|
import {
|
|
iisWebConfig,
|
|
nginxProxyConf,
|
|
nginxTestConf,
|
|
productionHost,
|
|
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, '&')}" />`,
|
|
);
|
|
expect(nginx).toContain(`add_header ${name} "${value}" always;`);
|
|
}
|
|
});
|
|
|
|
it('IIS stuurt www in één stap door naar https://andreaslop.nl', () => {
|
|
const iis = iisWebConfig();
|
|
expect(iis).toContain(
|
|
'<add input="{HTTP_HOST}" pattern="^www\\.andreaslop\\.nl$" />',
|
|
);
|
|
expect(iis).toContain(
|
|
'<action type="Redirect" url="https://andreaslop.nl/{R:1}" redirectType="Permanent" />',
|
|
);
|
|
// Vóór de HTTPS-regel, anders eerst http://www → https://www
|
|
expect(iis.indexOf('name="www naar')).toBeLessThan(
|
|
iis.indexOf('name="HTTPS"'),
|
|
);
|
|
});
|
|
|
|
it('www-doorverwijzing verwijst naar de productiehost uit de monitoring', () => {
|
|
expect(monitoringFor(productionHost)?.environment).toBe('production');
|
|
});
|
|
|
|
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: /');
|
|
// Geen SPA-fallback (BR-HST-02) en geen mapdoorverwijzing (BR-HST-07)
|
|
expect(nginx).toContain('try_files $uri $uri.html =404;');
|
|
expect(nginx).not.toMatch(/try_files[^;]*\$uri[^;]*\/index\.html/);
|
|
expect(nginx).not.toContain('$uri/');
|
|
});
|
|
|
|
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 /m)
|
|
.slice(1);
|
|
// robots.txt, 404, 404.html, assets, de beginpagina en de rest
|
|
expect(blocks).toHaveLength(6);
|
|
for (const block of blocks) {
|
|
expect(block).toContain('Content-Security-Policy');
|
|
}
|
|
});
|
|
});
|