2020-06-28 17:40:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration\Api\Client\Server;
|
|
|
|
|
|
|
|
use Mockery;
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param array $permissions
|
|
|
|
* @dataProvider renamePermissionsDataProvider
|
|
|
|
*/
|
|
|
|
public function testServerNameCanBeChanged($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", [
|
|
|
|
'name' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
|
|
|
->postJson("/api/client/servers/{$server->uuid}/settings/rename", [
|
|
|
|
'name' => 'Test Server Name',
|
|
|
|
])
|
|
|
|
->assertStatus(Response::HTTP_NO_CONTENT);
|
|
|
|
|
|
|
|
$server = $server->refresh();
|
|
|
|
$this->assertSame('Test Server Name', $server->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
->postJson("/api/client/servers/{$server->uuid}/settings/rename", [
|
|
|
|
'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.
|
|
|
|
*
|
|
|
|
* @param array $permissions
|
|
|
|
* @dataProvider reinstallPermissionsDataProvider
|
|
|
|
*/
|
|
|
|
public function testServerCanBeReinstalled($permissions)
|
|
|
|
{
|
|
|
|
/** @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
|
|
|
|
|
|
|
$service = Mockery::mock(DaemonServerRepository::class);
|
|
|
|
$this->app->instance(DaemonServerRepository::class, $service);
|
|
|
|
|
|
|
|
$service->expects('setServer')
|
|
|
|
->with(Mockery::on(function ($value) use ($server) {
|
|
|
|
return $value->uuid === $server->uuid;
|
|
|
|
}))
|
|
|
|
->andReturnSelf()
|
|
|
|
->getMock()
|
|
|
|
->expects('reinstall')
|
|
|
|
->andReturnUndefined();
|
|
|
|
|
|
|
|
$this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/settings/reinstall")
|
|
|
|
->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)
|
|
|
|
->postJson("/api/client/servers/{$server->uuid}/settings/reinstall")
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function renamePermissionsDataProvider(): array
|
|
|
|
{
|
|
|
|
return [[[]], [[Permission::ACTION_SETTINGS_RENAME]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function reinstallPermissionsDataProvider(): array
|
|
|
|
{
|
|
|
|
return [[[]], [[Permission::ACTION_SETTINGS_REINSTALL]]];
|
|
|
|
}
|
|
|
|
}
|