Files
SGF/scripts/supplier-search-guard.php
T
2026-11-04 09:37:20 +02:00

7 lines
1.7 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/supplier-search-guard.json';if(!($s['supplierSearch']??false)||is_file($out))throw new LogicException('Isolated selector fixture required');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$queries=0;DB::listen(function()use(&$queries){$queries++;});$checks=[];
config(['receipt_qa.sourcing_enabled'=>false]);try{(new App\Modules\Purchasing\SourcingController)->suppliers(1,new Illuminate\Http\Request,new App\Modules\Purchasing\ReceiptRuntime);throw new RuntimeException('Disabled lookup accepted');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==404)throw $e;}$checks[]='disabled supplier lookup refuses before SQL';
config(['receipt_qa.sourcing_enabled'=>true]);$app->instance('env','production');try{(new App\Modules\Purchasing\SourcingController)->suppliers(1,new Illuminate\Http\Request,new App\Modules\Purchasing\ReceiptRuntime);throw new RuntimeException('Production accepted');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==403)throw $e;}$checks[]='production refuses synthetic selector before SQL';
if($queries!==0||App\Shared\Context\ModuleNavigation::owner('api/purchasing-sourcing/requests/1/suppliers')!=='purchasing')throw new RuntimeException('Guard boundary');$checks[]='lookup belongs to purchasing and guard probes issue zero SQL';file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." supplier lookup guards passed.\n";