Files
Investidor-V2/outputs/investmoz-documentos-publicos-QA-20261018/check-private-QA.php
T
nala cf003c8623
tests / ci (push) Canceled after 0s
versao nrgocios 4
2026-10-18 15:57:06 +02:00

19 lines
2.1 KiB
PHP

<?php
require __DIR__.'/boot-QA.php';
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
if($target!==['database'=>'public_documents_20261018_test','port'=>55441])throw new RuntimeException('QA only');
$kernel=$app->make(Illuminate\Contracts\Http\Kernel::class);$resource=DB::table('portal_resources')->where('id',2)->first();$checks=[];
foreach(['unpublished','private','unscanned','restricted']as$case){
DB::beginTransaction();
try{
if($case==='unpublished')DB::table('portal_resources')->where('id',2)->update(['published'=>false]);
if($case==='private')DB::table('documents')->where('id',$resource->document_id)->update(['data_classification'=>'internal']);
if($case==='unscanned')DB::table('documents')->where('id',$resource->document_id)->update(['malware_scan_status'=>'pending']);
if($case==='restricted')DB::table('documents')->where('id',$resource->document_id)->update(['rights_status'=>'restricted']);
foreach(['/documentos/2','/documentos/2/view','/documentos/2/download']as$path){$request=Request::create('http://127.0.0.1:18546'.$path,'GET');$response=$kernel->handle($request);$checks[]=['case'=>$case,'path'=>$path,'status'=>$response->getStatusCode(),'result'=>$response->getStatusCode()===404?'observado':'falhou'];if($response->getStatusCode()!==404)throw new RuntimeException('Visibility guard failed');}
$request=Request::create('http://127.0.0.1:18546/api/v1/documents/recommendations','GET',[],[],[],['HTTP_ACCEPT'=>'application/json']);$response=$kernel->handle($request);$body=json_decode($response->getContent(),true,512,JSON_THROW_ON_ERROR);if(in_array(2,array_column($body['data'],'id'),true))throw new RuntimeException('Private recommendation leak');$checks[]=['case'=>$case,'path'=>'/api/v1/documents/recommendations','resource_2_absent'=>true,'result'=>'observado'];
}finally{DB::rollBack();}
}
file_put_contents(__DIR__.'/PROVAS-ACESSO-PRIVADO-QA.json',json_encode(['target'=>$target,'fixtures'=>'temporary visibility changes rolled back after each case; no permanent document mutation','checks'=>$checks,'active_changes'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode(['checks'=>count($checks),'failed'=>0]).PHP_EOL;