- 新增统一日志工具,支持日志文件路径和级别配置 - 记录 CLI/chat、Agent、LLM、action、MCP、LangGraph、checkpoint 等关键流程 - 对日志中的 token、secret、api_key、Authorization 等敏感信息做脱敏 - chat 新增 llm test 命令,用于验证当前 LLM client 是否正常加载 - 同步 README、打包文档和 run.sh 帮助说明 - 补充日志脱敏和 llm test 相关测试
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from pam_deploy_graph.logging_utils import json_for_log, redact_for_log
|
|
|
|
|
|
def test_redact_for_log_masks_sensitive_keys_and_inline_assignments():
|
|
payload = {
|
|
"CLIENT_SECRET": "home-secret",
|
|
"api_key": "llm-key",
|
|
"nested": {
|
|
"Authorization": "Bearer token-value",
|
|
"message": "CLIENT_SECRET=abc api_key:xyz Authorization=Bearer raw-token header Bearer plain-token",
|
|
},
|
|
}
|
|
|
|
redacted = redact_for_log(payload)
|
|
serialized = json_for_log(payload)
|
|
|
|
assert redacted["CLIENT_SECRET"] == "***"
|
|
assert redacted["api_key"] == "***"
|
|
assert redacted["nested"]["Authorization"] == "***"
|
|
assert "home-secret" not in serialized
|
|
assert "llm-key" not in serialized
|
|
assert "token-value" not in serialized
|
|
assert "CLIENT_SECRET=***" in serialized
|
|
assert "api_key:***" in serialized
|
|
assert "Authorization=***" in serialized
|
|
assert "Bearer ***" in serialized
|
|
assert "raw-token" not in serialized
|
|
assert "plain-token" not in serialized
|