fix(backend): non-login SSH and strict loginctl parse, SSH retry (0.20.31)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,6 +36,16 @@ def _install_fake_paramiko(monkeypatch, *, connect_side_effect=None, exec_setup=
|
||||
return client
|
||||
|
||||
|
||||
def test_ssh_output_hostname_ignores_motd():
|
||||
stdout = "Welcome!\nFASTPANEL\n\ncz-server\n"
|
||||
assert ssh_connect._ssh_output_hostname(stdout) == "cz-server"
|
||||
|
||||
|
||||
def test_remote_shell_command_non_login_for_sessions():
|
||||
cmd = _remote_shell_command("root", "loginctl list-sessions", "secret", login_shell=False)
|
||||
assert cmd == "bash -c 'loginctl list-sessions'"
|
||||
|
||||
|
||||
def test_remote_shell_command_non_root_probe_has_no_sudo():
|
||||
cmd = _remote_shell_command("deploy", "hostname", "secret", need_root=False)
|
||||
assert "sudo" not in cmd
|
||||
@@ -125,6 +135,53 @@ def test_iter_ssh_targets_requires_address():
|
||||
pass
|
||||
|
||||
|
||||
def test_run_ssh_command_retries_transient_no_existing_session(monkeypatch):
|
||||
attempts = {"count": 0}
|
||||
|
||||
class _NoSessionError(Exception):
|
||||
pass
|
||||
|
||||
def connect_side_effect(*args, **kwargs):
|
||||
attempts["count"] += 1
|
||||
if attempts["count"] == 1:
|
||||
raise _NoSessionError("No existing session")
|
||||
|
||||
def setup(client):
|
||||
stdout = MagicMock()
|
||||
stdout.read.return_value = b"ready\n"
|
||||
stdout.channel.recv_exit_status.return_value = 0
|
||||
stderr = MagicMock()
|
||||
stderr.read.return_value = b""
|
||||
|
||||
def exec_ok(cmd, **kwargs):
|
||||
return (None, stdout, stderr)
|
||||
|
||||
client.exec_command.side_effect = exec_ok
|
||||
|
||||
fake = MagicMock()
|
||||
fake.SSHClient = MagicMock()
|
||||
fake.AutoAddPolicy = MagicMock()
|
||||
fake.AuthenticationException = _AuthError
|
||||
|
||||
def make_client():
|
||||
client = MagicMock()
|
||||
client.connect.side_effect = connect_side_effect
|
||||
setup(client)
|
||||
return client
|
||||
|
||||
fake.SSHClient.side_effect = make_client
|
||||
monkeypatch.setitem(sys.modules, "paramiko", fake)
|
||||
|
||||
result = run_ssh_command(
|
||||
target="185.87.149.9",
|
||||
user="root",
|
||||
password="pw",
|
||||
remote_cmd="hostname",
|
||||
)
|
||||
assert result.ok is True
|
||||
assert attempts["count"] == 2
|
||||
|
||||
|
||||
def test_probe_ssh_connection_success(monkeypatch):
|
||||
def setup(client):
|
||||
stdout = MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user