Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Startup/GetStartupAndVariablesTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Client\Server\Startup;34use Pterodactyl\Models\User;5use Pterodactyl\Models\Permission;6use Pterodactyl\Models\EggVariable;7use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;89class GetStartupAndVariablesTest extends ClientApiIntegrationTestCase10{11/**12* Test that the startup command and variables are returned for a server, but only the variables13* that can be viewed by a user (e.g. user_viewable=true).14*/15#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]16public function testStartupVariablesAreReturnedForServer(array $permissions)17{18/** @var \Pterodactyl\Models\Server $server */19[$user, $server] = $this->generateTestAccount($permissions);2021$egg = $this->cloneEggAndVariables($server->egg);22// BUNGEE_VERSION should never be returned to the user in this API call, either in23// the array of variables, or revealed in the startup command.24$egg->variables()->first()->update([25'user_viewable' => false,26]);2728$server->fill([29'egg_id' => $egg->id,30'startup' => 'java {{SERVER_JARFILE}} --version {{BUNGEE_VERSION}}',31])->save();32$server = $server->refresh();3334$response = $this->actingAs($user)->getJson($this->link($server) . '/startup');3536$response->assertOk();37$response->assertJsonPath('meta.startup_command', 'java bungeecord.jar --version [hidden]');38$response->assertJsonPath('meta.raw_startup_command', $server->startup);3940$response->assertJsonPath('object', 'list');41$response->assertJsonCount(1, 'data');42$response->assertJsonPath('data.0.object', EggVariable::RESOURCE_NAME);43$this->assertJsonTransformedWith($response->json('data.0.attributes'), $egg->variables[1]);44}4546/**47* Test that a user without the required permission, or who does not have any permission to48* access the server cannot get the startup information for it.49*/50public function testStartupDataIsNotReturnedWithoutPermission()51{52[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);53$this->actingAs($user)->getJson($this->link($server) . '/startup')->assertForbidden();5455$user2 = User::factory()->create();56$this->actingAs($user2)->getJson($this->link($server) . '/startup')->assertNotFound();57}5859public static function permissionsDataProvider(): array60{61return [[[]], [[Permission::ACTION_STARTUP_READ]]];62}63}646566