import test from 'brittle' import { parseBareOsHrpcAllowlistJson, bareOsHrpcAllowlistDeniesRoute } from './lib/bare-os-hrpc-allowlist.js' test('parseBareOsHrpcAllowlistJson array and object forms', (t) => { const a = parseBareOsHrpcAllowlistJson('["kernel.ping","vfs.readText"]') t.ok(a.allow) t.ok(a.allow.has('kernel.ping')) t.ok(a.allow.has('vfs.readText')) t.absent(a.parseError) const o = parseBareOsHrpcAllowlistJson( JSON.stringify({ 'kernel.*': true, 'x.y': false }) ) t.ok(o.allow) t.ok(o.allow.has('kernel.*')) t.absent(o.allow.has('x.y')) }) test('parseBareOsHrpcAllowlistJson malformed JSON', (t) => { const r = parseBareOsHrpcAllowlistJson('{') t.ok(r.parseError) t.absent(r.allow) }) test('bareOsHrpcAllowlistDeniesRoute wildcard edges', (t) => { const s = new Set(['*']) t.absent(bareOsHrpcAllowlistDeniesRoute(s, 'any', 'method')) const k = new Set(['kernel.*']) t.absent(bareOsHrpcAllowlistDeniesRoute(k, 'kernel', 'ping')) t.ok(bareOsHrpcAllowlistDeniesRoute(k, 'vfs', 'readText')) const exact = new Set(['vfs.readText']) t.absent(bareOsHrpcAllowlistDeniesRoute(exact, 'vfs', 'readText')) t.ok(bareOsHrpcAllowlistDeniesRoute(exact, 'vfs', 'other')) })