Merge branch 'release/v0.7.14' into feature/react

This commit is contained in:
Dane Everitt 2019-06-22 12:28:44 -07:00
commit 56640253b9
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
16 changed files with 178 additions and 59 deletions

View file

@ -71,6 +71,7 @@ class SecurityControllerTest extends ControllerTestCase
$this->assertIsJsonResponse($response);
$this->assertResponseCodeEquals(Response::HTTP_OK, $response);
$this->assertResponseJsonEquals(['enabled' => false, 'qr_image' => 'test-image', 'secret' => 'secret-code'], $response);
$this->assertResponseJsonEquals(['qrImage' => 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=qrCodeImage'], $response);
}
/**

View file

@ -5,8 +5,6 @@ namespace Tests\Unit\Services\Users;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\User;
use Illuminate\Support\Collection;
use PragmaRX\Google2FAQRCode\Google2FA;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Services\Users\TwoFactorSetupService;
@ -24,11 +22,6 @@ class TwoFactorSetupServiceTest extends TestCase
*/
private $encrypter;
/**
* @var PragmaRX\Google2FAQRCode\Google2FA|\Mockery\Mock
*/
private $google2FA;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
*/
@ -43,7 +36,6 @@ class TwoFactorSetupServiceTest extends TestCase
$this->config = m::mock(Repository::class);
$this->encrypter = m::mock(Encrypter::class);
$this->google2FA = m::mock(Google2FA::class);
$this->repository = m::mock(UserRepositoryInterface::class);
}
@ -54,20 +46,27 @@ class TwoFactorSetupServiceTest extends TestCase
{
$model = factory(User::class)->make();
config()->set('pterodactyl.auth.2fa.bytes', 32);
config()->set('app.name', 'CompanyName');
$this->config->shouldReceive('get')->with('pterodactyl.auth.2fa.bytes', 16)->andReturn(32);
$this->config->shouldReceive('get')->with('app.name')->andReturn('Company Name');
$this->encrypter->shouldReceive('encrypt')
->with(m::on(function ($value) {
return preg_match('/([A-Z234567]{32})/', $value) !== false;
}))
->once()
->andReturn('encryptedSecret');
$this->google2FA->shouldReceive('generateSecretKey')->with(32)->once()->andReturn('secretKey');
$this->config->shouldReceive('get')->with('app.name')->once()->andReturn('CompanyName');
$this->google2FA->shouldReceive('getQRCodeInline')->with('CompanyName', $model->email, 'secretKey')->once()->andReturn('http://url.com');
$this->encrypter->shouldReceive('encrypt')->with('secretKey')->once()->andReturn('encryptedSecret');
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, ['totp_secret' => 'encryptedSecret'])->once()->andReturnNull();
$response = $this->getService()->handle($model);
$this->assertNotEmpty($response);
$this->assertInstanceOf(Collection::class, $response);
$this->assertSame('http://url.com', $response->get('image'));
$this->assertSame('secretKey', $response->get('secret'));
$companyName = preg_quote(rawurlencode('Company Name'));
$email = preg_quote(rawurlencode($model->email));
$this->assertRegExp(
'/otpauth:\/\/totp\/' . $companyName . ':' . $email . '\?secret=([A-Z234567]{32})&issuer=' . $companyName . '/',
$response
);
}
/**
@ -77,6 +76,6 @@ class TwoFactorSetupServiceTest extends TestCase
*/
private function getService(): TwoFactorSetupService
{
return new TwoFactorSetupService($this->encrypter, $this->google2FA, $this->repository);
return new TwoFactorSetupService($this->config, $this->encrypter, $this->repository);
}
}