mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
Accept HTTP(S), git:// and SCP-style SSH repository URLs whose host is an IP address, including bracketed IPv6 such as git@[2a01:4f8::1]:org/repo.git. The clone runs on the user's deployment server, so the IP block did not protect Coolify, and SSH URLs with IPv4 already passed. Loopback, link-local and other reserved addresses are still rejected as internal hosts. Brackets are allowed only around a valid IPv6 host.
139 lines
4.7 KiB
PHP
139 lines
4.7 KiB
PHP
<?php
|
|
|
|
use App\Models\GithubApp;
|
|
|
|
/**
|
|
* The seeded "Public GitHub" source (id 0), built in memory so the test needs no database.
|
|
*/
|
|
function publicGithubAppForGitUrlTests(): GithubApp
|
|
{
|
|
return (new GithubApp)->forceFill([
|
|
'id' => 0,
|
|
'name' => 'Public GitHub',
|
|
'api_url' => 'https://api.github.com',
|
|
'html_url' => 'https://github.com',
|
|
'custom_user' => 'git',
|
|
'custom_port' => 22,
|
|
'is_public' => true,
|
|
]);
|
|
}
|
|
|
|
test('convertGitUrlsForDeployKeyAndGithubAppAndHttpUrl', function () {
|
|
$githubApp = publicGithubAppForGitUrlTests();
|
|
$result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@github.com:andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndGithubAppAndSshUrl', function () {
|
|
$githubApp = publicGithubAppForGitUrlTests();
|
|
$result = convertGitUrl('git@github.com:andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@github.com:andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndHttpUrl', function () {
|
|
$result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndSshUrl', function () {
|
|
$result = convertGitUrl('git@github.com:andrasbacsai/coolify-examples.git', 'deploy_key', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@github.com:andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndSshUrl', function () {
|
|
$result = convertGitUrl('git@github.com:andrasbacsai/coolify-examples.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@github.com:andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndHttpUrl', function () {
|
|
$result = convertGitUrl('andrasbacsai/coolify-examples.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'andrasbacsai/coolify-examples.git',
|
|
'port' => 22,
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndSshUrlWithCustomPort', function () {
|
|
$result = convertGitUrl('git@git.domain.com:766/group/project.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@git.domain.com:group/project.git',
|
|
'port' => '766',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndSshUrlWithCustomUsernameAndPort', function () {
|
|
$result = convertGitUrl('custom-user@git.domain.com:766/group/project.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'custom-user@git.domain.com:group/project.git',
|
|
'port' => '766',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndSshUrlSchemeWithCustomPort', function () {
|
|
$result = convertGitUrl('ssh://git@192.168.56.11:22222/User/Repo.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'ssh://git@192.168.56.11:22222/User/Repo.git',
|
|
'port' => '22222',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForSourceAndSshUrlSchemeWithCustomPortAndIpv6Host', function () {
|
|
$result = convertGitUrl('ssh://git@[2001:db8::10]:22222/group/project.git', 'source', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'ssh://git@[2001:db8::10]:22222/group/project.git',
|
|
'port' => '22222',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndGithubAppWithCustomPort', function () {
|
|
$githubApp = new GithubApp([
|
|
'html_url' => 'https://github.example.com',
|
|
'custom_user' => 'git',
|
|
'custom_port' => 22222,
|
|
]);
|
|
|
|
$result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
|
|
expect($result)->toBe([
|
|
'repository' => 'ssh://git@github.example.com:22222/andrasbacsai/coolify-examples.git',
|
|
'port' => '22222',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndGithubAppWithCustomPortAndIpv6Host', function () {
|
|
$githubApp = new GithubApp([
|
|
'html_url' => 'https://[2001:db8::10]',
|
|
'custom_user' => 'git',
|
|
'custom_port' => 22222,
|
|
]);
|
|
|
|
$result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
|
|
expect($result)->toBe([
|
|
'repository' => 'ssh://git@[2001:db8::10]:22222/andrasbacsai/coolify-examples.git',
|
|
'port' => '22222',
|
|
]);
|
|
});
|
|
|
|
test('convertGitUrlsForDeployKeyAndIpv6SshUrlWithPort', function () {
|
|
$result = convertGitUrl('git@[fd00::5]:2222/organization/repository.git', 'deploy_key', null);
|
|
expect($result)->toBe([
|
|
'repository' => 'git@[fd00::5]:organization/repository.git',
|
|
'port' => '2222',
|
|
]);
|
|
});
|