-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6cef9c
commit cf45fd6
Showing
11 changed files
with
159 additions
and
36 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
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 |
---|---|---|
|
@@ -4,6 +4,4 @@ | |
|
||
use Exception; | ||
|
||
class MissingCode extends Exception | ||
{ | ||
} | ||
class MissingCode extends Exception {} |
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
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 |
---|---|---|
|
@@ -198,7 +198,7 @@ public function test_can_login_with_superpin(): void | |
{ | ||
Notification::fake(); | ||
|
||
Config::set('totp-login.superpin', 333333); | ||
Config::set('totp-login.superpin.pin', 333333); | ||
|
||
$user = $this->createUser([ | ||
config('totp-login.columns.code_valid_until') => now()->addMinutes(10), | ||
|
@@ -220,4 +220,64 @@ public function test_can_login_with_superpin(): void | |
|
||
Notification::assertNothingSent(); | ||
} | ||
|
||
public function test_cannot_login_with_superpin_on_wrong_environment(): void | ||
{ | ||
Notification::fake(); | ||
|
||
Config::set('totp-login.superpin.pin', 333333); | ||
Config::set('totp-login.superpin.environments', ['production']); | ||
|
||
$user = $this->createUser([ | ||
config('totp-login.columns.code_valid_until') => now()->addMinutes(10), | ||
]); | ||
|
||
$response = $this | ||
->withSession([ | ||
config('totp-login.columns.identifier') => $user->{config('totp-login.columns.identifier')}, | ||
]) | ||
->post(route('totp-login.code.handle'), [ | ||
'code' => [3, 3, 3, 3, 3, 3], | ||
]); | ||
|
||
$response->assertRedirect(); | ||
|
||
$response->assertSessionHasErrors('code', __('controllers/session.store.error.totp_wrong', [ | ||
'attempts_left' => config('totp-login.code.max_attempts') - 1, | ||
])); | ||
|
||
$this->assertGuest(); | ||
|
||
Notification::assertNothingSent(); | ||
} | ||
|
||
public function test_can_login_with_superpin_on_wrong_environment_with_bypassing_identifier(): void | ||
{ | ||
Notification::fake(); | ||
|
||
Config::set('totp-login.superpin.pin', 333333); | ||
Config::set('totp-login.superpin.environments', ['production']); | ||
Config::set('totp-login.superpin.bypassing_identifiers', ['[email protected]']); | ||
|
||
$user = $this->createUser([ | ||
config('totp-login.columns.identifier') => '[email protected]', | ||
config('totp-login.columns.code_valid_until') => now()->addMinutes(10), | ||
]); | ||
|
||
$response = $this | ||
->withSession([ | ||
config('totp-login.columns.identifier') => $user->{config('totp-login.columns.identifier')}, | ||
]) | ||
->post(route('totp-login.code.handle'), [ | ||
'code' => [3, 3, 3, 3, 3, 3], | ||
]); | ||
|
||
$response->assertSessionHasNoErrors(); | ||
|
||
$response->assertRedirect(config('totp-login.redirect')); | ||
|
||
$this->assertAuthenticatedAs($user); | ||
|
||
Notification::assertNothingSent(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Empuxa\TotpLogin\Tests\Unit; | ||
|
||
use Empuxa\TotpLogin\Requests\CodeRequest; | ||
use Illuminate\Support\Facades\Config; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class HandleCodeRequestTest extends TestCase | ||
{ | ||
public function test_runs_on_allowed_environment(): void | ||
{ | ||
Config::set('totp-login.superpin.pin', 333333); | ||
Config::set('totp-login.superpin.environments', ['production']); | ||
|
||
$data = [ | ||
'production' => true, | ||
'prod*' => false, | ||
'staging' => false, | ||
'testing' => false, | ||
'local' => false, | ||
]; | ||
|
||
foreach ($data as $environment => $expected) { | ||
$this->assertEquals($expected, CodeRequest::runsOnAllowedEnvironment($environment), $environment); | ||
} | ||
} | ||
|
||
public function test_bypasses_environment(): void | ||
{ | ||
Config::set('totp-login.superpin.pin', 333333); | ||
Config::set('totp-login.superpin.environments', ['non-existing']); | ||
Config::set('totp-login.superpin.bypassing_identifiers', ['[email protected]']); | ||
|
||
$data = [ | ||
'[email protected]' => true, | ||
'test@*' => false, | ||
'[email protected]' => false, | ||
]; | ||
|
||
foreach ($data as $email => $expected) { | ||
$this->assertEquals($expected, CodeRequest::bypassesEnvironment($email), $email); | ||
} | ||
} | ||
} |