MC/website/tests/jarvis-master-boundary.test.mjs
2026-11-27 23:43:05 +00:00

18 lines
1.7 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {assertWebIssuableMaster} from '../node/jarvis-web-key-boundary.mjs';
import {createMasterKeyGenerator} from '../node/jarvis-master-generator.mjs';
import {KEY_TYPES} from '../node/organisation-key-policy.mjs';
import {MASTER_KEY_TEMPLATES} from '../control-panel/public/jarvis-master-keys.mjs';
test('website never issues developer keys, regardless of rank or permission',async()=>{
for(const keyType of ['dev','DEV-BATCH','developer-batch','root','sudo','dev.key'])assert.throws(()=>assertWebIssuableMaster({id:'any',keyType}),/Devkeys/);
for(const property of [{devOnly:true},{serverOnly:true},{family:'developer'}])assert.throws(()=>assertWebIssuableMaster({id:'any',keyType:'clan-administration',...property}),/Devkeys/);
let called=false;const service=createMasterKeyGenerator({}, {issue(){called=true;}},{authorize:async()=>true});
for(const actionId of ['dev-batch','developer.issue','root.issue','sudo.issue'])await assert.rejects(service.issue({id:'owner',role:'owners'},{actionId,templateVersion:1,values:{},requestId:'00000000-0000-4000-8000-000000000001'}),/Devkeys/);
assert.equal(called,false);assert.equal(Object.keys(KEY_TYPES).some(t=>/dev/i.test(t)),false);
});
test('every central key type has a master definition and no master introduces a dev key',()=>{
const actions=MASTER_KEY_TEMPLATES.flatMap(t=>t.actions),known=new Set(actions.map(a=>a.keyType));
for(const type of Object.keys(KEY_TYPES))assert.ok(known.has(type),'Missing masterkey: '+type);
for(const a of actions){assertWebIssuableMaster(a);assert.ok(KEY_TYPES[a.keyType]);}
assert.equal(new Set(actions.map(a=>a.id)).size,actions.length);
});