Files
TORCH/test/governance-security.test.mjs
T
google-labs-jules[bot]andPR0M3TH3AN 73a92da6c1 fix(security): verify governance command injection prevention and fix broken tests
- Add regression test `test/governance-security.test.mjs` to verify `applyProposal` is secure against command injection.
- Fix broken imports and duplicates in `src/lock-utils.mjs`, `src/lock-ops.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs` to resolve test failures.
- Verify all tests pass.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-20 21:56:12 +00:00

26 lines
1.2 KiB
JavaScript

import { test } from 'node:test';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import assert from 'node:assert';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const implPath = path.join(__dirname, 'governance-security-impl.mjs');
test('Governance Service Security: Command Injection Prevention', (t) => {
// We run the implementation in a separate process to ensure process.cwd() isolation
// and to verify that the dynamic import picks up the correct paths.
try {
const output = execFileSync(process.execPath, [implPath], { encoding: 'utf8' });
// If we reach here, the process exited with code 0 (success)
// We can optionally check the output for specific messages if needed,
// but the implementation script asserts internally.
assert.ok(output.includes('Verification passed: Commit message contains payload.'), 'Output should confirm verification passed');
} catch (err) {
console.error('Test implementation failed.');
if (err.stdout) console.error('STDOUT:', err.stdout);
if (err.stderr) console.error('STDERR:', err.stderr);
assert.fail(`Security test failed with exit code ${err.status}: ${err.message}`);
}
});