62 lines
4.7 KiB
PHP
62 lines
4.7 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args', '1');
|
|
putenv('STABILITY_QA_MODE=consumers');
|
|
$policyRoot = dirname(__DIR__, 2);
|
|
$policyQA = $policyRoot.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
|
|
$policyPath = __DIR__.'/case32-reauth-policy-QA-20261014.json';
|
|
if (is_file($policyPath)) { throw new RuntimeException('Regressão já executada.'); }
|
|
$app = require $policyQA.'/tools/portal-stability-runtime.php';
|
|
$db = Illuminate\Support\Facades\DB::connection();
|
|
$target = (array) $db->selectOne('SELECT current_database() AS database, inet_server_port() AS port');
|
|
if ($target !== ['database'=>'stability_consumers_20261011_084534_test', 'port'=>55441]) { throw new RuntimeException('QA isolada obrigatória.'); }
|
|
$db->beginTransaction();
|
|
$db->statement('SET TRANSACTION READ ONLY');
|
|
try {
|
|
// Test-only in-memory session fixtures; no actual user's session is modified.
|
|
config(['session.driver'=>'array']);
|
|
app('session')->forgetDrivers();
|
|
$session = app('session')->driver();
|
|
$actor = App\Models\User::findOrFail(24);
|
|
$record = App\Models\Opportunity::findOrFail(32);
|
|
$access = app(App\Services\PortalProfileAccess::class);
|
|
$workflow = app(App\Services\OpportunityProfileWorkflow::class);
|
|
$before = app(App\Services\OpportunityManagement::class)->etag($record);
|
|
$session->put(['portal.mfa_actor'=>24, 'portal.mfa_at'=>time() - 3600]);
|
|
$tests = [];
|
|
$tests['expired_MFA_shows_scoped_capabilities_disabled_by_page_flag'] = in_array('start_review', $workflow->actions($actor, $record), true) && $workflow->reauthenticationRequired($actor, $record);
|
|
$caught = null;
|
|
try {
|
|
$workflow->transition($actor, 32, ['etag'=>$before, 'action'=>'start_review',
|
|
'reason'=>'Regressão isolada QA: MFA antigo continua a impedir a ação.']);
|
|
} catch (Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $error) { $caught = $error; }
|
|
$tests['server_still_refuses_expired_MFA_403'] = $caught && $caught->getStatusCode() === 403;
|
|
$tests['refusal_identifies_same_window_reauthentication'] = $caught && ($caught->getHeaders()['X-Portal-Reauthentication'] ?? null) === 'required';
|
|
$request = Illuminate\Http\Request::create('/minhas-oportunidades/32/workflow', 'POST');
|
|
$request->headers->set('Accept', 'application/json');
|
|
$response = $caught ? app(Illuminate\Contracts\Debug\ExceptionHandler::class)->render($request, $caught) : null;
|
|
$tests['Laravel_JSON_preserves_reauthentication_header'] = $response && $response->getStatusCode() === 403
|
|
&& $response->headers->get('X-Portal-Reauthentication') === 'required';
|
|
$session->put('portal.mfa_at', time());
|
|
$tests['fresh_MFA_removes_reauthentication_flag'] = ! $workflow->reauthenticationRequired($actor, $record)
|
|
&& $access->mfa($actor) && in_array('start_review', $workflow->actions($actor, $record), true);
|
|
$session->put('portal.mfa_actor', 25);
|
|
$tests['other_actor_MFA_does_not_authorize_QA24'] = ! $access->mfa($actor) && $workflow->reauthenticationRequired($actor, $record);
|
|
$session->put(['portal.mfa_actor'=>24, 'portal.mfa_at'=>time(), 'login.id'=>24]);
|
|
$tests['pending_challenge_does_not_authorize'] = ! $access->mfa($actor) && $workflow->reauthenticationRequired($actor, $record);
|
|
$session->forget('login.id');
|
|
$outsider = App\Models\User::findOrFail(23);
|
|
$tests['outsider_receives_no_capabilities_or_reauthentication_hint'] = $workflow->actions($outsider, $record) === []
|
|
&& ! $workflow->reauthenticationRequired($outsider, $record) && ! $access->canView($outsider, $record);
|
|
$tests['record_and_ETag_unchanged'] = $before === app(App\Services\OpportunityManagement::class)->etag($record->fresh())
|
|
&& app(App\Services\PortalProfileAccess::class)->state($record->fresh()) === 'submitted';
|
|
if (in_array(false, $tests, true)) { throw new RuntimeException('Regressão de autorização falhou.'); }
|
|
$receipt = ['at'=>gmdate('c'), 'target'=>$target, 'SQL_read_only'=>true,
|
|
'tests'=>$tests, 'result'=>'passed', 'session_fixtures_in_memory_only'=>true,
|
|
'actual_user_sessions_unchanged'=>true, 'QA_database_changes'=>0, 'active_changes'=>0,
|
|
'visual_acceptance'=>false, 'successful_workflow_transition_executed'=>false,
|
|
'limits'=>['Policy/response regression only, not a browser MFA demonstration.',
|
|
'No secret, cookie or session value written to evidence.']];
|
|
file_put_contents($policyPath, json_encode($receipt, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['result'=>'passed', 'security_boundary_cases'=>count($tests), 'actual_user_sessions_unchanged'=>true, 'active_changes'=>0], JSON_THROW_ON_ERROR).PHP_EOL;
|
|
} finally { $db->rollBack(); }
|