tests: Use pytest's parametrize for KeyBasedEncryptor's unit tests

This commit is contained in:
Shreya Malviya 2021-10-05 12:08:52 +05:30
parent f6b1330982
commit f1b9683617
1 changed files with 6 additions and 15 deletions

View File

@ -1,3 +1,5 @@
import pytest
from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor
PLAINTEXT = "password" PLAINTEXT = "password"
@ -15,19 +17,8 @@ def test_encrypt_decrypt_string_with_key():
assert decrypted == PLAINTEXT assert decrypted == PLAINTEXT
def test_encrypt_decrypt_string_utf8_with_key_1(): @pytest.mark.parametrize("plaintext", [PLAINTEXT_UTF8_1, PLAINTEXT_UTF8_2, PLAINTEXT_UTF8_3])
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_1) def test_encrypt_decrypt_string_utf8_with_key(plaintext):
encrypted = kb_encryptor.encrypt(plaintext)
decrypted = kb_encryptor.decrypt(encrypted) decrypted = kb_encryptor.decrypt(encrypted)
assert decrypted == PLAINTEXT_UTF8_1 assert decrypted == plaintext
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