web/website/tests/bank-upstream-permissions.test.mjs
Dev 6deb4a2e7d DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
2026-11-13 00:05:14 +01:00

7 lines
1,004 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {createBanking} from '../control-panel/banking.mjs';
const uuid='12345678-1234-1234-1234-123456789abc';
const make=(status,path='/api/bank/personal')=>createBanking({}, {SERVER_CONTROL_TOKEN:'x'.repeat(64)}, {authenticate:async()=>({id:'1',username:'owner'}),access:async()=>({nodes:['web.bank.personal.view','web.bank.staff.view','web.menu.game']}),linked:async()=>uuid,fetcher:async()=>new Response(null,{status})})(new Request('https://cp.dunerealms.com'+path));
for(const status of [401,403])for(const path of ['/api/bank/personal','/api/bank/staff','/api/bank/faction'])test('upstream '+status+' on '+path+' is reported as denied',async()=>{const response=await make(status,path);assert.equal(response.status,403);assert.match((await response.json()).message,/game bank rejected/i);});
test('upstream 500 remains a temporary service failure',async()=>{const response=await make(500);assert.equal(response.status,503);});