forked from unimatrix/web
14 lines
2.6 KiB
JavaScript
14 lines
2.6 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';
|
|
import {companyFixture} from './company-deed-fixture.mjs';import {createMasterKeyGeneratorAPI} from '../node/jarvis-master-generator-api.mjs';import {TEST_IDENTITY_PERMISSION} from '../node/account-test-identity.mjs';
|
|
test('key target suggestions use live eligible accounts, omit linked/service identities and reject scope overrides',async()=>{
|
|
const f=await companyFixture();try{
|
|
f.db.sqlite.exec('CREATE TABLE site_link_challenges(user_id TEXT PRIMARY KEY)');await f.db.query('DELETE FROM site_game_links WHERE user_id IN (?,?)',[f.people.Member.id,f.people.Other.id]);await f.db.query("UPDATE site_accounts SET role='system_account' WHERE id=?",[f.people.Other.id]);
|
|
const api=createMasterKeyGeneratorAPI(f.db,f.keys,{authenticate:async()=>f.people.Owner,authorize:async()=>true}),call=q=>api(new Request('https://cp.dunerealms.com/api/jarvis/generator/options?'+q));
|
|
const response=await call('actionId=accounts.test-minecraft-identity&q=Me'),data=await response.json();assert.equal(response.status,200);assert.equal(response.headers.get('Cache-Control'),'private, no-store');assert.deepEqual(data.targets,[{value:'Member',label:'Member · Member Character'}]);assert.equal(data.selectionGrantsAuthority,false);assert.deepEqual((await(await call('actionId=accounts.test-minecraft-identity&q=Ot')).json()).targets,[]);
|
|
await f.db.query('INSERT INTO site_link_challenges VALUES(?)',[f.people.Member.id]);assert.deepEqual((await(await call('actionId=accounts.test-minecraft-identity&q=Me')).json()).targets,[]);
|
|
for(const q of ['actionId=accounts.test-minecraft-identity&q=M','actionId=dev.issue&q=Me','actionId=accounts.test-minecraft-identity&q=Me&accountId=override'])assert.equal((await call(q)).status,400);
|
|
}finally{f.db.close();}
|
|
});
|
|
test('target suggestions require action authority and reject a changed session before returning account names',async()=>{
|
|
const f=await companyFixture();try{f.db.sqlite.exec('CREATE TABLE site_link_challenges(user_id TEXT PRIMARY KEY)');let calls=0;const url='https://cp.dunerealms.com/api/jarvis/generator/options?actionId=accounts.test-minecraft-identity&q=Me';const denied=createMasterKeyGeneratorAPI(f.db,f.keys,{authenticate:async()=>f.people.Owner,authorize:async(_user,node)=>node!==TEST_IDENTITY_PERMISSION});assert.equal((await denied(new Request(url))).status,403);const expired=createMasterKeyGeneratorAPI(f.db,f.keys,{authenticate:async()=>++calls===1?f.people.Owner:null,authorize:async()=>true});assert.equal((await expired(new Request(url))).status,403);}finally{f.db.close();}
|
|
});
|

Staff