Files
Nexus/tests/test_http_errors_zh.py
T
Nexus Agent a842af2405 fix(auth): use Chinese fallbacks and map reason codes to user messages
Stop exposing raw reason codes like admin_not_found in TOTP setup errors;
auth routes and JWT guard now use Chinese literals with auth_failure_detail.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 08:44:51 +08:00

53 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for HTTPException detail Chinese translation."""
from server.utils.http_errors_zh import (
auth_failure_detail,
translate_http_detail,
translate_http_detail_str,
)
def test_translate_server_not_found():
assert translate_http_detail_str("Server not found") == "服务器不存在"
def test_translate_auth_jwt_header():
assert translate_http_detail_str("Missing Authorization header") == "缺少 Authorization 请求头"
def test_translate_chinese_unchanged():
s = "NEXUS_API_BASE_URL 未配置"
assert translate_http_detail_str(s) == s
def test_translate_command_failed_pattern():
assert translate_http_detail_str("Command failed (exit 1)") == "命令失败(退出码 1"
def test_translate_immutable_setting_pattern():
msg = "Setting 'secret_key' is immutable and cannot be modified via API"
assert translate_http_detail_str(msg) == "设置项「secret_key」不可通过 API 修改"
def test_translate_dict_message_key():
out = translate_http_detail({"message": "Script not found", "code": 404})
assert out["message"] == "脚本不存在"
assert out["code"] == 404
def test_translate_list_detail():
out = translate_http_detail(["Server not found", "已配置"])
assert out == ["服务器不存在", "已配置"]
def test_auth_failure_detail_prefers_message():
assert auth_failure_detail({"message": "用户名或密码错误"}) == "用户名或密码错误"
def test_auth_failure_detail_maps_reason_code():
assert auth_failure_detail({"reason": "admin_not_found"}) == "管理员不存在"
def test_auth_failure_detail_fallback_zh():
assert auth_failure_detail({}, fallback="登录失败") == "登录失败"