Files
dwroller/tests/rules.test.js
alexpolo1 bf98d44a45 security: remove hardcoded database credentials and auth secrets
- Replace hardcoded DB_PASSWORD 'dwroller2025' with process.env.DB_PASSWORD
- Replace hardcoded GM_SECRET 'bongo' with process.env.GM_SECRET
- Replace hardcoded GM_PASSWORD with process.env.GM_PASSWORD
- Replace hardcoded PLAYER_PASSWORD '1234' with process.env.PLAYER_PASSWORD
- Update .env.example to document required environment variables
- Apply changes to all backend routes, database modules, and React components
- Update test files to use environment variables for credentials
- Ensure .env remains in .gitignore for production safety

This fix addresses critical security vulnerabilities where database
credentials and authentication secrets were exposed in source code.
2026-03-01 09:24:24 +01:00

44 lines
1.7 KiB
JavaScript

jest.setTimeout(20000);
const { execSync } = require('child_process');
const path = require('path');
describe('Rules endpoints', () => {
const baseURL = process.env.API_BASE || 'http://localhost:5000';
const gmHeaders = `-H "x-gm-secret: ${process.env.GM_SECRET || 'defaultsecret'}"`;
const curl = (method, url, data = null, headers = '') => {
const command = `curl -s -X ${method} ${headers} -H "Content-Type: application/json" ${data ? `-d '${JSON.stringify(data)}'` : ''} ${url}`;
try {
const result = execSync(command, { encoding: 'utf-8' });
return JSON.parse(result || '{}');
} catch (error) {
if (error.stdout) {
try { return JSON.parse(error.stdout); } catch (e) { /* ignore */ }
}
throw error;
}
};
test('categories, search, random and stats endpoints respond', () => {
const cats = curl('GET', `${baseURL}/api/rules/categories`);
expect(Array.isArray(cats)).toBe(true);
const search = curl('GET', `${baseURL}/api/rules/search?q=test`);
expect(Array.isArray(search)).toBe(true);
const randomRes = curl('GET', `${baseURL}/api/rules/random`);
expect(Array.isArray(randomRes)).toBe(true);
const stats = curl('GET', `${baseURL}/api/rules/stats`);
expect(stats && typeof stats.totalRules === 'number').toBe(true);
// Try reload without proper GM secret should fail
const reloadFail = curl('POST', `${baseURL}/api/rules/reload`);
expect(reloadFail && reloadFail.error).toBeTruthy();
// Reload with GM secret
const reloadOk = curl('POST', `${baseURL}/api/rules/reload`, null, gmHeaders);
expect(reloadOk && typeof reloadOk.success === 'boolean').toBe(true);
});
});