MFA obrigatório para administração e Finanças
Decisão de 30/11/2026, substitui a de 03/11 («MFA desligado»). - SGC_TWO_FACTOR_ENABLED passa a true por omissão. - RequireTwoFactorForSensitiveRoles: com o MFA ligado, quem tem uma função de config/mfa.php (por omissão admin e finance) é reencaminhado para /settings/security até confirmar o MFA; pedidos JSON recebem 403. Definições, confirmação de palavra-passe e saída continuam acessíveis. Restantes perfis: voluntário. Avaliação local isolada isenta. - Página de segurança mostra o aviso quando o MFA é obrigatório. - Testes correm com MFA desligado; MfaRequiredTest liga-o explicitamente. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\Department;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Laravel\Fortify\Actions\EnableTwoFactorAuthentication;
|
||||
|
||||
require_once __DIR__.'/../../Support/FortifyMfa.php';
|
||||
|
||||
// Decisão de 30/11/2026: MFA obrigatório para administração e Finanças, voluntário para os restantes.
|
||||
|
||||
beforeEach(function () {
|
||||
foundationMfaRoutes();
|
||||
$tenant = Tenant::query()->create(['name' => 'Empresa MFA']);
|
||||
$this->department = Department::query()->create(['tenant_id' => $tenant->id, 'name' => 'Operações']);
|
||||
$this->user = fn (PurchasingRole $role) => User::factory()->create(['tenant_id' => $tenant->id, 'department_id' => $this->department->id, 'purchasing_role' => $role]);
|
||||
});
|
||||
|
||||
test('sensitive roles without confirmed MFA are sent to the security settings', function (PurchasingRole $role) {
|
||||
$this->actingAs(($this->user)($role));
|
||||
$this->get('/dashboard')->assertRedirect('/settings/security');
|
||||
$this->get('/facturas')->assertRedirect('/settings/security');
|
||||
$this->getJson('/requisicoes')->assertForbidden();
|
||||
})->with([PurchasingRole::Admin, PurchasingRole::Finance]);
|
||||
|
||||
test('the security settings, password confirmation and logout stay reachable while MFA is pending', function () {
|
||||
$this->actingAs(($this->user)(PurchasingRole::Finance));
|
||||
$this->get('/user/confirm-password')->assertOk();
|
||||
$this->withSession(['auth.password_confirmed_at' => time()])->get('/settings/security')->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->component('settings/security')->where('mfaRequired', true)->where('canManageTwoFactor', true));
|
||||
$this->post('/logout')->assertRedirect();
|
||||
$this->assertGuest();
|
||||
});
|
||||
|
||||
test('confirmed MFA unlocks the application for sensitive roles', function () {
|
||||
$finance = ($this->user)(PurchasingRole::Finance);
|
||||
app(EnableTwoFactorAuthentication::class)($finance);
|
||||
$finance->forceFill(['two_factor_confirmed_at' => now()])->save();
|
||||
$this->actingAs($finance)->get('/dashboard')->assertOk();
|
||||
});
|
||||
|
||||
test('other roles keep MFA voluntary', function () {
|
||||
$this->actingAs(($this->user)(PurchasingRole::Requester))->get('/dashboard')->assertOk();
|
||||
});
|
||||
|
||||
test('nothing is enforced while MFA is switched off for the installation', function () {
|
||||
config(['fortify.features' => []]);
|
||||
$this->actingAs(($this->user)(PurchasingRole::Admin))->get('/dashboard')->assertOk();
|
||||
});
|
||||
Reference in New Issue
Block a user