Skip to content

Commit

Permalink
Add test for MessageCrypt #152
Browse files Browse the repository at this point in the history
  • Loading branch information
helloqiu committed Aug 15, 2016
1 parent 604bf56 commit 43e99e4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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')

0 comments on commit 43e99e4

Please sign in to comment.