cc: expanduser in data_dir path in Encryptor

This commit is contained in:
Mike Salvatore 2021-02-16 10:59:35 -05:00
parent d265238107
commit a09cd8f497
2 changed files with 11 additions and 1 deletions

View File

@ -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)

View File

@ -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"))