forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsControllerTest.php
More file actions
128 lines (107 loc) · 4.28 KB
/
SettingsControllerTest.php
File metadata and controls
128 lines (107 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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);
$response->assertJsonPath('errors.0.code', 'required');
$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);
$this->assertSame(Server::STATUS_INSTALLED, $server->installed);
$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();
$this->assertSame(Server::STATUS_INSTALLING, $server->installed);
}
/**
* 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();
$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]]];
}
}