Use more standardized phpcs
This commit is contained in:
parent
a043071e3c
commit
c449ca5155
493 changed files with 1116 additions and 3903 deletions
|
@ -15,7 +15,9 @@ use Pterodactyl\Tests\Traits\Http\IntegrationJsonRequestAssertions;
|
|||
|
||||
abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
||||
{
|
||||
use CreatesTestModels, DatabaseTransactions, IntegrationJsonRequestAssertions;
|
||||
use CreatesTestModels;
|
||||
use DatabaseTransactions;
|
||||
use IntegrationJsonRequestAssertions;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Models\ApiKey
|
||||
|
@ -44,17 +46,11 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
$this->withMiddleware('api..key:' . ApiKey::TYPE_APPLICATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Pterodactyl\Models\User
|
||||
*/
|
||||
public function getApiUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Pterodactyl\Models\ApiKey
|
||||
*/
|
||||
public function getApiKey(): ApiKey
|
||||
{
|
||||
return $this->key;
|
||||
|
@ -62,10 +58,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Creates a new default API key and refreshes the headers using it.
|
||||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param array $permissions
|
||||
* @return \Pterodactyl\Models\ApiKey
|
||||
*/
|
||||
protected function createNewDefaultApiKey(User $user, array $permissions = []): ApiKey
|
||||
{
|
||||
|
@ -77,8 +69,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Refresh the authorization header for a request to use a different API key.
|
||||
*
|
||||
* @param \Pterodactyl\Models\ApiKey $key
|
||||
*/
|
||||
protected function refreshHeaders(ApiKey $key)
|
||||
{
|
||||
|
@ -87,8 +77,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Create an administrative user.
|
||||
*
|
||||
* @return \Pterodactyl\Models\User
|
||||
*/
|
||||
protected function createApiUser(): User
|
||||
{
|
||||
|
@ -99,10 +87,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Create a new application API key for a given user model.
|
||||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param array $permissions
|
||||
* @return \Pterodactyl\Models\ApiKey
|
||||
*/
|
||||
protected function createApiKey(User $user, array $permissions = []): ApiKey
|
||||
{
|
||||
|
@ -123,9 +107,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Return a transformer that can be used for testing purposes.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
||||
*/
|
||||
protected function getTransformer(string $abstract): BaseTransformer
|
||||
{
|
||||
|
|
|
@ -61,7 +61,9 @@ class EggControllerTest extends ApplicationApiIntegrationTestCase
|
|||
$expected = json_encode(Arr::sortRecursive($datum['attributes']));
|
||||
$actual = json_encode(Arr::sortRecursive($this->getTransformer(EggTransformer::class)->transform($egg)));
|
||||
|
||||
$this->assertSame($expected, $actual,
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$actual,
|
||||
'Unable to find JSON fragment: ' . PHP_EOL . PHP_EOL . "[{$expected}]" . PHP_EOL . PHP_EOL . 'within' . PHP_EOL . PHP_EOL . "[{$actual}]."
|
||||
);
|
||||
}
|
||||
|
|
|
@ -292,9 +292,6 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
|
|||
* Test that an API key without write permissions cannot create, update, or
|
||||
* delete a user model.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
*
|
||||
* @dataProvider userWriteEndpointsDataProvider
|
||||
*/
|
||||
public function testApiKeyWithoutWritePermissions(string $method, string $url)
|
||||
|
@ -313,8 +310,6 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
|
|||
/**
|
||||
* Endpoints that should return a 403 error when the key does not have write
|
||||
* permissions for user management.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function userWriteEndpointsDataProvider(): array
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
* to keep re-assigning variables.
|
||||
*
|
||||
* @param \Illuminate\Http\Response $response
|
||||
*
|
||||
* @return \Illuminate\Testing\TestResponse
|
||||
*/
|
||||
protected function createTestResponse($response)
|
||||
|
@ -54,10 +55,8 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
/**
|
||||
* Returns a link to the specific resource using the client API.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param mixed $model
|
||||
* @param string|null $append
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function link($model, $append = null): string
|
||||
{
|
||||
|
@ -87,8 +86,6 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
* is assumed that the user is actually a subuser of the server.
|
||||
*
|
||||
* @param string[] $permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function generateTestAccount(array $permissions = []): array
|
||||
{
|
||||
|
@ -115,7 +112,6 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
* Asserts that the data passed through matches the output of the data from the transformer. This
|
||||
* will remove the "relationships" key when performing the comparison.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Pterodactyl\Models\Model|\Illuminate\Database\Eloquent\Model $model
|
||||
*/
|
||||
protected function assertJsonTransformedWith(array $data, $model)
|
||||
|
@ -123,7 +119,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
$reflect = new ReflectionClass($model);
|
||||
$transformer = sprintf('\\Pterodactyl\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName());
|
||||
|
||||
$transformer = new $transformer;
|
||||
$transformer = new $transformer();
|
||||
$this->assertInstanceOf(BaseClientTransformer::class, $transformer);
|
||||
|
||||
$this->assertSame(
|
||||
|
|
|
@ -9,8 +9,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
class AllocationAuthorizationTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @dataProvider methodDataProvider
|
||||
*/
|
||||
public function testAccessToAServersAllocationsIsRestrictedProperly(string $method, string $endpoint)
|
||||
|
|
|
@ -24,7 +24,6 @@ class CreateNewAllocationTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Tests that a new allocation can be properly assigned to a server.
|
||||
*
|
||||
* @param array $permission
|
||||
* @dataProvider permissionDataProvider
|
||||
*/
|
||||
public function testNewAllocationCanBeAssignedToServer(array $permission)
|
||||
|
|
|
@ -13,7 +13,6 @@ class DeleteAllocationTest extends ClientApiIntegrationTestCase
|
|||
* Test that an allocation is deleted from the server and the notes are properly reset
|
||||
* to an empty value on assignment.
|
||||
*
|
||||
* @param array $permission
|
||||
* @dataProvider permissionDataProvider
|
||||
*/
|
||||
public function testAllocationCanBeDeletedFromServer(array $permission)
|
||||
|
|
|
@ -12,8 +12,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
class BackupAuthorizationTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @dataProvider methodDataProvider
|
||||
*/
|
||||
public function testAccessToAServersBackupIsRestrictedProperly(string $method, string $endpoint)
|
||||
|
|
|
@ -69,7 +69,7 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
|
|||
$this->repository->expects('setServer')->with(Mockery::on(function ($value) use ($server) {
|
||||
return $value->uuid === $server->uuid;
|
||||
}))->andReturnSelf();
|
||||
$this->repository->expects('send')->with('say Test')->andReturn(new GuzzleResponse);
|
||||
$this->repository->expects('send')->with('say Test')->andReturn(new GuzzleResponse());
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
|
||||
'command' => 'say Test',
|
||||
|
|
|
@ -14,8 +14,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
class DatabaseAuthorizationTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @dataProvider methodDataProvider
|
||||
*/
|
||||
public function testAccessToAServersDatabasesIsRestrictedProperly(string $method, string $endpoint)
|
||||
|
|
|
@ -49,7 +49,6 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Tests that notes on an allocation can be set correctly.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider updatePermissionsDataProvider
|
||||
*/
|
||||
public function testAllocationNotesCanBeUpdated(array $permissions)
|
||||
|
@ -98,7 +97,6 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $permissions
|
||||
* @dataProvider updatePermissionsDataProvider
|
||||
*/
|
||||
public function testPrimaryAllocationCanBeModified(array $permissions)
|
||||
|
|
|
@ -15,7 +15,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
* an error in response. This checks against the specific permission needed to send
|
||||
* the command to the server.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string[] $permissions
|
||||
* @dataProvider invalidPermissionDataProvider
|
||||
*/
|
||||
|
@ -47,8 +46,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that sending a valid power actions works.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $permission
|
||||
* @dataProvider validPowerActionDataProvider
|
||||
*/
|
||||
public function testActionCanBeSentToServer(string $action, string $permission)
|
||||
|
@ -74,8 +71,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
|
||||
/**
|
||||
* Returns invalid permission combinations for a given power action.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function invalidPermissionDataProvider(): array
|
||||
{
|
||||
|
@ -88,9 +83,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validPowerActionDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -90,9 +90,6 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SCHEDULE_CREATE]]];
|
||||
|
|
|
@ -78,9 +78,6 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SCHEDULE_DELETE]]];
|
||||
|
|
|
@ -15,7 +15,6 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a schedule can be executed and is updated in the database correctly.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testScheduleIsExecutedRightAway(array $permissions)
|
||||
|
@ -85,9 +84,6 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->postJson($this->link($schedule, '/execute'))->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];
|
||||
|
|
|
@ -24,7 +24,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
* Test that schedules for a server are returned.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param bool $individual
|
||||
* @param bool $individual
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testServerSchedulesAreReturned($permissions, $individual)
|
||||
|
@ -45,7 +45,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
->assertOk();
|
||||
|
||||
$prefix = $individual ? '' : 'data.0.';
|
||||
if (! $individual) {
|
||||
if (!$individual) {
|
||||
$response->assertJsonCount(1, 'data');
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,6 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -17,8 +17,6 @@ class ScheduleAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
* The comments within the test code itself are better at explaining exactly what is
|
||||
* being tested and protected against.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @dataProvider methodDataProvider
|
||||
*/
|
||||
public function testAccessToAServersSchedulesIsRestrictedProperly(string $method, string $endpoint)
|
||||
|
|
|
@ -112,9 +112,6 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$this->assertFalse($schedule->is_processing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];
|
||||
|
|
|
@ -167,9 +167,6 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];
|
||||
|
|
|
@ -110,17 +110,11 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
$this->assertSame(Server::STATUS_INSTALLED, $server->installed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function renamePermissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SETTINGS_RENAME]]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function reinstallPermissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_SETTINGS_REINSTALL]]];
|
||||
|
|
|
@ -49,7 +49,6 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase
|
|||
* Test that variables that are either not user_viewable, or not user_editable, cannot be
|
||||
* updated via this endpoint.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testStartupVariableCannotBeUpdatedIfNotUserViewableOrEditable(array $permissions)
|
||||
|
|
|
@ -156,9 +156,6 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase
|
|||
$response->assertJsonPath('errors.0.detail', 'A user with that email address is already assigned as a subuser for this server.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_USER_CREATE]]];
|
||||
|
|
|
@ -13,7 +13,6 @@ class SubuserAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that mismatched subusers are not accessible to a server.
|
||||
*
|
||||
* @param string $method
|
||||
* @dataProvider methodDataProvider
|
||||
*/
|
||||
public function testUserCannotAccessResourceBelongingToOtherServers(string $method)
|
||||
|
|
|
@ -50,8 +50,8 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
|||
$this->assertStringStartsWith('wss://', $connection, 'Failed asserting that websocket connection address has expected "wss://" prefix.');
|
||||
$this->assertStringEndsWith("/api/servers/{$server->uuid}/ws", $connection, 'Failed asserting that websocket connection address uses expected Wings endpoint.');
|
||||
|
||||
$config = Configuration::forSymmetricSigner(new Sha256, $key = InMemory::plainText($server->node->getDecryptedKey()));
|
||||
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
|
||||
$config = Configuration::forSymmetricSigner(new Sha256(), $key = InMemory::plainText($server->node->getDecryptedKey()));
|
||||
$config->setValidationConstraints(new SignedWith(new Sha256(), $key));
|
||||
/** @var \Lcobucci\JWT\Token\Plain $token */
|
||||
$token = $config->parser()->parse($response->json('data.token'));
|
||||
|
||||
|
@ -95,8 +95,8 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
|||
$response->assertOk();
|
||||
$response->assertJsonStructure(['data' => ['token', 'socket']]);
|
||||
|
||||
$config = Configuration::forSymmetricSigner(new Sha256, $key = InMemory::plainText($server->node->getDecryptedKey()));
|
||||
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
|
||||
$config = Configuration::forSymmetricSigner(new Sha256(), $key = InMemory::plainText($server->node->getDecryptedKey()));
|
||||
$config->setValidationConstraints(new SignedWith(new Sha256(), $key));
|
||||
/** @var \Lcobucci\JWT\Token\Plain $token */
|
||||
$token = $config->parser()->parse($response->json('data.token'));
|
||||
|
||||
|
|
|
@ -111,9 +111,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
}
|
||||
|
||||
throw new ExpectationFailedException(
|
||||
sprintf('Failed asserting that token [%s] exists as a hashed value in recovery_tokens table.', $raw)
|
||||
);
|
||||
throw new ExpectationFailedException(sprintf('Failed asserting that token [%s] exists as a hashed value in recovery_tokens table.', $raw));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue