coolify/tests/Feature/PublicGitRepositorySshUrlTest.php
Andras Bacsai 83714ea395 fix(git): parse generic scp-style SSH URLs with custom users
Centralize scp-style Git URL parsing so user@host:path (including custom
usernames and embedded ports) is accepted and converted to HTTPS for
public clones, API create, webhooks, validation, and commit/branch links.
2026-09-08 20:33:45 +02:00

34 lines
1.2 KiB
PHP

<?php
use App\Livewire\Project\New\PublicGitRepository;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$team = Team::factory()->create();
$user = User::factory()->create();
$team->members()->attach($user->id, ['role' => 'owner']);
$this->actingAs($user);
session(['currentTeam' => $team]);
});
test('converts scp-style ssh urls with custom usernames to https', function () {
Livewire::test(PublicGitRepository::class, ['type' => 'public'])
->set('repository_url', 'custom-user@git.example.com:organization/repository.git')
->call('loadBranch')
->assertSet('repository_url', 'https://git.example.com/organization/repository.git')
->assertSet('branchFound', true);
});
test('strips custom ports when converting scp-style ssh urls to https', function () {
Livewire::test(PublicGitRepository::class, ['type' => 'public'])
->set('repository_url', 'custom-user@git.example.com:2222/organization/repository.git')
->call('loadBranch')
->assertSet('repository_url', 'https://git.example.com/organization/repository.git')
->assertSet('branchFound', true);
});