fix(git): preserve ssh scheme URLs with custom ports (#9425)
This commit is contained in:
commit
3fa4ea9ad3
3 changed files with 78 additions and 6 deletions
|
|
@ -3660,13 +3660,21 @@ function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match('/(?<=:)\d+(?=\/)/', $gitRepository, $matches);
|
$normalizedRepository = $repository;
|
||||||
|
|
||||||
if (count($matches) === 1) {
|
if (str($normalizedRepository)->contains('://')) {
|
||||||
$providerInfo['port'] = $matches[0];
|
$parsedRepository = parse_url($normalizedRepository);
|
||||||
$gitHost = str($gitRepository)->before(':');
|
|
||||||
$gitRepo = str($gitRepository)->after('/');
|
if ($parsedRepository !== false && array_key_exists('port', $parsedRepository)) {
|
||||||
$repository = "$gitHost:$gitRepo";
|
$providerInfo['port'] = (string) $parsedRepository['port'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
preg_match('/^(?<host>[^:]+):(?<port>\d+)\/(?<path>.+)$/', $normalizedRepository, $matches);
|
||||||
|
|
||||||
|
if (! empty($matches['port'])) {
|
||||||
|
$providerInfo['port'] = $matches['port'];
|
||||||
|
$repository = "{$matches['host']}:{$matches['path']}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
|
|
@ -60,3 +60,47 @@
|
||||||
'port' => '766',
|
'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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -99,3 +99,23 @@
|
||||||
// The malicious payload should be escaped (escapeshellarg wraps and escapes quotes)
|
// The malicious payload should be escaped (escapeshellarg wraps and escapes quotes)
|
||||||
expect($command)->toContain("'https://github.com/user/repo.git'\\''");
|
expect($command)->toContain("'https://github.com/user/repo.git'\\''");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('preserves ssh scheme URLs with custom ports in deploy_key commands', function () {
|
||||||
|
$deploymentUuid = 'test-deployment-uuid';
|
||||||
|
|
||||||
|
$application = new Application;
|
||||||
|
$application->git_branch = 'master';
|
||||||
|
$application->git_repository = 'ssh://git@192.168.56.11:22222/User/Repo.git';
|
||||||
|
$application->private_key_id = 1;
|
||||||
|
|
||||||
|
$privateKey = new PrivateKey;
|
||||||
|
$privateKey->private_key = 'fake-private-key';
|
||||||
|
$application->setRelation('private_key', $privateKey);
|
||||||
|
|
||||||
|
$result = $application->generateGitLsRemoteCommands($deploymentUuid, false);
|
||||||
|
|
||||||
|
expect($result['commands'])
|
||||||
|
->toContain("'ssh://git@192.168.56.11:22222/User/Repo.git'")
|
||||||
|
->toContain('-p 22222')
|
||||||
|
->not->toContain('ssh:/git@192.168.56.11:22222/User/Repo.git');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue