Fixes two nginx rule defects found by real nginx in CI
Plain map keys compare case-insensitively, so /Over-Mij was not redirected. A path starting with an encoded backslash could become an open redirect through the trailing-slash rule; it now gets the 404 page. Also makes the tests readable for nginx's workers and less sensitive to the slow CI runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -99,4 +99,30 @@ describe('serverconfiguratie', () => {
|
||||
expect(block).toContain('Content-Security-Policy');
|
||||
}
|
||||
});
|
||||
|
||||
it('de nginx-map kent geen tekstsleutels: die negeren hoofdletters', () => {
|
||||
// Een sleutel /over-mij zou ook /Over-Mij ongemoeid laten (echte nginx)
|
||||
const map = nginxTestConf().match(
|
||||
/map \$uri \$andreaslop_canonical \{([^}]*)\}/,
|
||||
)?.[1];
|
||||
const keys = (map ?? '')
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line && line !== 'default "";')
|
||||
.map((line) => line.split(' ')[0]);
|
||||
expect(keys.length).toBeGreaterThan(0);
|
||||
for (const key of keys) expect(key).toMatch(/^~\*?\^\//);
|
||||
// De hoofdlettergevoelige canonieke vormen staan vóór de varianten
|
||||
const lastCanonical = keys.findLastIndex((key) => key.startsWith('~^'));
|
||||
const firstVariant = keys.findIndex((key) => key.startsWith('~*'));
|
||||
expect(lastCanonical).toBeLessThan(firstVariant);
|
||||
});
|
||||
|
||||
it('een backslash vooraan in het pad geeft 404 voor de doorverwijzing', () => {
|
||||
const nginx = nginxTestConf();
|
||||
const guard = nginx.indexOf('if ($uri ~ "^/\\x5c") {');
|
||||
expect(guard).toBeGreaterThan(-1);
|
||||
expect(guard).toBeLessThan(nginx.indexOf('if ($andreaslop_canonical)'));
|
||||
expect(guard).toBeLessThan(nginx.indexOf('rewrite ^/(.+?)/+$'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user