From 6282cd0de333e2d834a7e9d4d5fedb841657f340 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 7 Jul 2021 10:48:35 +0300 Subject: [PATCH] Add a UT to test if ransomware payload tries to encrypt files if "linux_target_dir" and "windows_target_dir" inputs are empty. We have empty "linux_target_dir" and "windows_target_dir" by default so it's important that ransomware payload doesn't try to encrypt files by default, without users' knowledge. --- .../ransomware/test_ransomware_payload.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py b/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py index 2014c7486..f0cb6bad9 100644 --- a/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py +++ b/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py @@ -163,6 +163,24 @@ def test_encryption_skipped_if_configured_false( assert hash_file(ransomware_target / TEST_KEYBOARD_TXT) == TEST_KEYBOARD_TXT_CLEARTEXT_SHA256 +def test_encryption_skipped_if_no_directory( + ransomware_payload_config, telemetry_messenger_spy, monkeypatch +): + ransomware_payload_config["encryption"]["enabled"] = True + ransomware_payload_config["encryption"]["directories"]["linux_target_dir"] = "" + ransomware_payload_config["encryption"]["directories"]["windows_target_dir"] = "" + + def _file_encryption_method_mock(*args, **kwargs): + raise Exception( + "Ransomware payload attempted to " + "encrypt files even though no directory was provided!" + ) + + ransomware_payload = RansomwarePayload(ransomware_payload_config, telemetry_messenger_spy) + monkeypatch.setattr(ransomware_payload, "_encrypt_files", _file_encryption_method_mock) + ransomware_payload.run_payload() + + def test_telemetry_success(ransomware_payload, telemetry_messenger_spy): ransomware_payload.run_payload()