From 8310204e66d047565d656b908c05c866ad8a068c Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 6 Oct 2021 09:51:03 -0400 Subject: [PATCH] Tests: Test InvalidCiphertextError --- .../encryption/test_password_based_encryption.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py index a231f3219..0e044c84a 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py @@ -5,39 +5,45 @@ from tests.unit_tests.monkey_island.cc.services.utils.ciphertexts_for_encryption ) from monkey_island.cc.server_utils.encryption import ( + InvalidCiphertextError, InvalidCredentialsError, PasswordBasedStringEncryptor, ) +# Mark all tests in this module as slow +pytestmark = pytest.mark.slow + MONKEY_CONFIGS_DIR_PATH = "monkey_configs" STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME = "monkey_config_standard.json" PASSWORD = "hello123" INCORRECT_PASSWORD = "goodbye321" -@pytest.mark.slow def test_encrypt_decrypt_string(monkey_config_json): pb_encryptor = PasswordBasedStringEncryptor(PASSWORD) encrypted_config = pb_encryptor.encrypt(monkey_config_json) assert pb_encryptor.decrypt(encrypted_config) == monkey_config_json -@pytest.mark.slow def test_decrypt_string__wrong_password(monkey_config_json): pb_encryptor = PasswordBasedStringEncryptor(INCORRECT_PASSWORD) with pytest.raises(InvalidCredentialsError): pb_encryptor.decrypt(VALID_CIPHER_TEXT) -@pytest.mark.slow def test_decrypt_string__malformed_corrupted(): pb_encryptor = PasswordBasedStringEncryptor(PASSWORD) with pytest.raises(ValueError): pb_encryptor.decrypt(MALFORMED_CIPHER_TEXT_CORRUPTED) -@pytest.mark.slow def test_decrypt_string__no_password(monkey_config_json): pb_encryptor = PasswordBasedStringEncryptor("") with pytest.raises(InvalidCredentialsError): pb_encryptor.decrypt(VALID_CIPHER_TEXT) + + +def test_decrypt_string__invalid_cyphertext(monkey_config_json): + pb_encryptor = PasswordBasedStringEncryptor("") + with pytest.raises(InvalidCiphertextError): + pb_encryptor.decrypt("")