tests: Add test cases for KeyBasedEncryptor's tests

This commit is contained in:
Shreya Malviya 2021-10-05 12:05:49 +05:30
parent 404228b04c
commit f6b1330982
1 changed files with 18 additions and 4 deletions

View File

@ -1,7 +1,9 @@
from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor
PLAINTEXT = "password"
PLAINTEXT_UTF8 = "slaptažodis" # "password" in Lithuanian
PLAINTEXT_UTF8_1 = "slaptažodis" # "password" in Lithuanian
PLAINTEXT_UTF8_2 = "" # Japanese
PLAINTEXT_UTF8_3 = "ж" # Ukranian
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)
@ -13,7 +15,19 @@ def test_encrypt_decrypt_string_with_key():
assert decrypted == PLAINTEXT
def test_encrypt_decrypt_string_utf8_with_key():
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8)
def test_encrypt_decrypt_string_utf8_with_key_1():
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_1)
decrypted = kb_encryptor.decrypt(encrypted)
assert decrypted == PLAINTEXT_UTF8
assert decrypted == PLAINTEXT_UTF8_1
def test_encrypt_decrypt_string_utf8_with_key_2():
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_2)
decrypted = kb_encryptor.decrypt(encrypted)
assert decrypted == PLAINTEXT_UTF8_2
def test_encrypt_decrypt_string_utf8_with_key_3():
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_3)
decrypted = kb_encryptor.decrypt(encrypted)
assert decrypted == PLAINTEXT_UTF8_3