Skip to content

Commit 5a9e175

Browse files
committed
Add test for doas user warnings when making command.
1 parent be5e3e1 commit 5a9e175

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pyinfra/api/connectors/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def make_unix_command(
266266
_warn_invalid_auth_args(
267267
locals(),
268268
'doas',
269-
('doas_user'),
269+
('doas_user',),
270270
)
271271

272272
if use_sudo_password:

tests/test_connectors/test_util.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,20 @@ def test_command_exists_su_config_only(self):
131131

132132

133133
class TestMakeUnixCommandConnectorUtilWarnings(TestCase):
134+
def test_doas_warnings(self):
135+
state = State(make_inventory(), Config(SU_USER=True, SUDO=True))
136+
137+
with patch('pyinfra.api.connectors.util._warn_invalid_auth_args') as fake_auth_args:
138+
command = make_unix_command('echo Šablony', state=state)
139+
140+
assert command.get_raw_value() == "sh -c 'echo Šablony'"
141+
fake_auth_args.assert_called_once()
142+
_, args, kwargs = fake_auth_args.mock_calls[0]
143+
assert args[1] == 'doas'
144+
assert args[2] == ('doas_user',)
145+
134146
def test_sudo_warnings(self):
135-
state = State(make_inventory(), Config(SU_USER=True))
147+
state = State(make_inventory(), Config(SU_USER=True, DOAS=True))
136148

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

146158
def test_su_warnings(self):
147-
state = State(make_inventory(), Config(SUDO=True))
159+
state = State(make_inventory(), Config(DOAS=True, SUDO=True))
148160

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

0 commit comments

Comments
 (0)