From a09cd8f49743dec1bc18ed27a9d360229f60f3ac Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 16 Feb 2021 10:59:35 -0500 Subject: [PATCH] cc: expanduser in data_dir path in Encryptor --- monkey/monkey_island/cc/server_utils/encryptor.py | 4 +++- monkey/monkey_island/cc/test_encryptor.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/server_utils/encryptor.py b/monkey/monkey_island/cc/server_utils/encryptor.py index dd088530f..36fff735c 100644 --- a/monkey/monkey_island/cc/server_utils/encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryptor.py @@ -16,7 +16,9 @@ class Encryptor: _PASSWORD_FILENAME = "mongo_key.bin" def __init__(self, data_dir): - password_file = os.path.join(data_dir, self._PASSWORD_FILENAME) + password_file = os.path.expanduser( + os.path.join(data_dir, self._PASSWORD_FILENAME) + ) if os.path.exists(password_file): self._load_existing_key(password_file) diff --git a/monkey/monkey_island/cc/test_encryptor.py b/monkey/monkey_island/cc/test_encryptor.py index 9a424cc01..3380d1d43 100644 --- a/monkey/monkey_island/cc/test_encryptor.py +++ b/monkey/monkey_island/cc/test_encryptor.py @@ -27,3 +27,11 @@ def test_create_new_password_file(tmpdir): initialize_encryptor(tmpdir) assert os.path.isfile(os.path.join(tmpdir, PASSWORD_FILENAME)) + + +def test_expand_home(monkeypatch, tmpdir): + monkeypatch.setenv("HOME", str(tmpdir)) + + initialize_encryptor("~/") + + assert os.path.isfile(os.path.join(tmpdir, "mongo_key.bin"))