assertFalse(User::factory()->create()->verifyTotp('123456')); } public function test_malformed_secret_returns_false_without_throwing(): void { // A non-null but invalid secret must not bubble a Google2FA exception. $user = User::factory()->create(['two_factor_secret' => 'x', 'two_factor_confirmed_at' => now()]); $this->assertFalse($user->verifyTotp('123456')); } public function test_valid_secret_accepts_the_current_code(): void { $g = new Google2FA; $secret = $g->generateSecretKey(); $user = User::factory()->create(['two_factor_secret' => $secret, 'two_factor_confirmed_at' => now()]); $this->assertTrue($user->verifyTotp($g->getCurrentOtp($secret))); $this->assertFalse($user->verifyTotp('000000')); } }