22 lines
683 B
Python
22 lines
683 B
Python
import base64
|
|
|
|
from app.services.integrations.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 = '<xml><MsgType><![CDATA[event]]></MsgType></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
|