refactor tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
|
||||
async function nginxConfig() {
|
||||
return fs.readFile(path.join(root, 'nginx/wegwichtel.conf'), 'utf8');
|
||||
}
|
||||
|
||||
function activeLines(config) {
|
||||
return config
|
||||
.split(/\r?\n/)
|
||||
.map(line => line.trim())
|
||||
.filter(line => line && !line.startsWith('#'));
|
||||
}
|
||||
|
||||
test('nginx listens actively on HTTP while SSL remains a commented template', async () => {
|
||||
const config = await nginxConfig();
|
||||
|
||||
assert.match(config, /listen 80;\s*\n\s*listen \[::\]:80;\s*\n\s*# listen 443 ssl;\s*\n\s*# listen \[::\]:443 ssl;/);
|
||||
assert.match(config, /server_name wegwichtel\.de www\.wegwichtel\.de;[\s\S]*# ssl_certificate\s+\/etc\/nginx\/ssl\/snakeoil\.pem;/);
|
||||
assert.match(config, /# ssl_certificate_key\s+\/etc\/nginx\/ssl\/snakeoil\.key;/);
|
||||
assert.match(config, /# ssl_protocols TLSv1\.2 TLSv1\.3;/);
|
||||
|
||||
const active = activeLines(config).join('\n');
|
||||
assert.doesNotMatch(active, /listen (?:\[::\]:)?443\b/);
|
||||
assert.doesNotMatch(active, /^ssl_/m);
|
||||
assert.doesNotMatch(active, /https:\/\//);
|
||||
});
|
||||
|
||||
test('nginx keeps reverse-proxy, upload and forwarding settings in the HTTP server block', async () => {
|
||||
const config = await nginxConfig();
|
||||
|
||||
assert.match(config, /proxy_pass\s+http:\/\/127\.0\.0\.1:47145;/);
|
||||
assert.match(config, /client_max_body_size\s+64m;/);
|
||||
assert.match(config, /proxy_request_buffering\s+off;/);
|
||||
assert.match(config, /proxy_set_header\s+Host\s+\$host;/);
|
||||
assert.match(config, /proxy_set_header\s+X-Real-IP\s+\$remote_addr;/);
|
||||
assert.match(config, /proxy_set_header\s+X-Forwarded-For\s+\$proxy_add_x_forwarded_for;/);
|
||||
assert.match(config, /proxy_set_header\s+X-Forwarded-Proto\s+\$scheme;/);
|
||||
assert.match(config, /proxy_connect_timeout\s+10s;/);
|
||||
assert.match(config, /proxy_send_timeout\s+120s;/);
|
||||
assert.match(config, /proxy_read_timeout\s+120s;/);
|
||||
});
|
||||
Reference in New Issue
Block a user