ForcePilot/backend/test/unit/channels/test_wechat_crypto.py
Kris 3264900bc9 test: 新增多渠道单元测试用例并配置测试环境变量
新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块
同时在测试配置中添加了测试用的OpenAI API密钥环境变量
2026-05-12 00:56:47 +08:00

54 lines
1.7 KiB
Python

from __future__ import annotations
from yuxi.channels.adapters.wechat.wecom.crypto import verify_signature
from yuxi.channels.adapters.wechat.mp.crypto import verify_signature as mp_verify_signature
class TestWeComCrypto:
def test_verify_signature_valid(self):
token = "test_token"
timestamp = "1234567890"
nonce = "abcdefg"
import hashlib
params = sorted([token, timestamp, nonce])
expected = hashlib.sha1("".join(params).encode()).hexdigest()
assert verify_signature(token, timestamp, nonce, expected) is True
def test_verify_signature_invalid(self):
token = "test_token"
timestamp = "1234567890"
nonce = "abcdefg"
assert verify_signature(token, timestamp, nonce, "invalid_sig") is False
def test_verify_signature_different_token(self):
token = "test_token"
timestamp = "1234567890"
nonce = "abcdefg"
import hashlib
params = sorted(["different_token", timestamp, nonce])
diff_sig = hashlib.sha1("".join(params).encode()).hexdigest()
assert verify_signature(token, timestamp, nonce, diff_sig) is False
class TestMPCrypto:
def test_verify_signature_valid(self):
token = "mp_token"
timestamp = "1234567890"
nonce = "abcdefg"
import hashlib
params = sorted([token, timestamp, nonce])
expected = hashlib.sha1("".join(params).encode()).hexdigest()
assert mp_verify_signature(token, timestamp, nonce, expected) is True
def test_verify_signature_invalid(self):
token = "mp_token"
timestamp = "1234567890"
nonce = "abcdefg"
assert mp_verify_signature(token, timestamp, nonce, "wrong_sig") is False