Skip to content

Commit

Permalink
Add test for doas user warnings when making command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Oct 15, 2021
1 parent e22b89d commit f01ba12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyinfra/api/connectors/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def make_unix_command(
_warn_invalid_auth_args(
locals(),
'doas',
('doas_user'),
('doas_user',),
)

if use_sudo_password:
Expand Down
16 changes: 14 additions & 2 deletions tests/test_connectors/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,20 @@ def test_command_exists_su_config_only(self):


class TestMakeUnixCommandConnectorUtilWarnings(TestCase):
def test_doas_warnings(self):
state = State(make_inventory(), Config(SU_USER=True, SUDO=True))

with patch('pyinfra.api.connectors.util._warn_invalid_auth_args') as fake_auth_args:
command = make_unix_command('echo Šablony', state=state)

assert command.get_raw_value() == "sh -c 'echo Šablony'"
fake_auth_args.assert_called_once()
_, args, kwargs = fake_auth_args.mock_calls[0]
assert args[1] == 'doas'
assert args[2] == ('doas_user',)

def test_sudo_warnings(self):
state = State(make_inventory(), Config(SU_USER=True))
state = State(make_inventory(), Config(SU_USER=True, DOAS=True))

with patch('pyinfra.api.connectors.util._warn_invalid_auth_args') as fake_auth_args:
command = make_unix_command('echo Šablony', state=state)
Expand All @@ -144,7 +156,7 @@ def test_sudo_warnings(self):
assert args[2] == ('use_sudo_password', 'use_sudo_login', 'preserve_sudo_env', 'sudo_user')

def test_su_warnings(self):
state = State(make_inventory(), Config(SUDO=True))
state = State(make_inventory(), Config(DOAS=True, SUDO=True))

with patch('pyinfra.api.connectors.util._warn_invalid_auth_args') as fake_auth_args:
command = make_unix_command('echo Šablony', state=state)
Expand Down

0 comments on commit f01ba12

Please sign in to comment.