diff --git a/monkey/monkey_island/cc/server_utils/file_utils.py b/monkey/monkey_island/cc/server_utils/file_utils.py index 25161ca2f..995501c09 100644 --- a/monkey/monkey_island/cc/server_utils/file_utils.py +++ b/monkey/monkey_island/cc/server_utils/file_utils.py @@ -55,11 +55,10 @@ def _create_secure_directory_windows(path: str): def get_file_descriptor_for_new_secure_file(path: str) -> int: - if not os.path.isfile(path): - if is_windows_os(): - return _get_file_descriptor_for_new_secure_file_windows(path) - else: - return _get_file_descriptor_for_new_secure_file_linux(path) + if is_windows_os(): + return _get_file_descriptor_for_new_secure_file_windows(path) + else: + return _get_file_descriptor_for_new_secure_file_linux(path) def _get_file_descriptor_for_new_secure_file_linux(path: str) -> int: diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py index ac0c20abe..7e3e10ed6 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_file_utils.py @@ -98,8 +98,9 @@ def test_create_secure_directory__perm_windows(test_path): def test_create_secure_file__already_created(test_path): os.close(os.open(test_path, os.O_CREAT, stat.S_IRWXU)) assert os.path.isfile(test_path) - # test fails if any exceptions are thrown - get_file_descriptor_for_new_secure_file(test_path) + + with pytest.raises(Exception): + get_file_descriptor_for_new_secure_file(test_path) def test_create_secure_file__no_parent_dir(test_path_nested):