Files
Nexus/tests/test_sync_error_message.py
T
Nexus Agent a14fbb3df3 fix(ssh): 快速添加跳过主机密钥校验并中文化错误
凭据轮询在 SSH_STRICT 默认 true 时因 HostKeyNotVerifiable 在认证前失败;
探测始终 known_hosts=None,默认 strict 改为 false,错误信息统一中文。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:31:38 +08:00

52 lines
1.8 KiB
Python

"""Tests for push/sync error message localization."""
from server.utils.sync_error_message import translate_sync_error_message
class TestTranslateSyncErrorMessage:
def test_none_and_empty(self):
assert translate_sync_error_message(None) is None
assert translate_sync_error_message("") == ""
assert translate_sync_error_message(" ") == " "
def test_already_chinese_unchanged(self):
msg = "推送已取消"
assert translate_sync_error_message(msg) == msg
def test_permission_denied(self):
assert "权限被拒绝" in translate_sync_error_message("Permission denied")
def test_no_such_file(self):
assert "文件或目录不存在" in translate_sync_error_message(
"rsync: No such file or directory (2)"
)
def test_connection_refused(self):
assert "连接被拒绝" in translate_sync_error_message(
"ssh: connect to host 1.2.3.4 port 22: Connection refused"
)
def test_rsync_connection_closed(self):
assert "连接意外关闭" in translate_sync_error_message(
"rsync: connection unexpectedly closed (0 bytes received so far) [sender]"
)
def test_exit_code(self):
out = translate_sync_error_message("Command failed (exit 23)")
assert "退出码" in out
def test_server_not_found(self):
assert translate_sync_error_message("Server not found") == "服务器不存在"
def test_host_key_not_trusted(self):
msg = translate_sync_error_message(
"Host key is not trusted for host 66.154.115.131"
)
assert "主机密钥未信任" in msg
def test_permission_denied_for_user(self):
msg = translate_sync_error_message(
"Permission denied for user root on host 66.154.115.131"
)
assert "认证失败" in msg