mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 16:36:52 +01:00 
			
		
		
		
	* Just skip this table because it no longer exists * Add postgresql * This no longer needs to be there * These are the same output in mysql, but different in postgresql * Fix these migrations for postgresql * This table no longer exists * This is expected to be a json column for json operations, required for postgresql * Shoot for the stars * Fix pint * Why was this missing * Updates * Restore this * This needs to be explicit * Don’t like strings * Fix these classes * Use different method to compare dates * Apparently postgresql doesn’t like case insensitivity * Postgresql orders it backwards * Ordered different by postgresql * Unnecessary and breaking * Make sure the order is correct for postresql * Fix this with the order too * Remove this * Force email to be lowercased * Update app/Models/User.php
		
			
				
	
	
		
			70 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Tests\Integration\Api\Application\Users;
 | 
						|
 | 
						|
use Illuminate\Support\Str;
 | 
						|
use App\Models\User;
 | 
						|
use App\Services\Acl\Api\AdminAcl;
 | 
						|
use Illuminate\Http\Response;
 | 
						|
use App\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
 | 
						|
 | 
						|
class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Test that a user can be retrieved by their external ID.
 | 
						|
     */
 | 
						|
    public function test_get_remote_user(): void
 | 
						|
    {
 | 
						|
        $user = User::factory()->create(['external_id' => Str::random()]);
 | 
						|
 | 
						|
        $response = $this->getJson('/api/application/users/external/' . $user->external_id);
 | 
						|
        $response->assertStatus(Response::HTTP_OK);
 | 
						|
        $response->assertJsonCount(2);
 | 
						|
        $response->assertJsonStructure([
 | 
						|
            'object',
 | 
						|
            'attributes' => [
 | 
						|
                'id', 'external_id', 'uuid', 'username', 'email',
 | 
						|
                '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->isRootAdmin(),
 | 
						|
                '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.
 | 
						|
     */
 | 
						|
    public function test_get_missing_user(): void
 | 
						|
    {
 | 
						|
        $response = $this->getJson('/api/application/users/external/12345');
 | 
						|
        $this->assertNotFoundJson($response);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Test that an authentication error occurs if a key does not have permission
 | 
						|
     * to access a resource.
 | 
						|
     */
 | 
						|
    public function test_error_returned_if_no_permission(): void
 | 
						|
    {
 | 
						|
        $user = User::factory()->create(['external_id' => Str::random()]);
 | 
						|
        $this->createNewDefaultApiKey($this->getApiUser(), [User::RESOURCE_NAME => AdminAcl::NONE]);
 | 
						|
 | 
						|
        $response = $this->getJson('/api/application/users/external/' . $user->external_id);
 | 
						|
        $this->assertAccessDeniedJson($response);
 | 
						|
    }
 | 
						|
}
 |