2018-03-04 22:56:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration\Api\Application\Users;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
2018-03-05 04:35:57 +00:00
|
|
|
use Illuminate\Http\Response;
|
2018-03-04 22:56:05 +00:00
|
|
|
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
|
|
|
|
|
|
|
|
class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test that a user can be retrieved by their external ID.
|
|
|
|
*/
|
|
|
|
public function testGetRemoteUser()
|
|
|
|
{
|
2021-01-23 20:09:16 +00:00
|
|
|
$user = User::factory()->create();
|
2018-03-04 22:56:05 +00:00
|
|
|
|
2018-03-05 04:35:57 +00:00
|
|
|
$response = $this->getJson('/api/application/users/external/' . $user->external_id);
|
|
|
|
$response->assertStatus(Response::HTTP_OK);
|
2018-03-04 22:56:05 +00:00
|
|
|
$response->assertJsonCount(2);
|
|
|
|
$response->assertJsonStructure([
|
|
|
|
'object',
|
|
|
|
'attributes' => [
|
2021-08-03 04:17:11 +00:00
|
|
|
'id', 'external_id', 'uuid', 'username', 'email',
|
2018-03-04 22:56:05 +00:00
|
|
|
'language', 'root_admin', '2fa', 'created_at', 'updated_at',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertJson([
|
|
|
|
'object' => 'user',
|
|
|
|
'attributes' => [
|
|
|
|
'id' => $user->id,
|
|
|
|
'external_id' => $user->external_id,
|
|
|
|
'uuid' => $user->uuid,
|
|
|
|
'username' => $user->username,
|
|
|
|
'email' => $user->email,
|
|
|
|
'language' => $user->language,
|
|
|
|
'root_admin' => (bool) $user->root_admin,
|
|
|
|
'2fa' => (bool) $user->totp_enabled,
|
|
|
|
'created_at' => $this->formatTimestamp($user->created_at),
|
|
|
|
'updated_at' => $this->formatTimestamp($user->updated_at),
|
|
|
|
],
|
|
|
|
], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an invalid external ID returns a 404 error.
|
|
|
|
*/
|
2018-03-05 04:35:57 +00:00
|
|
|
public function testGetMissingUser()
|
2018-03-04 22:56:05 +00:00
|
|
|
{
|
2018-03-05 04:35:57 +00:00
|
|
|
$response = $this->getJson('/api/application/users/external/nil');
|
2018-03-04 22:56:05 +00:00
|
|
|
$this->assertNotFoundJson($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an authentication error occurs if a key does not have permission
|
|
|
|
* to access a resource.
|
|
|
|
*/
|
|
|
|
public function testErrorReturnedIfNoPermission()
|
|
|
|
{
|
2021-08-07 23:17:16 +00:00
|
|
|
$this->markTestSkipped('todo: implement proper admin api key permissions system');
|
2018-03-04 22:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a users's existence is not exposed unless an API key has permission
|
|
|
|
* to access the resource.
|
|
|
|
*/
|
|
|
|
public function testResourceIsNotExposedWithoutPermissions()
|
|
|
|
{
|
2021-08-07 23:17:16 +00:00
|
|
|
$this->markTestSkipped('todo: implement proper admin api key permissions system');
|
2018-03-04 22:56:05 +00:00
|
|
|
}
|
|
|
|
}
|