tests: Add unit test for ransomware target dir path with env variables

This commit is contained in:
Shreya 2021-07-05 19:10:21 +05:30
parent 8ef6a50180
commit 8afd69634c
2 changed files with 25 additions and 0 deletions

View File

@ -4,6 +4,13 @@ from pathlib import Path
import pytest
@pytest.fixture
def patched_home_env(monkeypatch, tmp_path):
monkeypatch.setenv("HOME", str(tmp_path))
return tmp_path
@pytest.fixture
def ransomware_target(tmp_path, data_for_tests_dir):
ransomware_test_data = Path(data_for_tests_dir) / "ransomware_targets"

View File

@ -48,6 +48,24 @@ def ransomware_payload(ransomware_payload_config, telemetry_messenger_spy):
return RansomwarePayload(ransomware_payload_config, telemetry_messenger_spy)
def test_env_variables_in_target_dir_resolved_linux(
ransomware_payload_config, ransomware_target, telemetry_messenger_spy, patched_home_env
):
path_with_env_variable = "$HOME/ransomware_target"
ransomware_payload_config["encryption"]["directories"][
"linux_target_dir"
] = ransomware_payload_config["encryption"]["directories"][
"windows_target_dir"
] = path_with_env_variable
RansomwarePayload(ransomware_payload_config, telemetry_messenger_spy).run_payload()
assert (
hash_file(ransomware_target / with_extension(ALL_ZEROS_PDF))
== ALL_ZEROS_PDF_ENCRYPTED_SHA256
)
def test_file_with_excluded_extension_not_encrypted(ransomware_target, ransomware_payload):
ransomware_payload.run_payload()