diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 6c748668..6236c8e2 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- -from werobot.crypto import PrpCrypto -from werobot.utils import generate_token, to_binary +from werobot.crypto import PrpCrypto, MessageCrypt +from werobot.utils import generate_token, to_binary, to_text +from werobot.parser import parse_xml +import time def test_prpcrypto(): @@ -14,3 +16,24 @@ def test_prpcrypto(): app_id = generate_token(32) assert crypto.decrypt(crypto.encrypt(text, app_id), app_id) == to_binary(text) + + +def test_message_crypt(): + encoding_aes_key = generate_token(32) + generate_token(11) + token = generate_token() + timestamp = to_text(int(time.time())) + nonce = generate_token(5) + app_id = generate_token(18) + crypt = MessageCrypt(token=token, + encoding_aes_key=encoding_aes_key, + app_id=app_id) + + message = crypt.encrypt_message('hello', timestamp, nonce) + assert message is not None + message = parse_xml(message) + assert message is not None + message = crypt.decrypt_message(message['TimeStamp'], + message['Nonce'], + message['MsgSignature'], + message['Encrypt']) + assert message == to_binary('hello')