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