This commit is contained in:
miles committed 2026-11-09 17:25:42 -06:00
1 parent c250653961
commit f26fdd9d07
18 files changed
+493 -83

No files matched your search

+34
View File
@@ -76,12 +76,29 @@ test('HTTP app exposes documented APIs, security headers, and CORS allowlist', a
});
assert.equal(preflight.status, 204);
assert.equal(preflight.headers.get('access-control-allow-origin'), 'https://milesallen.site');
assert.equal(preflight.headers.get('access-control-allow-credentials'), 'true');
const apiPreflight = await fetch(base + '/api/status', {
method: 'OPTIONS',
headers: {
Origin: 'https://api.milesallen.site',
'Access-Control-Request-Method': 'GET'
}
});
assert.equal(apiPreflight.status, 204);
assert.equal(apiPreflight.headers.get('access-control-allow-origin'), 'https://api.milesallen.site');
assert.equal(apiPreflight.headers.get('access-control-allow-credentials'), 'true');
assert.equal(apiPreflight.headers.get('access-control-expose-headers'), 'Retry-After');
const blocked = await fetch(base + '/api/status', {
headers: { Origin: 'https://evil.example' }
});
assert.equal(blocked.status, 403);
const siteConfig = await fetch(base + '/site-config.js');
assert.equal(siteConfig.status, 200);
assert.match(await siteConfig.text(), /api\.milesallen\.site/);
const missing = await fetch(base + '/api/nope');
assert.equal(missing.status, 404);
const missingBody = await missing.json();
@@ -108,6 +125,17 @@ test('Moon Vault content is server-gated and the old passphrase is gone from pub
const deniedGame = await fetch(base + '/games/dino.html', { redirect: 'manual' });
assert.equal(deniedGame.status, 302);
for (const encoded of [
'/games%2Fdino.html',
'/%67ames/dino.html',
'/games/%2564ino.html',
'/GAMES/dino.html',
'/Games/dino.html'
]) {
const bypass = await fetch(base + encoded, { redirect: 'manual' });
assert.equal(bypass.status, 302, `protected path must stay gated: ${encoded}`);
}
const badLogin = await fetch(base + '/api/vault/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -143,6 +171,12 @@ test('Moon Vault content is server-gated and the old passphrase is gone from pub
assert.equal(game.status, 200);
assert.equal(game.headers.get('cache-control'), 'no-store', 'protected games must not be cached');
const encodedGame = await fetch(base + '/games%2Fdino.html', {
headers: { Cookie: cookie },
redirect: 'manual'
});
assert.equal(encodedGame.status, 200, 'encoded protected paths work for authenticated sessions');
const logout = await fetch(base + '/api/vault/logout', {
method: 'POST',
headers: { Cookie: cookie }
+17
View File
@@ -45,6 +45,23 @@ test('config honors environment overrides without changing code', () => {
assert.equal(config.monitor.expectedSubnet, '192.168.1.0/24');
});
test('production split-origin config allows the API and main site origins', () => {
const config = loadConfig({
NODE_ENV: 'production',
SESSION_SECRET: secret,
VAULT_PASSWORD: 'a local passphrase',
PUBLIC_ORIGIN: 'https://api.milesallen.site',
ALLOWED_ORIGINS: 'https://milesallen.site,https://www.milesallen.site'
});
assert.equal(config.publicOrigin, 'https://api.milesallen.site');
assert.ok(config.allowedOrigins.has('https://milesallen.site'));
assert.ok(config.allowedOrigins.has('https://www.milesallen.site'));
assert.ok(config.allowedOrigins.has('https://api.milesallen.site'));
assert.equal(config.cookie.sameSite, 'Strict');
assert.equal(config.cookie.secure, true);
});
test('production refuses missing or short session secrets', () => {
assert.throws(
() => loadConfig({ NODE_ENV: 'production', VAULT_PASSWORD: 'a local passphrase' }),
+6 -1
View File
@@ -50,7 +50,12 @@ export function makeConfig(overrides = {}) {
dbPath: path.join(tempDir, 'dashboard.db'),
tempDir,
publicOrigin: 'http://localhost:8787',
allowedOrigins: new Set(['http://localhost:8787', 'https://milesallen.site']),
allowedOrigins: new Set([
'http://localhost:8787',
'https://milesallen.site',
'https://www.milesallen.site',
'https://api.milesallen.site'
]),
sessionSecret: 'test-session-secret-that-is-long-enough-0123456789',
trustProxy: false,
cookie: {