mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(terminal): fall back to usable shell for nologin and false (#12242)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7faa46bbd4
commit
f2ece40dd4
@@ -109,7 +109,8 @@ class TerminalSessionService
|
||||
{
|
||||
return 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && '.
|
||||
'if [ -f ~/.profile ]; then . ~/.profile; fi && '.
|
||||
'if [ -n "$SHELL" ] && [ -x "$SHELL" ]; then exec $SHELL; else sh; fi';
|
||||
'if [ -n "$SHELL" ] && [ -x "$SHELL" ] && [ "${SHELL##*/}" != nologin ] && [ "${SHELL##*/}" != false ]; then exec $SHELL; '.
|
||||
'elif command -v bash >/dev/null 2>&1; then exec bash; else sh; fi';
|
||||
}
|
||||
|
||||
private function cacheKey(string $token): string
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use App\Services\TerminalSessionService;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
function runTerminalShellCommand(string $shellName, int $exitCode = 1): Process
|
||||
{
|
||||
$home = sys_get_temp_dir().'/terminal-shell-'.uniqid();
|
||||
mkdir($home);
|
||||
$shell = "{$home}/{$shellName}";
|
||||
file_put_contents($shell, "#!/bin/sh\necho {$shellName}-ran\nexit {$exitCode}\n");
|
||||
chmod($shell, 0755);
|
||||
|
||||
$command = (fn () => $this->shellCommand())->call(new TerminalSessionService);
|
||||
|
||||
$process = new Process(['sh', '-c', $command], null, ['HOME' => $home, 'SHELL' => $shell]);
|
||||
$process->setInput("echo fallback-ran\n");
|
||||
$process->run();
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
||||
it('falls back to a usable shell when $SHELL is a login-disabling shell', function (string $shellName) {
|
||||
$process = runTerminalShellCommand($shellName);
|
||||
|
||||
expect($process->getOutput())->toContain('fallback-ran')
|
||||
->not->toContain("{$shellName}-ran");
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
})->with(['nologin', 'false']);
|
||||
|
||||
it('starts $SHELL when it is a usable shell', function () {
|
||||
$process = runTerminalShellCommand('zsh', exitCode: 0);
|
||||
|
||||
expect($process->getOutput())->toContain('zsh-ran');
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
});
|
||||
Reference in New Issue
Block a user