import base64 from app.services.wecom_crypto import decrypt_wecom_aes, encrypt_wecom_aes, sha1_hex def test_wecom_aes_roundtrip(): corp_id = 'ww1234567890abcdef' aes_key_b64 = base64.b64encode(b'0' * 32).decode('ascii').rstrip('=') xml = '' cipher = encrypt_wecom_aes(xml, aes_key_b64, corp_id) plain = decrypt_wecom_aes(cipher, aes_key_b64, corp_id) assert plain == xml def test_wecom_msg_signature(): token = 'hxops-token' ts = '123' nonce = 'abc' encrypt = 'cipher-text' sig = sha1_hex([token, ts, nonce, encrypt]) assert sha1_hex([token, ts, nonce, encrypt]) == sig