@davoodmehraban89 / Factor-easy / commits / b37ec40
Fork 0

سامانه صدور فاکتور و حسابداری

test: require explicit authorization denials in WP3

davoodmehraban89 committed Nov 17, 2026 at 13:06 UTC b37ec408290aeb07fa20e1b362ec87cb524e4a2f
1 file changed +2 -5
scripts/wp3-financial-tenant-e2e.mjs
+2 -5
@@ -19,16 +19,13 @@ async function rpc(name,args,t){
19 const r=await rest(`rpc/${name}`,t,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(args)});
20 const body=await r.text();return {status:r.status,body};
21 }
22 -function sql(s){
23 - const {spawnSync}=globalThis.__unused||{};
24 -}
22 const {spawnSync}=await import('node:child_process');
23 function psql(statement){
24 const r=spawnSync('psql',[db,'-v','ON_ERROR_STOP=1','-c',statement],{encoding:'utf8'});
25 if(r.status!==0)throw new Error(`psql failed: ${r.stderr||r.stdout}`);
26 }
27 const expectDenied=({status,body},label)=>{
31 - assert.ok(status===401||status===403||status===400, `${label}: expected server denial, got HTTP ${status}: ${body}`);
28 + assert.ok(status===401||status===403, `${label}: expected explicit authentication/authorization denial (401/403), got HTTP ${status}: ${body}`);
29 };
30 try{
31 const emailA=`wp3-a-${suffix}@example.test`,emailB=`wp3-b-${suffix}@example.test`;
@@ -57,7 +54,7 @@ try{
54 const foreign=await rest(`records?select=id,organization_id,data&collection=eq.journalVouchers&id=eq.${encodeURIComponent(voucherId)}`,jwtB);
55 assert.equal(foreign.status,200);assert.equal((await foreign.json()).length,0,'tenant B read another tenant journal voucher');
56 const insertForeign=await rest('records?select=id',jwtB,{method:'POST',headers:{'Content-Type':'application/json',Prefer:'return=representation'},body:JSON.stringify({organization_id:orgA,owner_id:userB,collection:'journalVouchers',id:`wp3-injected-${suffix}`,data})});
60 - assert.ok(insertForeign.status===401||insertForeign.status===403||insertForeign.status===400, `cross-tenant insert unexpectedly accepted: ${insertForeign.status} ${await insertForeign.text()}`);
57 + assert.ok(insertForeign.status===401||insertForeign.status===403, `cross-tenant insert must be explicitly denied (401/403), got ${insertForeign.status}: ${await insertForeign.text()}`);
58 const updateForeign=await rest(`records?organization_id=eq.${orgA}&collection=eq.journalVouchers&id=eq.${encodeURIComponent(voucherId)}`,jwtB,{method:'PATCH',headers:{'Content-Type':'application/json',Prefer:'return=representation'},body:JSON.stringify({data:{...data,description:'tampered by tenant B'}})});
59 assert.ok(updateForeign.status===200||updateForeign.status===204, `unexpected cross-tenant update status ${updateForeign.status}`);
60 assert.equal((await updateForeign.json().catch(()=>[])).length,0,'cross-tenant update returned modified rows');