Rename APIKey to ApiKey
This commit is contained in:
parent
7aa540b895
commit
ad3a954256
14 changed files with 53 additions and 53 deletions
|
@ -4,7 +4,7 @@ namespace Tests\Unit\Http\Controllers\Base;
|
|||
|
||||
use Mockery as m;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\APIKey;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Services\Api\KeyCreationService;
|
||||
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
||||
|
@ -88,7 +88,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
{
|
||||
$this->setRequestMockClass(ApiKeyFormRequest::class);
|
||||
$model = $this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
$keyModel = factory(APIKey::class)->make();
|
||||
$keyModel = factory(ApiKey::class)->make();
|
||||
|
||||
if ($admin) {
|
||||
$this->request->shouldReceive('input')->with('admin_permissions', [])->once()->andReturn(['admin.permission']);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Tests\Unit\Http\Middleware\Api\Admin;
|
||||
|
||||
use Pterodactyl\Models\APIKey;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
||||
use Pterodactyl\Http\Middleware\Api\Admin\AuthenticateIPAccess;
|
||||
|
||||
|
@ -13,7 +13,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testWithNoIPRestrictions()
|
||||
{
|
||||
$model = factory(APIKey::class)->make(['allowed_ips' => []]);
|
||||
$model = factory(ApiKey::class)->make(['allowed_ips' => []]);
|
||||
$this->setRequestAttribute('api_key', $model);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
|
@ -25,7 +25,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testWithValidIP()
|
||||
{
|
||||
$model = factory(APIKey::class)->make(['allowed_ips' => ['127.0.0.1']]);
|
||||
$model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]);
|
||||
$this->setRequestAttribute('api_key', $model);
|
||||
|
||||
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1');
|
||||
|
@ -38,7 +38,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testValidIPAganistCIDRRange()
|
||||
{
|
||||
$model = factory(APIKey::class)->make(['allowed_ips' => ['192.168.1.1/28']]);
|
||||
$model = factory(ApiKey::class)->make(['allowed_ips' => ['192.168.1.1/28']]);
|
||||
$this->setRequestAttribute('api_key', $model);
|
||||
|
||||
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15');
|
||||
|
@ -54,7 +54,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testWithInvalidIP()
|
||||
{
|
||||
$model = factory(APIKey::class)->make(['allowed_ips' => ['127.0.0.1']]);
|
||||
$model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]);
|
||||
$this->setRequestAttribute('api_key', $model);
|
||||
|
||||
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.2');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Tests\Unit\Http\Middleware\Api;
|
||||
|
||||
use Mockery as m;
|
||||
use Pterodactyl\Models\APIKey;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Auth\AuthManager;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
||||
|
@ -74,7 +74,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testValidToken()
|
||||
{
|
||||
$model = factory(APIKey::class)->make();
|
||||
$model = factory(ApiKey::class)->make();
|
||||
|
||||
$this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturn($model->identifier . 'decrypted');
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['identifier', '=', $model->identifier]])->once()->andReturn($model);
|
||||
|
@ -93,7 +93,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase
|
|||
*/
|
||||
public function testInvalidTokenForIdentifier()
|
||||
{
|
||||
$model = factory(APIKey::class)->make();
|
||||
$model = factory(ApiKey::class)->make();
|
||||
|
||||
$this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturn($model->identifier . 'asdf');
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['identifier', '=', $model->identifier]])->once()->andReturn($model);
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Tests\Unit\Services\Api;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use phpmock\phpunit\PHPMock;
|
||||
use Pterodactyl\Models\APIKey;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Services\Api\KeyCreationService;
|
||||
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
|
||||
|
@ -40,48 +40,48 @@ class KeyCreationServiceTest extends TestCase
|
|||
*/
|
||||
public function testKeyIsCreated()
|
||||
{
|
||||
$model = factory(APIKey::class)->make();
|
||||
$model = factory(ApiKey::class)->make();
|
||||
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random')
|
||||
->expects($this->exactly(2))->willReturnCallback(function ($length) {
|
||||
return 'str_' . $length;
|
||||
});
|
||||
|
||||
$this->encrypter->shouldReceive('encrypt')->with('str_' . APIKey::KEY_LENGTH)->once()->andReturn($model->token);
|
||||
$this->encrypter->shouldReceive('encrypt')->with('str_' . ApiKey::KEY_LENGTH)->once()->andReturn($model->token);
|
||||
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'test-data' => 'test',
|
||||
'identifier' => 'str_' . APIKey::IDENTIFIER_LENGTH,
|
||||
'identifier' => 'str_' . ApiKey::IDENTIFIER_LENGTH,
|
||||
'token' => $model->token,
|
||||
], true, true)->once()->andReturn($model);
|
||||
|
||||
$response = $this->getService()->handle(['test-data' => 'test']);
|
||||
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertInstanceOf(APIKey::class, $response);
|
||||
$this->assertInstanceOf(ApiKey::class, $response);
|
||||
$this->assertSame($model, $response);
|
||||
}
|
||||
|
||||
public function testIdentifierAndTokenAreOnlySetByFunction()
|
||||
{
|
||||
$model = factory(APIKey::class)->make();
|
||||
$model = factory(ApiKey::class)->make();
|
||||
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random')
|
||||
->expects($this->exactly(2))->willReturnCallback(function ($length) {
|
||||
return 'str_' . $length;
|
||||
});
|
||||
|
||||
$this->encrypter->shouldReceive('encrypt')->with('str_' . APIKey::KEY_LENGTH)->once()->andReturn($model->token);
|
||||
$this->encrypter->shouldReceive('encrypt')->with('str_' . ApiKey::KEY_LENGTH)->once()->andReturn($model->token);
|
||||
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'identifier' => 'str_' . APIKey::IDENTIFIER_LENGTH,
|
||||
'identifier' => 'str_' . ApiKey::IDENTIFIER_LENGTH,
|
||||
'token' => $model->token,
|
||||
], true, true)->once()->andReturn($model);
|
||||
|
||||
$response = $this->getService()->handle(['identifier' => 'customIdentifier', 'token' => 'customToken']);
|
||||
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertInstanceOf(APIKey::class, $response);
|
||||
$this->assertInstanceOf(ApiKey::class, $response);
|
||||
$this->assertSame($model, $response);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue