-
Notifications
You must be signed in to change notification settings - Fork 2
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
baf4850
commit b4b54af
Showing
1 changed file
with
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Emargareten\TwoFactor\Tests; | ||
|
||
class TwoFactorAuthenticationTest extends OrchestraTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->loadLaravelMigrations(['--database' => 'testbench']); | ||
$this->artisan('migrate', ['--database' => 'testbench'])->run(); | ||
} | ||
|
||
public function test_two_factor_authentication_can_be_enabled(): void | ||
{ | ||
$user = TestUser::create([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
]); | ||
|
||
$user->enableTwoFactorAuthentication(); | ||
|
||
$user->refresh(); | ||
|
||
$this->assertNotNull($user->two_factor_secret); | ||
$this->assertNotNull($user->two_factor_recovery_codes); | ||
$this->assertNull($user->two_factor_confirmed_at); | ||
} | ||
|
||
public function test_two_factor_authentication_can_be_confirmed(): void | ||
{ | ||
$user = TestUser::create([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
]); | ||
|
||
$user->enableTwoFactorAuthentication(); | ||
|
||
$user->confirmTwoFactorAuthentication($user->getCurrentOtp()); | ||
|
||
$user->refresh(); | ||
|
||
$this->assertNotNull($user->two_factor_secret); | ||
$this->assertNotNull($user->two_factor_recovery_codes); | ||
$this->assertNotNull($user->two_factor_confirmed_at); | ||
} | ||
|
||
public function test_two_factor_authentication_can_be_confirmed_with_method(): void | ||
{ | ||
$user = TestUser::create([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
]); | ||
|
||
$user->enableTwoFactorAuthentication(); | ||
|
||
$user->confirmTwoFactorAuthentication($user->getCurrentOtp(), 'SMS'); | ||
|
||
$user->refresh(); | ||
|
||
$this->assertNotNull($user->two_factor_secret); | ||
$this->assertNotNull($user->two_factor_recovery_codes); | ||
$this->assertNotNull($user->two_factor_confirmed_at); | ||
$this->assertEquals('SMS', $user->two_factor_method); | ||
} | ||
|
||
public function test_two_factor_authentication_can_be_disabled(): void | ||
{ | ||
$user = TestUser::create([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
'two_factor_secret' => 'foo', | ||
'two_factor_recovery_codes' => ['bar', 'baz'], | ||
'two_factor_confirmed_at' => now(), | ||
'two_factor_method' => 'SMS', | ||
]); | ||
|
||
$user->disableTwoFactorAuthentication(); | ||
|
||
$user->refresh(); | ||
|
||
$this->assertNull($user->two_factor_secret); | ||
$this->assertNull($user->two_factor_recovery_codes); | ||
$this->assertNull($user->two_factor_confirmed_at); | ||
$this->assertNull($user->two_factor_method); | ||
} | ||
} |