fix(webui): ignore SSH banners when detecting missing Python

This commit is contained in:
Xubin Ren committed 2026-11-18 20:15:13 +08:00
1 parent 413b9a1074
commit 098d854339
2 files changed
+8 -5

No files matched your search

+4 -4
View File
@@ -159,13 +159,13 @@ async def run_check(
await stop_process(process)
if process.returncode == 0:
break
# Windows sshd may report a missing command as 1. Match the
# quoted executable in cmd.exe's diagnostic, not its language.
first_line = stderr.partition(b"\n")[0]
# Windows sshd can return 1. Match the executable in cmd.exe's
# trailing one- or two-line diagnostic, after any login banner.
diagnostic = b"\n".join(stderr.splitlines()[-2:])
if not sudo and (process.returncode in {49, 127, 9009} or (
process.returncode == 1 and (
b"CommandNotFoundException" in stderr
or any(f"{quote}{executable}{quote}".encode() in first_line for quote in ("'", '"'))
or any(f"{quote}{executable}{quote}".encode() in diagnostic for quote in ("'", '"'))
)
)):
continue
+4 -1
View File
@@ -1046,10 +1046,13 @@ async def test_probe_ignores_shell_banners_without_exposing_them(monkeypatch, ba
(127, b"python3: not found", ""),
(49, b"'python3' is not recognized as an internal or external command", ""),
(1, b"'python3' is not recognized as an internal or external command", ""),
(1, b"Authorized users only.\r\n'python3' is not recognized as an internal or external command,\r\n"
b"operable program or batch file.\r\n", ""),
(1, '"python3" 不是内部或外部命令'.encode(), ""),
(1, b"FullyQualifiedErrorId : CommandNotFoundException", ""),
(255, b"Permission denied (publickey).", "ssh_auth_failed"),
(1, b"Traceback (most recent call last):", "probe_failed"),
(1, b"Use 'python3' for authorized jobs.\r\nTraceback (most recent call last):\r\n"
b"RuntimeError: probe failed\r\n", "probe_failed"),
])
async def test_probe_only_retries_when_the_remote_interpreter_is_missing(monkeypatch, returncode, stderr, expected_error):
data = {"port": 8765, "secret": "synthetic-root"}