mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-06 00:26:33 +00:00
Add comprehensive test suite for application functionality
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers. - Create configuration tests to validate loading of defaults and environment overrides. - Add tests for FEDL service to verify data handling and snapshot functionality. - Introduce GitHub service tests to check API data normalization and caching behavior. - Develop monitor service tests for network checks and uptime calculations. - Implement persistence tests to ensure database migrations are idempotent and data persists across restarts. - Add vault service tests for session management and brute-force protection mechanisms. - Include helper functions for test context creation and JSON response handling.
This commit is contained in:
1 parent
84b7a7e302
commit
c250653961
55 files changed
+8174
-226
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadConfig } from '../server/config.js';
|
||||
|
||||
const secret = 'a'.repeat(48);
|
||||
|
||||
test('config loads local defaults and project registry', () => {
|
||||
const config = loadConfig({
|
||||
NODE_ENV: 'development',
|
||||
SESSION_SECRET: secret,
|
||||
VAULT_PASSWORD: 'a local passphrase'
|
||||
});
|
||||
|
||||
assert.equal(config.port, 8787);
|
||||
assert.equal(config.host, '127.0.0.1');
|
||||
assert.equal(config.production, false);
|
||||
assert.ok(config.allowedOrigins.has('http://localhost:8787'));
|
||||
assert.ok(config.allowedOrigins.has('https://milesallen.site'));
|
||||
assert.ok(config.projects.length > 5);
|
||||
assert.equal(config.projects.find((p) => p.id === 'fedl').featured, true);
|
||||
assert.equal(config.services.length, 5);
|
||||
assert.equal(config.servers[0].ip, '10.0.0.87');
|
||||
});
|
||||
|
||||
test('config honors environment overrides without changing code', () => {
|
||||
const config = loadConfig({
|
||||
NODE_ENV: 'development',
|
||||
SESSION_SECRET: secret,
|
||||
VAULT_PASSWORD: 'a local passphrase',
|
||||
PORT: '9001',
|
||||
HOST: '0.0.0.0',
|
||||
SERVER_1_NAME: 'Rack One',
|
||||
SERVER_1_IP: '192.168.1.50',
|
||||
SERVICE_FEDL_URL: 'https://fedl.example.test/',
|
||||
SERVICE_FEDL_ENABLED: 'false',
|
||||
HOME_SUBNET: '192.168.1.0/24'
|
||||
});
|
||||
|
||||
assert.equal(config.port, 9001);
|
||||
assert.equal(config.host, '0.0.0.0');
|
||||
assert.equal(config.servers[0].name, 'Rack One');
|
||||
assert.equal(config.servers[0].ip, '192.168.1.50');
|
||||
assert.equal(config.services.find((s) => s.id === 'fedl').url, 'https://fedl.example.test/');
|
||||
assert.equal(config.services.find((s) => s.id === 'fedl').enabled, false);
|
||||
assert.equal(config.monitor.expectedSubnet, '192.168.1.0/24');
|
||||
});
|
||||
|
||||
test('production refuses missing or short session secrets', () => {
|
||||
assert.throws(
|
||||
() => loadConfig({ NODE_ENV: 'production', VAULT_PASSWORD: 'a local passphrase' }),
|
||||
/SESSION_SECRET is required/
|
||||
);
|
||||
assert.throws(
|
||||
() => loadConfig({ NODE_ENV: 'production', SESSION_SECRET: 'short', VAULT_PASSWORD: 'a local passphrase' }),
|
||||
/at least 32 characters/
|
||||
);
|
||||
});
|
||||
|
||||
test('invalid origins and service URLs are rejected at startup', () => {
|
||||
assert.throws(
|
||||
() => loadConfig({
|
||||
NODE_ENV: 'development',
|
||||
SESSION_SECRET: secret,
|
||||
VAULT_PASSWORD: 'x',
|
||||
ALLOWED_ORIGINS: 'not a url'
|
||||
}),
|
||||
/Invalid origin/
|
||||
);
|
||||
assert.throws(
|
||||
() => loadConfig({
|
||||
NODE_ENV: 'development',
|
||||
SESSION_SECRET: secret,
|
||||
VAULT_PASSWORD: 'x',
|
||||
SERVICE_FEDL_URL: 'javascript:alert(1)'
|
||||
}),
|
||||
/Invalid URL/
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user