9
9
use Illuminate \Support \Facades \Hash ;
10
10
use Laravel \Fortify \Events \TwoFactorAuthenticationChallenged ;
11
11
use Laravel \Fortify \Events \TwoFactorAuthenticationFailed ;
12
+ use Laravel \Fortify \Events \ValidTwoFactorAuthenticationCodeProvided ;
12
13
use Laravel \Fortify \Features ;
13
14
use Laravel \Fortify \Tests \Models \UserWithTwoFactor ;
14
15
use Orchestra \Testbench \Attributes \DefineEnvironment ;
@@ -156,6 +157,8 @@ public function test_does_not_rehash_user_password_when_redirecting_to_two_facto
156
157
157
158
public function test_two_factor_challenge_can_be_passed_via_code ()
158
159
{
160
+ Event::fake ();
161
+
159
162
$ tfaEngine = app (Google2FA::class);
160
163
$ userSecret = $ tfaEngine ->generateSecretKey ();
161
164
$ validOtp = $ tfaEngine ->getCurrentOtp ($ userSecret );
@@ -174,6 +177,8 @@ public function test_two_factor_challenge_can_be_passed_via_code()
174
177
'code ' => $ validOtp ,
175
178
]);
176
179
180
+ Event::assertDispatched (ValidTwoFactorAuthenticationCodeProvided::class);
181
+
177
182
$ response ->assertRedirect ('/home ' )
178
183
->assertSessionMissing ('login.id ' );
179
184
}
@@ -234,6 +239,8 @@ public function test_two_factor_challenge_fails_for_old_otp_and_zero_window()
234
239
235
240
public function test_two_factor_challenge_can_be_passed_via_recovery_code ()
236
241
{
242
+ Event::fake ();
243
+
237
244
$ user = UserWithTwoFactor::forceCreate ([
238
245
'name ' => 'Taylor Otwell ' ,
239
246
@@ -248,6 +255,8 @@ public function test_two_factor_challenge_can_be_passed_via_recovery_code()
248
255
'recovery_code ' => 'valid-code ' ,
249
256
]);
250
257
258
+ Event::assertDispatched (ValidTwoFactorAuthenticationCodeProvided::class);
259
+
251
260
$ response ->assertRedirect ('/home ' )
252
261
->assertSessionMissing ('login.id ' );
253
262
$ this ->assertNotNull (Auth::getUser ());
0 commit comments