fix(terminal): fall back to usable shell for nologin and false

This commit is contained in:
Andras Bacsai committed 2026-10-20 11:41:35 +02:00
1 parent bf957e425f
commit 9eb9649005
2 files changed
+34 -1

No files matched your search

+2 -1
View File
@@ -78,7 +78,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
+32
View File
@@ -0,0 +1,32 @@
<?php
use App\Services\TerminalSessionService;
use Symfony\Component\Process\Process;
function runTerminalShellCommand(string $shellName): string
{
$home = sys_get_temp_dir().'/terminal-shell-'.uniqid();
mkdir($home);
$shell = "{$home}/{$shellName}";
file_put_contents($shell, "#!/bin/sh\necho {$shellName}-ran\nexit 1\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->getOutput();
}
it('falls back to a usable shell when $SHELL is a login-disabling shell', function (string $shellName) {
$output = runTerminalShellCommand($shellName);
expect($output)->toContain('fallback-ran')
->not->toContain("{$shellName}-ran");
})->with(['nologin', 'false']);
it('starts $SHELL when it is a usable shell', function () {
expect(runTerminalShellCommand('zsh'))->toContain('zsh-ran');
});