Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for presence of systemd unit file before encryption #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion vaultlocker/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,16 @@ def encrypt(args, config):
:param: args: argparser generated cli arguments
:param: config: configparser object of vaultlocker config
"""
_do_it_with_persistence(_encrypt_block_device, args, config)
if os.path.exists(
"/usr/lib/systemd/system/[email protected]"
) or os.path.exists(
"/etc/systemd/system/[email protected]"):
_do_it_with_persistence(_encrypt_block_device, args, config)
else:
raise FileNotFoundError("""
Systemd Unit [email protected] not found
in /usr/lib/systemd/system/ or /etc/systemd/system/
""")


def decrypt(args, config):
Expand Down
10 changes: 10 additions & 0 deletions vaultlocker/tests/functional/test_keystorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ def test_encrypt(self, _luks_open, _luks_format, _systemd,
args.block_device = ['/dev/sdb']
args.retry = -1

def mock_path_exists_side_effect(arg):
if arg in ['/usr/lib/systemd/system/[email protected]',
'/etc/systemd/system/[email protected]']:
return True
else:
return False

mock_pathexists = mock.patch('os.path.exists').start()
mock_pathexists.side_effect = mock_path_exists_side_effect
shell.encrypt(args, self.config)

_luks_format.assert_called_once_with(mock.ANY,
'/dev/sdb',
'passed-UUID')
Expand Down