-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
6910f73
commit a9f453b
Showing
2 changed files
with
38 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Date; | ||
use InvalidArgumentException; | ||
use Laragear\TwoFactor\Models\TwoFactorAuthentication; | ||
use ParagonIE\ConstantTime\Base32; | ||
use Tests\Stubs\UserStub; | ||
|
@@ -315,6 +316,20 @@ public function test_serializes_uri_to_json(): void | |
static::assertEquals($uri, $tfa->toJson()); | ||
} | ||
|
||
public function test_uses_app_name_as_issuer(): void | ||
{ | ||
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([ | ||
'label' => '[email protected]', | ||
'shared_secret' => static::SECRET, | ||
'algorithm' => 'sHa256', | ||
'digits' => 14, | ||
]); | ||
|
||
$uri = 'otpauth://totp/Laravel%[email protected]?issuer=Laravel&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14'; | ||
|
||
static::assertSame($uri, $tfa->toUri()); | ||
} | ||
|
||
public function test_changes_issuer(): void | ||
{ | ||
$this->app->make('config')->set('two-factor.issuer', 'foo bar'); | ||
|
@@ -331,6 +346,24 @@ public function test_changes_issuer(): void | |
static::assertSame($uri, $tfa->toUri()); | ||
} | ||
|
||
public function test_throws_exception_when_issuer_is_empty(): void | ||
{ | ||
$this->app->make('config')->set('app.name', ''); | ||
$this->app->make('config')->set('two-factor.issuer', ''); | ||
|
||
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([ | ||
'label' => '[email protected]', | ||
'shared_secret' => static::SECRET, | ||
'algorithm' => 'sHa256', | ||
'digits' => 14, | ||
]); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('The TOTP issuer cannot be empty.'); | ||
|
||
$tfa->toUri(); | ||
} | ||
|
||
public function test_uses_custom_generator(): void | ||
{ | ||
$i = 0; | ||
|