2020-06-28 17:40:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration\Api\Client\Server;
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Models\Permission;
|
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
|
|
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|
|
|
|
|
|
|
class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test that the server's name can be changed.
|
|
|
|
*
|
|
|
|
* @dataProvider renamePermissionsDataProvider
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function testServerNameCanBeChanged(array $permissions)
|
2020-06-28 17:40:41 +00:00
|
|
|
{
|
|
|
|
/** @var \Pterodactyl\Models\Server $server */
|
|
|
|
[$user, $server] = $this->generateTestAccount($permissions);
|
|
|
|
$originalName = $server->name;
|
2022-10-31 16:20:53 +00:00
|
|
|
$originalDescription = $server->description;
|
2020-06-28 17:40:41 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
$response = $this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
2020-06-28 17:40:41 +00:00
|
|
|
'name' => '',
|
2022-10-31 16:20:53 +00:00
|
|
|
'description' => '',
|
2020-06-28 17:40:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
|
2020-08-28 04:19:01 +00:00
|
|
|
$response->assertJsonPath('errors.0.meta.rule', 'required');
|
2020-06-28 17:40:41 +00:00
|
|
|
|
|
|
|
$server = $server->refresh();
|
|
|
|
$this->assertSame($originalName, $server->name);
|
2022-10-31 16:20:53 +00:00
|
|
|
$this->assertSame($originalDescription, $server->description);
|
2020-06-28 17:40:41 +00:00
|
|
|
|
|
|
|
$this->actingAs($user)
|
2022-10-14 16:59:20 +00:00
|
|
|
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
2020-06-28 17:40:41 +00:00
|
|
|
'name' => 'Test Server Name',
|
2022-10-31 16:20:53 +00:00
|
|
|
'description' => 'This is a test server.',
|
2020-06-28 17:40:41 +00:00
|
|
|
])
|
|
|
|
->assertStatus(Response::HTTP_NO_CONTENT);
|
|
|
|
|
|
|
|
$server = $server->refresh();
|
|
|
|
$this->assertSame('Test Server Name', $server->name);
|
2022-10-31 16:20:53 +00:00
|
|
|
$this->assertSame('This is a test server.', $server->description);
|
2020-06-28 17:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a subuser receives a permissions error if they do not have the required permission
|
|
|
|
* and attempt to change the name.
|
|
|
|
*/
|
|
|
|
public function testSubuserCannotChangeServerNameWithoutPermission()
|
|
|
|
{
|
|
|
|
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
|
|
|
$originalName = $server->name;
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
2022-10-14 16:59:20 +00:00
|
|
|
->postJson("/api/client/servers/$server->uuid/settings/rename", [
|
2020-06-28 17:40:41 +00:00
|
|
|
'name' => 'Test Server Name',
|
|
|
|
])
|
|
|
|
->assertStatus(Response::HTTP_FORBIDDEN);
|
|
|
|
|
|
|
|
$server = $server->refresh();
|
|
|
|
$this->assertSame($originalName, $server->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a server can be reinstalled. Honestly this test doesn't do much of anything other
|
|
|
|
* than make sure the endpoint works since.
|
|
|
|
*
|
|
|
|
* @dataProvider reinstallPermissionsDataProvider
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function testServerCanBeReinstalled(array $permissions)
|
2020-06-28 17:40:41 +00:00
|
|
|
{
|
|
|
|
/** @var \Pterodactyl\Models\Server $server */
|
|
|
|
[$user, $server] = $this->generateTestAccount($permissions);
|
2021-01-17 23:51:56 +00:00
|
|
|
$this->assertTrue($server->isInstalled());
|
2020-06-28 17:40:41 +00:00
|
|
|
|
2022-11-29 17:53:59 +00:00
|
|
|
$service = \Mockery::mock(DaemonServerRepository::class);
|
2020-06-28 17:40:41 +00:00
|
|
|
$this->app->instance(DaemonServerRepository::class, $service);
|
|
|
|
|
|
|
|
$service->expects('setServer')
|
2022-11-29 17:53:59 +00:00
|
|
|
->with(\Mockery::on(function ($value) use ($server) {
|
2020-06-28 17:40:41 +00:00
|
|
|
return $value->uuid === $server->uuid;
|
|
|
|
}))
|
|
|
|
->andReturnSelf()
|
|
|
|
->getMock()
|
|
|
|
->expects('reinstall')
|
|
|
|
->andReturnUndefined();
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
$this->actingAs($user)->postJson("/api/client/servers/$server->uuid/settings/reinstall")
|
2020-06-28 17:40:41 +00:00
|
|
|
->assertStatus(Response::HTTP_ACCEPTED);
|
|
|
|
|
|
|
|
$server = $server->refresh();
|
2021-01-17 23:51:56 +00:00
|
|
|
$this->assertSame(Server::STATUS_INSTALLING, $server->status);
|
2020-06-28 17:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a subuser receives a permissions error if they do not have the required permission
|
|
|
|
* and attempt to reinstall a server.
|
|
|
|
*/
|
|
|
|
public function testSubuserCannotReinstallServerWithoutPermission()
|
|
|
|
{
|
|
|
|
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
2022-10-14 16:59:20 +00:00
|
|
|
->postJson("/api/client/servers/$server->uuid/settings/reinstall")
|
2020-06-28 17:40:41 +00:00
|
|
|
->assertStatus(Response::HTTP_FORBIDDEN);
|
|
|
|
|
|
|
|
$server = $server->refresh();
|
2021-01-17 23:51:56 +00:00
|
|
|
$this->assertTrue($server->isInstalled());
|
2020-06-28 17:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function renamePermissionsDataProvider(): array
|
|
|
|
{
|
|
|
|
return [[[]], [[Permission::ACTION_SETTINGS_RENAME]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reinstallPermissionsDataProvider(): array
|
|
|
|
{
|
|
|
|
return [[[]], [[Permission::ACTION_SETTINGS_REINSTALL]]];
|
|
|
|
}
|
|
|
|
}
|