Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B7-business-policy-QA.php
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

25 lines
3.6 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');
$b7Root=dirname(__DIR__,2);$b7QA=$b7Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';$app=require$b7QA.'/tools/portal-stability-runtime.php';$db=Illuminate\Support\Facades\DB::connection();
$t=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');if($t!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441])throw new RuntimeException('QA only');
$state=json_decode(file_get_contents(__DIR__.'/option-B7-business-progress.json'),true);$business=App\Models\ExistingBusiness::findOrFail($state['id']);$policy=app(App\Policies\ExistingBusinessPolicy::class);$u=App\Models\User::findOrFail(24);
$proof=['at'=>gmdate('c'),'target'=>$t,'kind'=>'direct policy/SQL with rolled-back QA grant mutations; not HTTP or browser','active_writes'=>0,'persisted_role_changes'=>0,'cases'=>[]];
session(['portal.mfa_actor'=>24,'portal.mfa_at'=>time()]);if(!$policy->view($u,$business))throw new RuntimeException('Global validator baseline');
$rows=$db->table('portal_role_assignments')->orderBy('id')->get();$before=hash('sha256',json_encode($rows,JSON_THROW_ON_ERROR));
foreach(['wrong_type','organization_without_explicit_listing_link','revoked','expired']as$case){
$db->beginTransaction();
try{
$q=$db->table('portal_role_assignments')->where('user_id',24)->where('role','validator');
match($case){'wrong_type'=>$q->update(['opportunity_types'=>json_encode(['investment_project'])]),'organization_without_explicit_listing_link'=>$q->update(['organization_id'=>'99964753-2632-4658-a687-8ebc6a178296']),'revoked'=>$q->update(['revoked_at'=>now()]),'expired'=>$q->update(['expires_at'=>now()->subSecond()])};
config(['existing-business.reviewers'=>[strtolower($u->email)],'existing-business.approvers_l1'=>[strtolower($u->email)],'existing-business.publishers'=>[strtolower($u->email)]]);
$queue=App\Models\ExistingBusiness::query()->whereKey($business->id);$policy->scopeReviewQueue($queue,$u);
if($policy->view($u,$business)||$policy->reviewQueue($u)||$queue->exists())throw new RuntimeException('Scope bypass: '.$case);
$proof['cases'][]=['case'=>$case,'private_view_denied'=>true,'queue_denied'=>true,'legacy_email_did_not_restore_privilege'=>true,'mutations_rolled_back'=>true];
}finally{$db->rollBack();}
}
config(['existing-business.reviewers'=>[],'existing-business.approvers_l1'=>[],'existing-business.publishers'=>[]]);
$after=hash('sha256',json_encode($db->table('portal_role_assignments')->orderBy('id')->get(),JSON_THROW_ON_ERROR));if(!hash_equals($before,$after))throw new RuntimeException('QA grants not preserved');
session(['portal.mfa_actor'=>null,'portal.mfa_at'=>0]);if($policy->view($u,$business)||$policy->reviewQueue($u))throw new RuntimeException('MFA missing bypass');$proof['cases'][]=['case'=>'enrollment_without_completed_session_MFA','private_view_denied'=>true];
foreach([26,27,31]as$id){$actor=App\Models\User::findOrFail($id);session(['portal.mfa_actor'=>$id,'portal.mfa_at'=>time()]);if($policy->view($actor,$business)||$policy->reviewQueue($actor))throw new RuntimeException('Administrative/multiple role bypass');$proof['cases'][]=['case'=>'administrative_or_auditor_accumulation','actor_id'=>$id,'private_view_denied'=>true,'queue_denied'=>true];}
$proof['grants_sha256_preserved']=$before;$proof['result']='passed';$dest=__DIR__.'/option-B7-business-policy-QA.json';if(is_file($dest))throw new RuntimeException('Preserve proof');file_put_contents($dest,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL;