Files
awoooi/apps/api/tests/test_telegram_gateway_error_sanitizer.py
Your Name 24b15f4ad2
Some checks failed
Code Review / ai-code-review (push) Successful in 10s
run-migration / migrate (push) Failing after 8s
CD Pipeline / tests (push) Successful in 1m4s
CD Pipeline / build-and-deploy (push) Successful in 3m27s
CD Pipeline / post-deploy-checks (push) Successful in 1m18s
feat(awooop): harden outbound truth chain mirror
2026-05-12 23:21:45 +08:00

46 lines
1.6 KiB
Python

from __future__ import annotations
from src.services.telegram_gateway import (
_outbound_source_envelope,
_sanitize_telegram_error,
)
def test_telegram_gateway_sanitizes_bot_token_url() -> None:
raw = "Client error for https://api.telegram.org/bot123456:SECRET/sendMessage"
sanitized = _sanitize_telegram_error(raw)
assert "SECRET" not in sanitized
assert "bot<redacted>" in sanitized
def test_outbound_source_envelope_keeps_replay_context_without_raw_payload() -> None:
payload = {
"chat_id": "-100123",
"text": "ACTION REQUIRED token 1234567890:abcdefghijklmnopqrstuvwxyzABCDEFGH",
"parse_mode": "HTML",
"reply_markup": {
"inline_keyboard": [
[
{"text": "批准", "callback_data": "approve:approval-id-secret"},
{"text": "詳情", "callback_data": "details:approval-id-secret"},
]
]
},
}
envelope = _outbound_source_envelope("sendMessage", payload)
assert envelope["adapter"] == "legacy_telegram_gateway"
assert envelope["method"] == "sendMessage"
assert envelope["payload_sha256"]
assert envelope["payload_keys"] == ["chat_id", "parse_mode", "reply_markup", "text"]
assert envelope["parse_mode"] == "HTML"
assert envelope["reply_markup"]["button_count"] == 2
assert envelope["reply_markup"]["buttons"][0]["callback_prefix"] == "approve"
assert envelope["reply_markup"]["buttons"][1]["callback_prefix"] == "details"
assert "approval-id-secret" not in str(envelope)
assert "1234567890:" not in str(envelope)
assert "ACTION REQUIRED" not in str(envelope)