mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-04 10:42:23 +00:00
Socialite's GitLab provider fetches the user from /api/v3/user, which GitLab removed in 11.0 (410 Gone). Add App\Auth\GitlabProvider that reads /api/v4/user with a bearer token and register it in the socialite helper, for both gitlab.com and self-hosted base URLs. Environment variable copyValue now checks the 'update' policy on the variable instead of the member role of the current team, so members can no longer copy values after switching to a team they own. Remove the redundant member check from ShowHardcoded. Add tests for the GitLab v4 user lookup and the team-switch copy case.
50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Models\OauthSetting;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
use GuzzleHttp\HandlerStack;
|
|
use GuzzleHttp\Middleware;
|
|
use GuzzleHttp\Psr7\Response;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('reads the GitLab user from API v4 with a bearer token', function (?string $baseUrl, string $expectedUrl) {
|
|
OauthSetting::create([
|
|
'provider' => 'gitlab',
|
|
'client_id' => 'client-id',
|
|
'client_secret' => 'client-secret',
|
|
'redirect_uri' => 'https://coolify.example.com/auth/gitlab/callback',
|
|
'base_url' => $baseUrl,
|
|
'enabled' => true,
|
|
]);
|
|
|
|
$requests = [];
|
|
$handler = HandlerStack::create(new MockHandler([
|
|
new Response(200, ['Content-Type' => 'application/json'], json_encode([
|
|
'id' => 42,
|
|
'username' => 'gitlab-user',
|
|
'name' => 'GitLab User',
|
|
'email' => 'user@example.com',
|
|
'avatar_url' => null,
|
|
'confirmed_at' => '2026-01-10T09:05:22Z',
|
|
])),
|
|
]));
|
|
$handler->push(Middleware::history($requests));
|
|
|
|
$gitlabUser = get_socialite_provider('gitlab')
|
|
->setHttpClient(new Client(['handler' => $handler]))
|
|
->userFromToken('gitlab-access-token');
|
|
|
|
$request = $requests[0]['request'];
|
|
expect((string) $request->getUri())->toBe($expectedUrl)
|
|
->and($request->getHeaderLine('Authorization'))->toBe('Bearer gitlab-access-token')
|
|
->and($gitlabUser->getId())->toBe(42)
|
|
->and($gitlabUser->getEmail())->toBe('user@example.com')
|
|
->and($gitlabUser->user['confirmed_at'])->toBe('2026-01-10T09:05:22Z');
|
|
})->with([
|
|
'gitlab.com' => [null, 'https://gitlab.com/api/v4/user'],
|
|
'self-hosted GitLab' => ['https://gitlab.example.com/', 'https://gitlab.example.com/api/v4/user'],
|
|
]);
|