Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -52,7 +52,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that an email is not updated if the password provided in the reuqest is not
|
||||
* Tests that an email is not updated if the password provided in the request is not
|
||||
* valid for the account.
|
||||
*/
|
||||
public function testEmailIsNotUpdatedWhenPasswordIsInvalid()
|
||||
|
|
|
@ -52,7 +52,7 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase
|
|||
/** @var \Pterodactyl\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
// Small sub-test to ensure we're always comparing the number of keys to the
|
||||
// Small subtest to ensure we're always comparing the number of keys to the
|
||||
// specific logged in account, and not just the total number of keys stored in
|
||||
// the database.
|
||||
ApiKey::factory()->times(10)->create([
|
||||
|
@ -218,7 +218,7 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that an application API key also belonging to the logged in user cannot be
|
||||
* Tests that an application API key also belonging to the logged-in user cannot be
|
||||
* deleted through this endpoint if it exists.
|
||||
*/
|
||||
public function testApplicationApiKeyCannotBeDeleted()
|
||||
|
|
|
@ -7,6 +7,7 @@ use Pterodactyl\Models\Node;
|
|||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\User;
|
||||
use InvalidArgumentException;
|
||||
use Pterodactyl\Models\Model;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Database;
|
||||
|
@ -17,6 +18,7 @@ use Pterodactyl\Models\Allocation;
|
|||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Tests\Integration\TestResponse;
|
||||
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
||||
use Illuminate\Database\Eloquent\Model as EloquentModel;
|
||||
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
||||
|
||||
abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
||||
|
@ -53,27 +55,24 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
|||
|
||||
/**
|
||||
* Returns a link to the specific resource using the client API.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param string|null $append
|
||||
*/
|
||||
protected function link($model, $append = null): string
|
||||
protected function link(mixed $model, string $append = null): string
|
||||
{
|
||||
switch (get_class($model)) {
|
||||
case Server::class:
|
||||
$link = "/api/client/servers/{$model->uuid}";
|
||||
$link = "/api/client/servers/$model->uuid";
|
||||
break;
|
||||
case Schedule::class:
|
||||
$link = "/api/client/servers/{$model->server->uuid}/schedules/{$model->id}";
|
||||
$link = "/api/client/servers/{$model->server->uuid}/schedules/$model->id";
|
||||
break;
|
||||
case Task::class:
|
||||
$link = "/api/client/servers/{$model->schedule->server->uuid}/schedules/{$model->schedule->id}/tasks/{$model->id}";
|
||||
$link = "/api/client/servers/{$model->schedule->server->uuid}/schedules/{$model->schedule->id}/tasks/$model->id";
|
||||
break;
|
||||
case Allocation::class:
|
||||
$link = "/api/client/servers/{$model->server->uuid}/network/allocations/{$model->id}";
|
||||
$link = "/api/client/servers/{$model->server->uuid}/network/allocations/$model->id";
|
||||
break;
|
||||
case Backup::class:
|
||||
$link = "/api/client/servers/{$model->server->uuid}/backups/{$model->uuid}";
|
||||
$link = "/api/client/servers/{$model->server->uuid}/backups/$model->uuid";
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf('Cannot create link for Model of type %s', class_basename($model)));
|
||||
|
@ -85,10 +84,8 @@ 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 \Pterodactyl\Models\Model|\Illuminate\Database\Eloquent\Model $model
|
||||
*/
|
||||
protected function assertJsonTransformedWith(array $data, $model)
|
||||
protected function assertJsonTransformedWith(array $data, Model|EloquentModel $model)
|
||||
{
|
||||
$reflect = new ReflectionClass($model);
|
||||
$transformer = sprintf('\\Pterodactyl\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName());
|
||||
|
|
|
@ -11,7 +11,7 @@ use Pterodactyl\Models\Permission;
|
|||
class ClientControllerTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* Test that only the servers a logged in user is assigned to are returned by the
|
||||
* Test that only the servers a logged-in user is assigned to are returned by the
|
||||
* API endpoint. Obviously there are cases such as being an administrator or being
|
||||
* a subuser, but for this test we just want to test a basic scenario and pretend
|
||||
* subusers do not exist at all.
|
||||
|
@ -241,7 +241,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase
|
|||
]);
|
||||
|
||||
// Only servers 2 & 3 (0 indexed) should be returned by the API at this point. The user making
|
||||
// the request is the owner of server 0, and a subuser of server 1 so they should be exluded.
|
||||
// the request is the owner of server 0, and a subuser of server 1, so they should be excluded.
|
||||
$response = $this->actingAs($users[0])->getJson('/api/client?type=admin');
|
||||
|
||||
$response->assertOk();
|
||||
|
@ -286,10 +286,9 @@ class ClientControllerTest extends ClientApiIntegrationTestCase
|
|||
* Test that no servers get returned if the user requests all admin level servers by using
|
||||
* ?type=admin or ?type=admin-all in the request.
|
||||
*
|
||||
* @param string $type
|
||||
* @dataProvider filterTypeDataProvider
|
||||
*/
|
||||
public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser($type)
|
||||
public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser(string $type)
|
||||
{
|
||||
/** @var \Pterodactyl\Models\User[] $users */
|
||||
$users = User::factory()->times(3)->create();
|
||||
|
@ -332,10 +331,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase
|
|||
$response->assertJsonPath('data.0.attributes.relationships.allocations.data.0.attributes.notes', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function filterTypeDataProvider()
|
||||
public function filterTypeDataProvider(): array
|
||||
{
|
||||
return [['admin'], ['admin-all']];
|
||||
}
|
||||
|
|
|
@ -46,9 +46,6 @@ class AllocationAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->json($method, $this->link($server3, '/network/allocations/' . $allocation3->id . $endpoint))->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function methodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -72,7 +72,7 @@ class CreateNewAllocationTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that an allocation cannot be created if the server has reached it's allocation limit.
|
||||
* Test that an allocation cannot be created if the server has reached its allocation limit.
|
||||
*/
|
||||
public function testAllocationCannotBeCreatedIfServerIsAtLimit()
|
||||
{
|
||||
|
@ -86,10 +86,7 @@ class CreateNewAllocationTest extends ClientApiIntegrationTestCase
|
|||
->assertJsonPath('errors.0.detail', 'Cannot assign additional allocations to this server: limit has been reached.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function permissionDataProvider()
|
||||
public function permissionDataProvider(): array
|
||||
{
|
||||
return [[[Permission::ACTION_ALLOCATION_CREATE]], [[]]];
|
||||
}
|
||||
|
|
|
@ -55,9 +55,6 @@ class BackupAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->json($method, $this->link($server3, '/backups/' . $backup3->uuid . $endpoint))->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function methodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;
|
||||
|
||||
use Mockery;
|
||||
use Mockery\MockInterface;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Permission;
|
||||
|
@ -13,7 +14,7 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
|
||||
class DeleteBackupTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
private $repository;
|
||||
private MockInterface $repository;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Tests\Integration\Api\Client\Server;
|
|||
use Mockery;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use GuzzleHttp\Exception\BadResponseException;
|
||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
|
@ -14,20 +15,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
|
||||
class CommandControllerTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/** @var \Mockery\MockInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->repository = Mockery::mock(DaemonCommandRepository::class);
|
||||
$this->app->instance(DaemonCommandRepository::class, $this->repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a validation error is returned if there is no command present in the
|
||||
* request.
|
||||
|
@ -36,7 +23,7 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/command", [
|
||||
'command' => '',
|
||||
]);
|
||||
|
||||
|
@ -52,7 +39,7 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/command", [
|
||||
'command' => 'say Test',
|
||||
]);
|
||||
|
||||
|
@ -66,12 +53,14 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_CONTROL_CONSOLE]);
|
||||
|
||||
$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());
|
||||
$mock = $this->mock(DaemonCommandRepository::class);
|
||||
$mock->expects('setServer')
|
||||
->with(Mockery::on(fn (Server $value) => $value->is($server)))
|
||||
->andReturnSelf();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
|
||||
$mock->expects('send')->with('say Test')->andReturn(new GuzzleResponse());
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/command", [
|
||||
'command' => 'say Test',
|
||||
]);
|
||||
|
||||
|
@ -86,13 +75,14 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
$this->repository->expects('setServer->send')->andThrows(
|
||||
$mock = $this->mock(DaemonCommandRepository::class);
|
||||
$mock->expects('setServer->send')->andThrows(
|
||||
new DaemonConnectionException(
|
||||
new BadResponseException('', new Request('GET', 'test'), new GuzzleResponse(Response::HTTP_BAD_GATEWAY))
|
||||
)
|
||||
);
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/command", [
|
||||
'command' => 'say Test',
|
||||
]);
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Database;
|
||||
|
||||
use Mockery;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
|
@ -35,14 +34,10 @@ class DatabaseAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$database2 = Database::factory()->create(['server_id' => $server2->id, 'database_host_id' => $host->id]);
|
||||
$database3 = Database::factory()->create(['server_id' => $server3->id, 'database_host_id' => $host->id]);
|
||||
|
||||
$this->instance(DatabasePasswordService::class, $mock = Mockery::mock(DatabasePasswordService::class));
|
||||
$this->instance(DatabaseManagementService::class, $mock2 = Mockery::mock(DatabaseManagementService::class));
|
||||
|
||||
if ($method === 'POST') {
|
||||
$mock->expects('handle')->andReturnUndefined();
|
||||
} else {
|
||||
$mock2->expects('delete')->andReturnUndefined();
|
||||
}
|
||||
$this
|
||||
->mock($method === 'POST' ? DatabasePasswordService::class : DatabaseManagementService::class)
|
||||
->expects($method === 'POST' ? 'handle' : 'delete')
|
||||
->andReturn($method === 'POST' ? 'foo' : null);
|
||||
|
||||
$hashids = $this->app->make(HashidsInterface::class);
|
||||
// This is the only valid call for this test, accessing the database for the same
|
||||
|
@ -63,9 +58,6 @@ class DatabaseAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->json($method, $this->link($server3, '/databases/' . $hashids->encode($database3->id) . $endpoint))->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function methodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -133,7 +133,7 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function updatePermissionsDataProvider()
|
||||
public function updatePermissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_ALLOCATION_UPDATE]]];
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
* the command to the server.
|
||||
*
|
||||
* @param string[] $permissions
|
||||
*
|
||||
* @dataProvider invalidPermissionDataProvider
|
||||
*/
|
||||
public function testSubuserWithoutPermissionsReceivesError(string $action, array $permissions)
|
||||
|
@ -23,7 +24,7 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/power", ['signal' => $action])
|
||||
->postJson("/api/client/servers/$server->uuid/power", ['signal' => $action])
|
||||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
|
@ -34,7 +35,7 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/power", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/power", [
|
||||
'signal' => 'invalid',
|
||||
]);
|
||||
|
||||
|
@ -65,7 +66,7 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
|
|||
->with(trim($action));
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/power", ['signal' => $action])
|
||||
->postJson("/api/client/servers/$server->uuid/power", ['signal' => $action])
|
||||
->assertStatus(Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use Pterodactyl\Models\Permission;
|
|||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
||||
|
||||
class ResourceUtilitizationControllerTest extends ClientApiIntegrationTestCase
|
||||
class ResourceUtilizationControllerTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* Test that the resource utilization for a server is returned in the expected format.
|
||||
|
@ -23,7 +23,7 @@ class ResourceUtilitizationControllerTest extends ClientApiIntegrationTestCase
|
|||
return $server->uuid === $value->uuid;
|
||||
}))->andReturnSelf()->getMock()->expects('getDetails')->andReturns([]);
|
||||
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/resources");
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/$server->uuid/resources");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
|
@ -12,14 +12,13 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a schedule can be created for the server.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testScheduleCanBeCreatedForServer($permissions)
|
||||
public function testScheduleCanBeCreatedForServer(array $permissions)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/schedules", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/schedules", [
|
||||
'name' => 'Test Schedule',
|
||||
'is_active' => false,
|
||||
'minute' => '0',
|
||||
|
@ -55,17 +54,17 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/schedules", []);
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/schedules", []);
|
||||
|
||||
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
foreach (['name', 'minute', 'hour', 'day_of_month', 'day_of_week'] as $i => $field) {
|
||||
$response->assertJsonPath("errors.{$i}.code", 'ValidationException');
|
||||
$response->assertJsonPath("errors.{$i}.meta.rule", 'required');
|
||||
$response->assertJsonPath("errors.{$i}.meta.source_field", $field);
|
||||
$response->assertJsonPath("errors.$i.code", 'ValidationException');
|
||||
$response->assertJsonPath("errors.$i.meta.rule", 'required');
|
||||
$response->assertJsonPath("errors.$i.meta.source_field", $field);
|
||||
}
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules", [
|
||||
->postJson("/api/client/servers/$server->uuid/schedules", [
|
||||
'name' => 'Testing',
|
||||
'is_active' => 'no',
|
||||
'minute' => '*',
|
||||
|
@ -86,7 +85,7 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_UPDATE]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules", [])
|
||||
->postJson("/api/client/servers/$server->uuid/schedules", [])
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a schedule can be deleted from the system.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testScheduleCanBeDeleted($permissions)
|
||||
public function testScheduleCanBeDeleted(array $permissions)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
|
@ -24,7 +23,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$task = Task::factory()->create(['schedule_id' => $schedule->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
|
||||
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
|
||||
->assertStatus(Response::HTTP_NO_CONTENT);
|
||||
|
||||
$this->assertDatabaseMissing('schedules', ['id' => $schedule->id]);
|
||||
|
@ -39,7 +38,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
$this->actingAs($user)
|
||||
->deleteJson("/api/client/servers/{$server->uuid}/schedules/123456789")
|
||||
->deleteJson("/api/client/servers/$server->uuid/schedules/123456789")
|
||||
->assertStatus(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
@ -55,7 +54,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$schedule = Schedule::factory()->create(['server_id' => $server2->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
|
||||
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
|
||||
->assertStatus(Response::HTTP_NOT_FOUND);
|
||||
|
||||
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
|
||||
|
@ -72,7 +71,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
|
||||
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
|
||||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
|
||||
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
|
||||
|
|
|
@ -23,11 +23,9 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that schedules for a server are returned.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param bool $individual
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testServerSchedulesAreReturned($permissions, $individual)
|
||||
public function testServerSchedulesAreReturned(array $permissions, bool $individual)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
|
@ -39,8 +37,8 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
$response = $this->actingAs($user)
|
||||
->getJson(
|
||||
$individual
|
||||
? "/api/client/servers/{$server->uuid}/schedules/{$schedule->id}"
|
||||
: "/api/client/servers/{$server->uuid}/schedules"
|
||||
? "/api/client/servers/$server->uuid/schedules/$schedule->id"
|
||||
: "/api/client/servers/$server->uuid/schedules"
|
||||
)
|
||||
->assertOk();
|
||||
|
||||
|
@ -69,7 +67,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
$schedule = Schedule::factory()->create(['server_id' => $server2->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
|
||||
->getJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
|
@ -81,13 +79,13 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
|
|||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson("/api/client/servers/{$server->uuid}/schedules")
|
||||
->getJson("/api/client/servers/$server->uuid/schedules")
|
||||
->assertForbidden();
|
||||
|
||||
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->getJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}")
|
||||
->getJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,6 @@ class ScheduleAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->json($method, $this->link($server3, '/schedules/' . $schedule3->id . $endpoint))->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function methodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -11,10 +11,8 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
/**
|
||||
* The data to use when updating a schedule.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $updateData = [
|
||||
private array $updateData = [
|
||||
'name' => 'Updated Schedule Name',
|
||||
'minute' => '5',
|
||||
'hour' => '*',
|
||||
|
@ -27,10 +25,9 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a schedule can be updated.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testScheduleCanBeUpdated($permissions)
|
||||
public function testScheduleCanBeUpdated(array $permissions)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
|
@ -48,7 +45,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$this->assertFalse($schedule->is_active);
|
||||
$this->assertJsonTransformedWith($response->json('attributes'), $schedule);
|
||||
|
||||
$this->assertSame($expected->toIso8601String(), $schedule->next_run_at->toIso8601String());
|
||||
$this->assertSame($expected->toAtomString(), $schedule->next_run_at->toAtomString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,10 +13,9 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a task can be created.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testTaskCanBeCreated($permissions)
|
||||
public function testTaskCanBeCreated(array $permissions)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
|
@ -56,8 +55,8 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
$response = $this->actingAs($user)->postJson($this->link($schedule, '/tasks'))->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
|
||||
foreach (['action', 'payload', 'time_offset'] as $i => $field) {
|
||||
$response->assertJsonPath("errors.{$i}.meta.rule", $field === 'payload' ? 'required_unless' : 'required');
|
||||
$response->assertJsonPath("errors.{$i}.meta.source_field", $field);
|
||||
$response->assertJsonPath("errors.$i.meta.rule", $field === 'payload' ? 'required_unless' : 'required');
|
||||
$response->assertJsonPath("errors.$i.meta.source_field", $field);
|
||||
}
|
||||
|
||||
$this->actingAs($user)->postJson($this->link($schedule, '/tasks'), [
|
||||
|
@ -151,7 +150,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
$schedule = Schedule::factory()->create(['server_id' => $server2->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}/tasks")
|
||||
->postJson("/api/client/servers/$server->uuid/schedules/$schedule->id/tasks")
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
|
||||
/**
|
||||
* Test that an error is returned if the task and schedule in the URL do not line up
|
||||
* with eachother.
|
||||
* with each other.
|
||||
*/
|
||||
public function testTaskBelongingToDifferentScheduleReturnsError()
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase
|
|||
$schedule2 = Schedule::factory()->create(['server_id' => $server->id]);
|
||||
$task = Task::factory()->create(['schedule_id' => $schedule->id]);
|
||||
|
||||
$this->actingAs($user)->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule2->id}/tasks/{$task->id}")->assertNotFound();
|
||||
$this->actingAs($user)->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule2->id/tasks/$task->id")->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,16 +14,15 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that the server's name can be changed.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider renamePermissionsDataProvider
|
||||
*/
|
||||
public function testServerNameCanBeChanged($permissions)
|
||||
public function testServerNameCanBeChanged(array $permissions)
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
$originalName = $server->name;
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/settings/rename", [
|
||||
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||
'name' => '',
|
||||
]);
|
||||
|
||||
|
@ -34,7 +33,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
$this->assertSame($originalName, $server->name);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/settings/rename", [
|
||||
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||
'name' => 'Test Server Name',
|
||||
])
|
||||
->assertStatus(Response::HTTP_NO_CONTENT);
|
||||
|
@ -53,7 +52,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
$originalName = $server->name;
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/settings/rename", [
|
||||
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
||||
'name' => 'Test Server Name',
|
||||
])
|
||||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
|
@ -66,10 +65,9 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
* Test that a server can be reinstalled. Honestly this test doesn't do much of anything other
|
||||
* than make sure the endpoint works since.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider reinstallPermissionsDataProvider
|
||||
*/
|
||||
public function testServerCanBeReinstalled($permissions)
|
||||
public function testServerCanBeReinstalled(array $permissions)
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
@ -87,7 +85,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
->expects('reinstall')
|
||||
->andReturnUndefined();
|
||||
|
||||
$this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/settings/reinstall")
|
||||
$this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/reinstall")
|
||||
->assertStatus(Response::HTTP_ACCEPTED);
|
||||
|
||||
$server = $server->refresh();
|
||||
|
@ -103,7 +101,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/settings/reinstall")
|
||||
->postJson("/api/client/servers/$server->uuid/settings/reinstall")
|
||||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
|
||||
$server = $server->refresh();
|
||||
|
|
|
@ -13,16 +13,15 @@ class GetStartupAndVariablesTest extends ClientApiIntegrationTestCase
|
|||
* Test that the startup command and variables are returned for a server, but only the variables
|
||||
* that can be viewed by a user (e.g. user_viewable=true).
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testStartupVariablesAreReturnedForServer($permissions)
|
||||
public function testStartupVariablesAreReturnedForServer(array $permissions)
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
$egg = $this->cloneEggAndVariables($server->egg);
|
||||
// BUNGEE_VERSION should never be returned back to the user in this API call, either in
|
||||
// BUNGEE_VERSION should never be returned to the user in this API call, either in
|
||||
// the array of variables, or revealed in the startup command.
|
||||
$egg->variables()->first()->update([
|
||||
'user_viewable' => false,
|
||||
|
@ -59,10 +58,7 @@ class GetStartupAndVariablesTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user2)->getJson($this->link($server) . '/startup')->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function permissionsDataProvider()
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_STARTUP_READ]]];
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a startup variable can be edited successfully for a server.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testStartupVariableCanBeUpdated($permissions)
|
||||
public function testStartupVariableCanBeUpdated(array $permissions)
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
@ -150,10 +149,7 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user2)->putJson($this->link($server) . '/startup/variable')->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
public function permissionsDataProvider()
|
||||
public function permissionsDataProvider(): array
|
||||
{
|
||||
return [[[]], [[Permission::ACTION_STARTUP_UPDATE]]];
|
||||
}
|
||||
|
|
|
@ -17,10 +17,9 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase
|
|||
/**
|
||||
* Test that a subuser can be created for a server.
|
||||
*
|
||||
* @param array $permissions
|
||||
* @dataProvider permissionsDataProvider
|
||||
*/
|
||||
public function testSubuserCanBeCreated($permissions)
|
||||
public function testSubuserCanBeCreated(array $permissions)
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
|
@ -62,7 +61,7 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase
|
|||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson($this->link($server) . '/users', [
|
||||
'email' => $email = $this->faker->email,
|
||||
'email' => $this->faker->email,
|
||||
'permissions' => [
|
||||
Permission::ACTION_USER_CREATE,
|
||||
Permission::ACTION_USER_UPDATE, // This permission is not assigned to the subuser.
|
||||
|
|
|
@ -47,7 +47,7 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase
|
|||
|
||||
$mock->expects('setServer->revokeUserJTI')->with($subuser->id)->andReturnUndefined();
|
||||
|
||||
$this->actingAs($user)->deleteJson($this->link($server) . "/users/{$subuser->uuid}")->assertNoContent();
|
||||
$this->actingAs($user)->deleteJson($this->link($server) . "/users/$subuser->uuid")->assertNoContent();
|
||||
|
||||
// Try the same test, but this time with a UUID that if cast to an int (shouldn't) line up with
|
||||
// anything in the database.
|
||||
|
@ -63,6 +63,6 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase
|
|||
|
||||
$mock->expects('setServer->revokeUserJTI')->with($subuser->id)->andReturnUndefined();
|
||||
|
||||
$this->actingAs($user)->deleteJson($this->link($server) . "/users/{$subuser->uuid}")->assertNoContent();
|
||||
$this->actingAs($user)->deleteJson($this->link($server) . "/users/$subuser->uuid")->assertNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,6 @@ class SubuserAuthorizationTest extends ClientApiIntegrationTestCase
|
|||
$this->actingAs($user)->json($method, $this->link($server3, '/users/' . $internal->uuid))->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function methodDataProvider(): array
|
||||
{
|
||||
return [['GET'], ['POST'], ['DELETE']];
|
||||
|
|
|
@ -14,14 +14,14 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* Test that a subuser attempting to connect to the websocket recieves an error if they
|
||||
* Test that a subuser attempting to connect to the websocket receives an error if they
|
||||
* do not explicitly have the permission.
|
||||
*/
|
||||
public function testSubuserWithoutWebsocketPermissionReceivesError()
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount([Permission::ACTION_CONTROL_RESTART]);
|
||||
|
||||
$this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/websocket")
|
||||
$this->actingAs($user)->getJson("/api/client/servers/$server->uuid/websocket")
|
||||
->assertStatus(Response::HTTP_FORBIDDEN)
|
||||
->assertJsonPath('errors.0.code', 'HttpForbiddenException')
|
||||
->assertJsonPath('errors.0.detail', 'You do not have permission to connect to this server\'s websocket.');
|
||||
|
@ -33,9 +33,9 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
|||
public function testUserWithoutPermissionForServerReceivesError()
|
||||
{
|
||||
[, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
[$user,] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
[$user] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
||||
|
||||
$this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/websocket")
|
||||
$this->actingAs($user)->getJson("/api/client/servers/$server->uuid/websocket")
|
||||
->assertStatus(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
@ -53,14 +53,14 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
|||
$server->node->scheme = 'https';
|
||||
$server->node->save();
|
||||
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/websocket");
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/$server->uuid/websocket");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure(['data' => ['token', 'socket']]);
|
||||
|
||||
$connection = $response->json('data.socket');
|
||||
$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.');
|
||||
$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));
|
||||
|
@ -102,7 +102,7 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
|
|||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/websocket");
|
||||
$response = $this->actingAs($user)->getJson("/api/client/servers/$server->uuid/websocket");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure(['data' => ['token', 'socket']]);
|
||||
|
|
|
@ -122,7 +122,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that two factor authentication can be disabled on an account as long as the password
|
||||
* Test that two-factor authentication can be disabled on an account as long as the password
|
||||
* provided is valid for the account.
|
||||
*/
|
||||
public function testTwoFactorCanBeDisabledOnAccount()
|
||||
|
@ -149,7 +149,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase
|
|||
$user = $user->refresh();
|
||||
$this->assertFalse($user->use_totp);
|
||||
$this->assertNotNull($user->totp_authenticated_at);
|
||||
$this->assertSame(Carbon::now()->toIso8601String(), $user->totp_authenticated_at->toIso8601String());
|
||||
$this->assertSame(Carbon::now()->toAtomString(), $user->totp_authenticated_at->toAtomString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue