Files
coolify/tests/Unit/ScpStyleGitUrlTest.php
T
Andras BacsaiandClaude Opus 5.5 7466da12a2 fix(git): accept ssh:// repository URLs with custom ports
The repository URL rule rejected ssh://user@host:port/path, so deploy-key
resources on servers with a custom SSH port needed a manual URL edit after
creation. Accept ssh:// URLs and keep them unchanged for deploy keys so the
port reaches the clone. Rename scpStyleGitUrlToHttps to sshGitUrlToHttps and
let it convert ssh:// URLs too, so public flows, repository links and GitHub
App repository slugs handle them.

Closes #12161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 22:30:26 +02:00

106 lines
4.0 KiB
PHP

<?php
it('parses scp-style ssh git urls including custom usernames and ports', function (string $url, array $expected) {
expect(parseScpStyleGitUrl($url))->toBe($expected);
})->with([
'git username' => [
'git@github.com:organization/repository.git',
[
'user' => 'git',
'host' => 'github.com',
'port' => null,
'path' => 'organization/repository.git',
],
],
'custom username' => [
'custom-user@git.example.com:organization/repository.git',
[
'user' => 'custom-user',
'host' => 'git.example.com',
'port' => null,
'path' => 'organization/repository.git',
],
],
'custom username and port' => [
'custom-user@git.example.com:2222/organization/repository.git',
[
'user' => 'custom-user',
'host' => 'git.example.com',
'port' => '2222',
'path' => 'organization/repository.git',
],
],
'IPv6 host' => [
'git@[2a01:4f8::1]:organization/repository.git',
[
'user' => 'git',
'host' => '[2a01:4f8::1]',
'port' => null,
'path' => 'organization/repository.git',
],
],
'IPv6 host and port' => [
'git@[fd00::5]:2222/organization/repository.git',
[
'user' => 'git',
'host' => '[fd00::5]',
'port' => '2222',
'path' => 'organization/repository.git',
],
],
]);
it('converts ssh git urls to https without embedding custom ports in the path', function (string $url, string $expected) {
expect(sshGitUrlToHttps($url))->toBe($expected);
})->with([
'git username' => [
'git@github.com:organization/repository.git',
'https://github.com/organization/repository.git',
],
'custom username' => [
'custom-user@git.example.com:organization/repository.git',
'https://git.example.com/organization/repository.git',
],
'custom username and port' => [
'custom-user@git.example.com:2222/organization/repository.git',
'https://git.example.com/organization/repository.git',
],
'IPv6 host and port' => [
'git@[fd00::5]:2222/organization/repository.git',
'https://[fd00::5]/organization/repository.git',
],
'ssh scheme' => [
'ssh://git@github.com/organization/repository.git',
'https://github.com/organization/repository.git',
],
'ssh scheme with port' => [
'ssh://git@gitea.example.com:2222/organization/repository.git',
'https://gitea.example.com/organization/repository.git',
],
'ssh scheme with IPv6 host and port' => [
'ssh://git@[fd00::5]:2222/organization/repository.git',
'https://[fd00::5]/organization/repository.git',
],
]);
it('rejects non-scp-style git urls', function (string $url) {
expect(parseScpStyleGitUrl($url))->toBeNull()
->and(sshGitUrlToHttps($url))->toBeNull();
})->with([
'https' => 'https://github.com/organization/repository.git',
'email without path' => 'custom-user@git.example.com',
'empty' => '',
]);
it('normalizes github app repository slugs from ssh urls', function (string $url, string $expected) {
expect(gitRepositorySlug($url))->toBe($expected);
})->with([
'https' => ['https://github.com/organization/repository.git', 'organization/repository'],
'owner/repo' => ['organization/repository', 'organization/repository'],
'git username' => ['git@github.com:organization/repository.git', 'organization/repository'],
'custom username' => ['custom-user@git.example.com:organization/repository.git', 'organization/repository'],
'custom username and port' => ['custom-user@git.example.com:2222/organization/repository.git', 'organization/repository'],
'ssh scheme' => ['ssh://git@github.com/organization/repository.git', 'organization/repository'],
'ssh scheme with port' => ['ssh://git@ghe.example.com:2222/organization/repository.git', 'organization/repository'],
]);