fix(webui): run SSH probes on Windows hosts with python
This commit is contained in:
1 parent
307b3bce82
commit
b18ca98aff
14 files changed
+110
-54
No files matched your search
@@ -1042,6 +1042,32 @@ async def test_probe_ignores_shell_banners_without_exposing_them(monkeypatch, ba
|
||||
assert await remote_ssh.probe(RemoteProfile(name="Test", host="example.test")) == data
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("returncode", "stderr", "expected_error"), [
|
||||
(127, b"python3: not found", ""),
|
||||
(49, b"'python3' is not recognized as an internal or external command", ""),
|
||||
(1, b"FullyQualifiedErrorId : CommandNotFoundException", ""),
|
||||
(255, b"Permission denied (publickey).", "ssh_auth_failed"),
|
||||
(1, b"Traceback (most recent call last):", "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"}
|
||||
attempt = MagicMock(returncode=returncode, communicate=AsyncMock(return_value=(b"", stderr)))
|
||||
fallback = MagicMock(returncode=0, communicate=AsyncMock(return_value=(
|
||||
remote_ssh._PROBE_PREFIX + json.dumps(data).encode() + b"\r\n", b"",
|
||||
)))
|
||||
spawn = AsyncMock(side_effect=[attempt, fallback])
|
||||
monkeypatch.setattr(asyncio, "create_subprocess_exec", spawn)
|
||||
profile = RemoteProfile(name="Test", host="example.test", config_path=r"C:\測試 & 100%\config.json")
|
||||
if expected_error:
|
||||
with pytest.raises(RemoteError, match=f"^{expected_error}$"):
|
||||
await remote_ssh.probe(profile)
|
||||
spawn.assert_awaited_once()
|
||||
else:
|
||||
assert await remote_ssh.probe(profile) == data
|
||||
assert [call.args[-1] for call in spawn.await_args_list] == ["python3 -", "python -"]
|
||||
assert attempt.communicate.await_args == fallback.communicate.await_args
|
||||
|
||||
|
||||
@pytest.mark.parametrize("output", [
|
||||
b"Welcome. Password required for private-user.",
|
||||
b'\x1eNANOBOT_REMOTE:{"port": 8765, "secret": "s"}\n\x1eNANOBOT_REMOTE:{}',
|
||||
@@ -1055,15 +1081,28 @@ async def test_invalid_probe_protocol_is_not_reported_as_bad_config(monkeypatch,
|
||||
await remote_ssh.probe(RemoteProfile(name="Test", host="example.test"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("config", ["invalid JSON", "[]", '{"channels": null}', '{"channels": {"websocket": []}}'])
|
||||
@pytest.mark.parametrize("config", [b"invalid JSON", b"[]", b'{"channels": null}', b'{"channels": {"websocket": []}}', b'{"name":"\xff"}'])
|
||||
def test_probe_reports_malformed_config_as_config_error(tmp_path, config):
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(config)
|
||||
path.write_bytes(config)
|
||||
result = subprocess.run([sys.executable, "-c", remote_ssh._PROBE, str(path)],
|
||||
capture_output=True, text=True, check=True)
|
||||
assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1]) == {"error": "config_invalid"}
|
||||
|
||||
|
||||
def test_probe_reads_config_as_utf8_independently_of_locale(tmp_path, monkeypatch):
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(json.dumps({"channels": {"websocket": {
|
||||
"enabled": True, "token": "synthetic-root", "tokenIssuePath": "/测试",
|
||||
}}}, ensure_ascii=False), encoding="utf-8")
|
||||
monkeypatch.setenv("PYTHONUTF8", "0")
|
||||
monkeypatch.setenv("PYTHONCOERCECLOCALE", "0")
|
||||
monkeypatch.setenv("LC_ALL", "C")
|
||||
result = subprocess.run([sys.executable, "-c", remote_ssh._PROBE, str(path)],
|
||||
capture_output=True, text=True, check=True)
|
||||
assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1])["token_issue_path"] == "/测试"
|
||||
|
||||
|
||||
async def test_tunnel_refuses_an_existing_listener(monkeypatch):
|
||||
spawn = AsyncMock()
|
||||
monkeypatch.setattr(asyncio, "create_subprocess_exec", spawn)
|
||||
|
||||
Reference in new issue
Block a user