47 lines
5.4 KiB
PHP
47 lines
5.4 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');
|
|
set_exception_handler(function(Throwable $e){fwrite(STDERR,'QA fixture stopped: '.$e::class.' line '.$e->getLine().PHP_EOL);exit(1);});
|
|
require __DIR__.'/boot-QA.php';
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use App\Models\ExistingBusiness;
|
|
$private='C:/Users/macbook/.config/investmoz/negocios-classificacao-QA-20261016';
|
|
if(is_file($private.'/fixture-private.json'))throw new RuntimeException('Preserve fixture');
|
|
$id='172aa874-98fc-4bf6-b78f-d2e9a386d345';$business=ExistingBusiness::findOrFail($id);
|
|
if($business->status!=='published'||$business->version_no!==12)throw new RuntimeException('Existing published v12 required');
|
|
$roles=DB::table('portal_role_assignments')->orderBy('id')->get()->toJson();
|
|
$actors=[];foreach([21=>'owner',24=>'reviewer',25=>'publisher',23=>'outsider',31=>'auditor']as$userId=>$name){
|
|
$password=bin2hex(random_bytes(20));$alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';$secret='';for($i=0;$i<32;$i++)$secret.=$alphabet[random_int(0,31)];
|
|
$email='qa-business-classification-'.$userId.'@example.invalid';
|
|
DB::table('users')->where('id',$userId)->update(['email'=>$email,'password'=>Hash::make($password),'two_factor_secret'=>Crypt::encrypt($secret),'two_factor_recovery_codes'=>Crypt::encrypt('[]'),'two_factor_confirmed_at'=>now(),'remember_token'=>null]);
|
|
$actors[$name]=['id'=>$userId,'email'=>$email,'password'=>$password,'secret'=>$secret];
|
|
}
|
|
$document=DB::table('documents')->where('id','025cce5b-73c1-43a3-b969-dc6e592bc28d')->first();
|
|
if(!$document||$document->file_name!=='synthetic-qa-proof.txt'||$document->status!=='active'||$document->malware_scan_status!=='clean'||!hash_equals(trim($document->sha256),trim($document->malware_scanned_sha256)))throw new RuntimeException('Existing synthetic scanned support required');
|
|
$reference=dirname(__DIR__,2).'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742/storage/app/private';
|
|
$from=realpath($reference.'/'.$document->storage_key);$base=realpath($reference);
|
|
if(!$from||!str_starts_with(strtolower(str_replace('\\','/',$from)),strtolower(str_replace('\\','/',$base)).'/'))throw new RuntimeException('QA document path guard');
|
|
$stored=file_get_contents($from);$bytes=($document->storage_encryption??null)==='laravel'?Crypt::decryptString($stored):$stored;
|
|
if(!hash_equals(trim($document->sha256),hash('sha256',$bytes)))throw new RuntimeException('Synthetic support bytes mismatch');
|
|
$dest=$source.'/storage/app/private/'.$document->storage_key;if(!is_dir(dirname($dest)))mkdir(dirname($dest),0700,true);file_put_contents($dest,$stored);
|
|
$linkId=DB::table('existing_business_document_links')->where('existing_business_id',$id)->where('document_id',$document->id)->value('id')??(string)Illuminate\Support\Str::uuid();
|
|
DB::table('existing_business_document_links')->insertOrIgnore(['id'=>$linkId,'existing_business_id'=>$id,'document_id'=>$document->id,'uploaded_by'=>21,'created_at'=>now(),'updated_at'=>now()]);
|
|
$options=app(App\Services\OpportunityClassification::class)->options();$rows=[];
|
|
foreach(['location'=>'proximity','cluster'=>'productive_complementarity','zone'=>'regime_recognition','sector'=>'economic_activity']as$kind=>$purpose){
|
|
$target=collect($options['targets'][$kind])->first();if(!$target)throw new RuntimeException('Existing consultable target required');
|
|
$rows[]=['related_id'=>(string)$target->id,'relation_type'=>'classification','classification'=>['target_type'=>$kind,'purpose'=>$purpose,'requested_state'=>'in_validation','disclosure'=>'public',
|
|
'criteria'=>'QA-PRIVATE-MARKER: ensaio de associação sintética, sem afirmação de relação real.',
|
|
'justification'=>'QA-PRIVATE-MARKER: suporte sintético autorizado para testar o mecanismo, não uma licença ou benefício.',
|
|
'source_reference'=>'ENSAIO SINTÉTICO QA — documento de suporte autorizado; sem efeito externo.',
|
|
'citation'=>'QA sintética, página 1; não constitui fonte de um ato de concessão.', 'document_id'=>$document->id,'authority_id'=>null,'external_status'=>'not_assessed']];
|
|
}
|
|
if($roles!==DB::table('portal_role_assignments')->orderBy('id')->get()->toJson())throw new RuntimeException('No role changes permitted');
|
|
$f=['url'=>'http://127.0.0.1:18521','database'=>'business_classification_20261016_test','actors'=>$actors,'id'=>$id,'slug'=>$business->public_slug,'rows'=>$rows,'document_id'=>$document->id,
|
|
'foreign_document_id'=>'011f4e4c-d477-48df-a92f-823bc9281738','roles_sha256'=>hash('sha256',$roles)];
|
|
file_put_contents($private.'/fixture-private.json',json_encode($f,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));
|
|
$proof=['target'=>'business_classification_20261016_test:55441','business_id'=>$id,'initial_status'=>'published','initial_version'=>12,'new_business_records'=>0,'grants_changed'=>0,'workflow_transitions'=>0,
|
|
'synthetic_support'=>['document_id'=>$document->id,'file_name'=>$document->file_name,'sha256'=>$document->sha256,'existing_clean_scan_and_hash_match'=>true,'bytes_verified'=>true,'new_upload'=>false,'new_publication'=>false,'new_link_in_clone_only'=>$linkId],
|
|
'reference_QA_unchanged'=>true,'credential_changes'=>'Five synthetic accounts in the isolated clone only; private values excluded','roles_sha256'=>hash('sha256',$roles),'active_changes'=>0];
|
|
file_put_contents(__DIR__.'/FIXTURE-QA.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE).PHP_EOL);echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL;
|