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

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

Test integration endpoint security policy

davoodmehraban89 committed Sep 29, 2026 at 22:31 UTC be4c445e02d7792302e1831227dec0ef4bc94988
1 file changed +1
scripts/phase5-behavior-check.mjs
+1
@@ -10,6 +10,7 @@ D.validateMovement({kind:'transfer',productId:'P1',warehouseId:'W1',toWarehouseI
10 let rejected=false;try{D.validateMovement({kind:'transfer',productId:'P1',warehouseId:'W1',toWarehouseId:'W1',qty:1})}catch{rejected=true}if(!rejected)throw new Error('same-warehouse transfer accepted');
11 D.validateRestore({formatVersion:5,warehouses:[]},['warehouses']);rejected=false;try{D.validateRestore({evil:[]},['warehouses'])}catch{rejected=true}if(!rejected)throw new Error('unknown restore collection accepted');
12 const app=fs.readFileSync('js/phase5-enterprise.js','utf8');for(const x of ['p5PostMovement','p5SaveCount','p5RunDepreciation','p5SaveRate','p5SaveCostCenter','p5PreviewRestore','p5QueueEvent','status:\'posted\''])if(!app.includes(x))throw new Error('Phase5 application invariant missing '+x);
13 +const intCtx={URL};vm.createContext(intCtx);vm.runInContext(app,intCtx);if(vm.runInContext("p5ValidateIntegrationEndpoint('https://hooks.example.com/events')",intCtx)!=='https://hooks.example.com/events')throw new Error('valid HTTPS integration endpoint rejected');for(const bad of ['http://hooks.example.com','https://user:pass@hooks.example.com','https://localhost/hook','https://192.168.1.20/hook']){let blocked=false;try{intCtx.bad=bad;vm.runInContext("p5ValidateIntegrationEndpoint(bad)",intCtx)}catch{blocked=true}if(!blocked)throw new Error('unsafe integration endpoint accepted: '+bad)}
14 console.log('Phase 5 behavioral/domain scenarios passed.');
15 const syncSrc=fs.readFileSync('js/sync.js','utf8');const syncCtx={console,currentUser:{id:'u1'},COLLS:[],neutralize:x=>JSON.parse(JSON.stringify(x)),safeId:(id,p)=>String(id||p),window:{addEventListener:()=>{}},document:{getElementById:()=>null,addEventListener:()=>{},visibilityState:'visible'},setTimeout:()=>0,clearTimeout:()=>{},localStorage:{getItem:()=>null,setItem:()=>{}},confirm:()=>true,alert:()=>{},refreshAllSurfaces:()=>{},requireWrite:()=>true};vm.createContext(syncCtx);vm.runInContext(syncSrc,syncCtx);
16 vm.runInContext("datastore.products.push({id:'P1',ownerUserId:'u1',name:'Before'});datastore.journalVouchers.push({id:'JV1',ownerUserId:'u1',status:'posted'});datastore.journalLines.push({id:'JL1',ownerUserId:'u1',voucherId:'JV1',debit:100,credit:0});",syncCtx);