66use Illuminate \Foundation \Testing \RefreshDatabase ;
77use Illuminate \Support \Facades \Cache ;
88use Illuminate \Support \Facades \Date ;
9+ use InvalidArgumentException ;
910use Laragear \TwoFactor \Models \TwoFactorAuthentication ;
1011use ParagonIE \ConstantTime \Base32 ;
1112use Tests \Stubs \UserStub ;
@@ -315,6 +316,20 @@ public function test_serializes_uri_to_json(): void
315316 static ::assertEquals ($ uri , $ tfa ->toJson ());
316317 }
317318
319+ public function test_uses_app_name_as_issuer (): void
320+ {
321+ $ tfa = TwoFactorAuthentication::factory ()->withRecovery ()->withSafeDevices ()->make ([
322+ 'label ' => 'test@foo.com ' ,
323+ 'shared_secret ' => static ::SECRET ,
324+ 'algorithm ' => 'sHa256 ' ,
325+ 'digits ' => 14 ,
326+ ]);
327+
328+ $ uri = 'otpauth://totp/Laravel%3Atest@foo.com?issuer=Laravel&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14 ' ;
329+
330+ static ::assertSame ($ uri , $ tfa ->toUri ());
331+ }
332+
318333 public function test_changes_issuer (): void
319334 {
320335 $ this ->app ->make ('config ' )->set ('two-factor.issuer ' , 'foo bar ' );
@@ -331,6 +346,24 @@ public function test_changes_issuer(): void
331346 static ::assertSame ($ uri , $ tfa ->toUri ());
332347 }
333348
349+ public function test_throws_exception_when_issuer_is_empty (): void
350+ {
351+ $ this ->app ->make ('config ' )->set ('app.name ' , '' );
352+ $ this ->app ->make ('config ' )->set ('two-factor.issuer ' , '' );
353+
354+ $ tfa = TwoFactorAuthentication::factory ()->withRecovery ()->withSafeDevices ()->make ([
355+ 'label ' => 'test@foo.com ' ,
356+ 'shared_secret ' => static ::SECRET ,
357+ 'algorithm ' => 'sHa256 ' ,
358+ 'digits ' => 14 ,
359+ ]);
360+
361+ $ this ->expectException (InvalidArgumentException::class);
362+ $ this ->expectExceptionMessage ('The TOTP issuer cannot be empty. ' );
363+
364+ $ tfa ->toUri ();
365+ }
366+
334367 public function test_uses_custom_generator (): void
335368 {
336369 $ i = 0 ;
0 commit comments