From 3ab660b8fea2ed4d209f077cbbf6c4288b437ae0 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 4 Oct 2021 13:43:51 +0530 Subject: [PATCH] tests: Add unit tests for key based encryptor --- .../encryption/test_key_based_encryptor.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py new file mode 100644 index 000000000..391002417 --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py @@ -0,0 +1,19 @@ +from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor + +PLAINTEXT = "password" +PLAINTEXT_UTF8 = "slaptažodis" # "password" in Lithuanian +KEY = b"\x84\xd4qA\xb5\xd4Y\x9bH.\x14\xab\xd8\xc7+g\x12\xfa\x80'%\xfd#\xf8c\x94\xb9\x96_\xf4\xc51" + +kb_encryptor = KeyBasedEncryptor(KEY) + + +def test_encrypt_decrypt_string_with_key(): + encrypted = kb_encryptor.encrypt(PLAINTEXT) + decrypted = kb_encryptor.decrypt(encrypted) + assert decrypted == PLAINTEXT + + +def test_encrypt_decrypt_string_utf8_with_key(): + encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8) + decrypted = kb_encryptor.decrypt(encrypted) + assert decrypted == PLAINTEXT_UTF8