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(); });