Skip to content

Commit 40d4459

Browse files
committed
Add test coverage for change to endpoint
1 parent a4abb25 commit 40d4459

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

tests/Integration/Api/Client/ClientControllerTest.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,43 @@ public function testOnlyAdminLevelServersAreReturned()
153153
$response->assertJsonPath('data.1.attributes.identifier', $servers[3]->uuidShort);
154154
}
155155

156+
/**
157+
* Test that all servers a user can access as an admin are returned if using ?filter=admin-all.
158+
*/
159+
public function testAllServersAreReturnedToAdmin()
160+
{
161+
/** @var \Pterodactyl\Models\User[] $users */
162+
$users = factory(User::class)->times(4)->create();
163+
$users[0]->update(['root_admin' => true]);
164+
165+
$servers = [
166+
$this->createServerModel(['user_id' => $users[0]->id]),
167+
$this->createServerModel(['user_id' => $users[1]->id]),
168+
$this->createServerModel(['user_id' => $users[2]->id]),
169+
$this->createServerModel(['user_id' => $users[3]->id]),
170+
];
171+
172+
Subuser::query()->create([
173+
'user_id' => $users[0]->id,
174+
'server_id' => $servers[1]->id,
175+
'permissions' => [Permission::ACTION_WEBSOCKET_CONNECT],
176+
]);
177+
178+
// All servers should be returned.
179+
$response = $this->actingAs($users[0])->getJson('/api/client?type=admin-all');
180+
181+
$response->assertOk();
182+
$response->assertJsonCount(4, 'data');
183+
}
184+
156185
/**
157186
* Test that no servers get returned if the user requests all admin level servers by using
158-
* ?type=admin in the request.
187+
* ?type=admin or ?type=admin-all in the request.
188+
*
189+
* @param string $type
190+
* @dataProvider filterTypeDataProvider
159191
*/
160-
public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser()
192+
public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser($type)
161193
{
162194
/** @var \Pterodactyl\Models\User[] $users */
163195
$users = factory(User::class)->times(3)->create();
@@ -166,9 +198,17 @@ public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser()
166198
$this->createServerModel(['user_id' => $users[1]->id]);
167199
$this->createServerModel(['user_id' => $users[2]->id]);
168200

169-
$response = $this->actingAs($users[0])->getJson('/api/client?type=admin');
201+
$response = $this->actingAs($users[0])->getJson('/api/client?type=' . $type);
170202

171203
$response->assertOk();
172204
$response->assertJsonCount(0, 'data');
173205
}
206+
207+
/**
208+
* @return array
209+
*/
210+
public function filterTypeDataProvider()
211+
{
212+
return [['admin'], ['admin-all']];
213+
}
174214
}

0 commit comments

Comments
 (0)