-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added config option for custom OTP window (#385)
* Added config option for custom OTP window * StyleCI fixes
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,41 @@ public function test_two_factor_challenge_can_be_passed_via_code() | |
->assertSessionMissing('login.id'); | ||
} | ||
|
||
public function test_two_factor_challenge_fails_for_old_otp_and_zero_window() | ||
{ | ||
app('config')->set('auth.providers.users.model', TestTwoFactorAuthenticationSessionUser::class); | ||
|
||
//Setting window to 0 should mean any old OTP is instantly invalid | ||
app('config')->set('fortify.features', [ | ||
Features::twoFactorAuthentication(['window' => 0]), | ||
]); | ||
|
||
$this->loadLaravelMigrations(['--database' => 'testbench']); | ||
$this->artisan('migrate', ['--database' => 'testbench'])->run(); | ||
|
||
$tfaEngine = app(Google2FA::class); | ||
$userSecret = $tfaEngine->generateSecretKey(); | ||
$currentTs = $tfaEngine->getTimestamp(); | ||
$previousOtp = $tfaEngine->oathTotp($userSecret, $currentTs - 1); | ||
|
||
$user = TestTwoFactorAuthenticationSessionUser::forceCreate([ | ||
'name' => 'Taylor Otwell', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
'two_factor_secret' => encrypt($userSecret), | ||
]); | ||
|
||
$response = $this->withSession([ | ||
'login.id' => $user->id, | ||
'login.remember' => false, | ||
])->withoutExceptionHandling()->post('/two-factor-challenge', [ | ||
'code' => $previousOtp, | ||
]); | ||
|
||
$response->assertRedirect('/two-factor-challenge') | ||
->assertSessionHas('login.id'); | ||
} | ||
|
||
public function test_two_factor_challenge_can_be_passed_via_recovery_code() | ||
{ | ||
app('config')->set('auth.providers.users.model', TestTwoFactorAuthenticationSessionUser::class); | ||
|