markTestSkipped('Two factor authentication is not enabled.'); } $this->actingAs($user = User::factory()->createOne()); $this->withSession(['auth.password_confirmed_at' => time()]); Livewire::test(TwoFactorAuthenticationForm::class) ->call('enableTwoFactorAuthentication'); $user = $user->fresh(); static::assertNotNull($user->two_factor_secret); static::assertCount(8, $user->recoveryCodes()); } /** * Recovery codes can be regenerated. * * @return void */ public function testRecoveryCodesCanBeRegenerated(): void { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two factor authentication is not enabled.'); } $this->actingAs($user = User::factory()->createOne()); $this->withSession(['auth.password_confirmed_at' => time()]); $component = Livewire::test(TwoFactorAuthenticationForm::class) ->call('enableTwoFactorAuthentication') ->call('regenerateRecoveryCodes'); $user = $user->fresh(); $component->call('regenerateRecoveryCodes'); static::assertCount(8, $user->recoveryCodes()); static::assertCount(8, array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes())); } /** * Two-factor authentication can be disabled. * * @return void */ public function testTwoFactorAuthenticationCanBeDisabled(): void { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two factor authentication is not enabled.'); } $this->actingAs($user = User::factory()->createOne()); $this->withSession(['auth.password_confirmed_at' => time()]); $component = Livewire::test(TwoFactorAuthenticationForm::class) ->call('enableTwoFactorAuthentication'); static::assertNotNull($user->fresh()->two_factor_secret); $component->call('disableTwoFactorAuthentication'); static::assertNull($user->fresh()->two_factor_secret); } }