Path: blob/1.0-develop/tests/Integration/Api/Application/Users/ExternalUserControllerTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Application\Users;34use Illuminate\Support\Str;5use Pterodactyl\Models\User;6use Illuminate\Http\Response;7use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;89class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase10{11/**12* Test that a user can be retrieved by their external ID.13*/14public function testGetRemoteUser()15{16$user = User::factory()->create(['external_id' => Str::random()]);1718$response = $this->getJson('/api/application/users/external/' . $user->external_id);19$response->assertStatus(Response::HTTP_OK);20$response->assertJsonCount(2);21$response->assertJsonStructure([22'object',23'attributes' => [24'id', 'external_id', 'uuid', 'username', 'email', 'first_name', 'last_name',25'language', 'root_admin', '2fa', 'created_at', 'updated_at',26],27]);2829$response->assertJson([30'object' => 'user',31'attributes' => [32'id' => $user->id,33'external_id' => $user->external_id,34'uuid' => $user->uuid,35'username' => $user->username,36'email' => $user->email,37'first_name' => $user->name_first,38'last_name' => $user->name_last,39'language' => $user->language,40'root_admin' => (bool) $user->root_admin,41'2fa' => (bool) $user->totp_enabled,42'created_at' => $this->formatTimestamp($user->created_at),43'updated_at' => $this->formatTimestamp($user->updated_at),44],45], true);46}4748/**49* Test that an invalid external ID returns a 404 error.50*/51public function testGetMissingUser()52{53$response = $this->getJson('/api/application/users/external/nil');54$this->assertNotFoundJson($response);55}5657/**58* Test that an authentication error occurs if a key does not have permission59* to access a resource.60*/61public function testErrorReturnedIfNoPermission()62{63$user = User::factory()->create(['external_id' => Str::random()]);64$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]);6566$response = $this->getJson('/api/application/users/external/' . $user->external_id);67$this->assertAccessDeniedJson($response);68}69}707172