66use Tests \TestCase ;
77use Pterodactyl \Models \User ;
88use PragmaRX \Google2FA \Google2FA ;
9- use Illuminate \Contracts \ Config \ Repository ;
9+ use Illuminate \Support \ Collection ;
1010use Illuminate \Contracts \Encryption \Encrypter ;
1111use Pterodactyl \Services \Users \TwoFactorSetupService ;
1212use Pterodactyl \Contracts \Repository \UserRepositoryInterface ;
@@ -40,7 +40,6 @@ public function setUp()
4040 {
4141 parent ::setUp ();
4242
43- $ this ->config = m::mock (Repository::class);
4443 $ this ->encrypter = m::mock (Encrypter::class);
4544 $ this ->google2FA = m::mock (Google2FA::class);
4645 $ this ->repository = m::mock (UserRepositoryInterface::class);
@@ -53,16 +52,19 @@ public function testSecretAndImageAreReturned()
5352 {
5453 $ model = factory (User::class)->make ();
5554
56- $ this ->config ->shouldReceive ('get ' )->with ('pterodactyl.auth.2fa.bytes ' )->once ()->andReturn (32 );
55+ config ()->set ('pterodactyl.auth.2fa.bytes ' , 32 );
56+ config ()->set ('app.name ' , 'CompanyName ' );
57+
5758 $ this ->google2FA ->shouldReceive ('generateSecretKey ' )->with (32 )->once ()->andReturn ('secretKey ' );
58- $ this ->config ->shouldReceive ('get ' )->with ('app.name ' )->once ()->andReturn ('CompanyName ' );
5959 $ this ->google2FA ->shouldReceive ('getQRCodeGoogleUrl ' )->with ('CompanyName ' , $ model ->email , 'secretKey ' )->once ()->andReturn ('http://url.com ' );
6060 $ this ->encrypter ->shouldReceive ('encrypt ' )->with ('secretKey ' )->once ()->andReturn ('encryptedSecret ' );
6161 $ this ->repository ->shouldReceive ('withoutFreshModel->update ' )->with ($ model ->id , ['totp_secret ' => 'encryptedSecret ' ])->once ()->andReturnNull ();
6262
6363 $ response = $ this ->getService ()->handle ($ model );
6464 $ this ->assertNotEmpty ($ response );
65- $ this ->assertSame ('http://url.com ' , $ response );
65+ $ this ->assertInstanceOf (Collection::class, $ response );
66+ $ this ->assertSame ('http://url.com ' , $ response ->get ('image ' ));
67+ $ this ->assertSame ('secretKey ' , $ response ->get ('secret ' ));
6668 }
6769
6870 /**
@@ -72,6 +74,6 @@ public function testSecretAndImageAreReturned()
7274 */
7375 private function getService (): TwoFactorSetupService
7476 {
75- return new TwoFactorSetupService ($ this ->config , $ this -> encrypter , $ this ->google2FA , $ this ->repository );
77+ return new TwoFactorSetupService ($ this ->encrypter , $ this ->google2FA , $ this ->repository );
7678 }
7779}
0 commit comments