Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

1 import assert from 'node:assert/strict';
2 import {spawn} from 'node:child_process';
3 const port=3132,base='http://127.0.0.1:'+port;
4 const env={...process.env,DATABASE_URL:'evidence-ref',IDENTITY_PROVIDER:'oidc-ref',
5 AUTH_PROXY_HMAC_SECRET:'synthetic-smoke-secret',KMS_KEY_ID:'kms-ref',
6 SIEM_ENDPOINT:'siem-ref',WAF_POLICY_ID:'waf-ref',ALERT_CHANNEL:'ops-ref',
7 BANK_ADAPTER_MODE:'disabled',TREASURYFLOW_DESKTOP_LOCAL:'0'};
8 const child=spawn(process.execPath,['node_modules/next/dist/bin/next','start','-p',String(port)],{env,stdio:'ignore'});
9 const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms));
10 try{
11 let ready=false;
12 for(let i=0;i<50;i++){
13 try{const r=await fetch(base+'/api/ready',{signal:AbortSignal.timeout(1800)});if(r.status===200){ready=true;break}}catch{}
14 await sleep(250);
15 }
16 assert(ready,'PRODUCTION_READY_TIMEOUT');
17 let count=0;
18 const forged=[
19 {'X-Authenticated-User':'system-admin','X-Forwarded-User':'admin'},
20 {'X-User-Role':'SUPERUSER','X-Tenant-Id':'local'},
21 {'Cookie':'session=forged; is_admin=true'},
22 {'X-Middleware-Subrequest':'middleware:middleware:middleware:middleware:middleware'}
23 ];
24 for(const path of ['/','/dashboard','/payments','/accounts','/reports/export',
25 '/audit','/queue','/api/transfer/submit','/integrations']){
26 for(const headers of forged){
27 const response=await fetch(base+path,{headers,redirect:'manual'});
28 assert.equal(response.status,403,'HEADER_BYPASS_'+path);
29 assert.equal(response.headers.get('cache-control'),'no-store');
30 assert.equal(response.headers.get('x-content-type-options'),'nosniff');
31 assert.match(await response.text(),/دسترسی عملیاتی مسدود است/);
32 count++;
33 }
34 }
35 for(const path of ['/payments/new','/api/transfer/submit','/accounts']){
36 const r=await fetch(base+path,{method:'POST',body:'amountIrr=100&role=admin',
37 headers:{'Content-Type':'application/x-www-form-urlencoded','X-Authenticated-User':'admin'}});
38 assert.equal(r.status,403,'POST_BYPASS_'+path);count++;
39 }
40 console.log('GATE_PASS_PRODUCTION_HTTP_SECURITY_'+count+'_SPOOF_AND_WRITE_ATTEMPTS_DENIED');
41 }catch(e){console.error('PRODUCTION_HTTP_SECURITY_FAIL_'+String(e.message).replace(/[^A-Za-z0-9_]/g,''));process.exitCode=1}
42 finally{child.kill();await sleep(300)}