MC/website/tests/pillager-war-access.test.mjs

17 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {raidWarAccessPlan,RAID_WAR_TABLES} from '../ops/pillager-war-access.mjs';
test('existing application service receives only named original-war SELECT/INSERT/UPDATE, never ledger/admin/player permissions',()=>{
const input={bankSchema:'synthetic_bank',centralIdentity:'synthetic_service@localhost'},plan=raidWarAccessPlan(input);
assert.equal(plan.length,9);assert.equal(new Set(plan).size,9);assert.deepEqual(raidWarAccessPlan(input),plan);
for(let i=0;i<plan.length;i++)assert.equal(plan[i],`GRANT SELECT,INSERT,UPDATE ON \`synthetic_bank\`.\`${RAID_WAR_TABLES[i]}\` TO 'synthetic_service'@'localhost'`);
assert.doesNotMatch(plan.join('\n'),/\*|GRANT OPTION|DELETE|CREATE|ALTER|DROP|pb_accounts|pb_entries|site_accounts|organisation_keys/);
for(const bad of [{bankSchema:'bank;DROP'},{centralIdentity:"app'@localhost"},{centralIdentity:'root@localhost'},{centralIdentity:'app@localhost@elsewhere'},{centralIdentity:'mysql.session@localhost'}])assert.throws(()=>raidWarAccessPlan({...input,...bad}));
});
test('built setup requires immutable source, same server/current identity and backups before grants; readiness cannot write',()=>{
const source=readFileSync(new URL('../ops/pillager-war-access.mjs',import.meta.url),'utf8');
assert.ok(source.indexOf("'grants.before.sql'")<source.indexOf('for(const sql of plan)'));
assert.match(source,/releases\/ci-/);assert.match(source,/same transaction server/);assert.match(source,/No financial transaction allowed during setup/);
assert.match(source,/mode:0o600,flag:'wx'/);assert.match(source,/information_schema.TABLES/);assert.doesNotMatch(source,/password.*--execute|--password/);
});