actingAs(User::factory()->withoutTwoFactor()->create()); $setUpUrl = Filament::getPanel('admin')->getSetUpRequiredMultiFactorAuthenticationUrl(); $this->get(BookingResource::getUrl('index'))->assertRedirect($setUpUrl); $this->get($setUpUrl)->assertOk()->assertSee('Authenticator', false); } public function test_admin_with_two_factor_enters_the_admin(): void { $this->actingAs(User::factory()->create()); $this->get(BookingResource::getUrl('index'))->assertOk(); } public function test_other_roles_may_work_without_two_factor(): void { $this->actingAs(User::factory()->role(UserRole::Rentals)->withoutTwoFactor()->create()); $this->get(BookingResource::getUrl('index'))->assertOk(); } public function test_two_factor_secret_is_stored_encrypted(): void { $user = User::factory()->create(); $this->assertNotSame('JBSWY3DPEHPK3PXP', $user->getRawOriginal('app_authentication_secret')); $this->assertSame('JBSWY3DPEHPK3PXP', $user->fresh()->getAppAuthenticationSecret()); } public function test_command_creates_an_admin_with_interactively_entered_password(): void { $this->artisan('users:create', ['email' => 'Lars@Example.com', '--name' => 'Lars', '--role' => 'admin']) ->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort') ->expectsQuestion('Passwort wiederholen', 'ein-sicheres-passwort') ->assertSuccessful(); $user = User::firstWhere('email', 'lars@example.com'); $this->assertSame(UserRole::Admin, $user->role); $this->assertTrue(Hash::check('ein-sicheres-passwort', $user->password)); $this->assertNull($user->getAppAuthenticationSecret()); } public function test_command_rejects_mismatching_passwords(): void { $this->artisan('users:create', ['email' => 'lars@example.com', '--name' => 'Lars', '--role' => 'admin']) ->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort') ->expectsQuestion('Passwort wiederholen', 'etwas-anderes-passwort') ->assertFailed(); $this->assertDatabaseCount('users', 0); } }