summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-12-02 11:58:01 -0500
committerGitHub <noreply@github.com>2021-12-02 11:58:01 -0500
commitb02168d644dfaff1f76f52931d7b41485c2753a3 (patch)
tree8dd0a624edd732601593920e8aed04410724d421 /test
parent480d47d071cc6ed08b80209a3fa75b64311ea648 (diff)
downloadansible-b02168d644dfaff1f76f52931d7b41485c2753a3.tar.gz
better handling of sudo flag replacement (#76389)
* better handling of sudo flag replacement
Diffstat (limited to 'test')
-rw-r--r--test/units/plugins/become/test_sudo.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/units/plugins/become/test_sudo.py b/test/units/plugins/become/test_sudo.py
index 8ccb2a12c3..67eb9a46b4 100644
--- a/test/units/plugins/become/test_sudo.py
+++ b/test/units/plugins/become/test_sudo.py
@@ -38,3 +38,30 @@ def test_sudo(mocker, parser, reset_cli_args):
cmd = sudo.build_become_command('/bin/foo', sh)
assert re.match(r"""sudo\s+-s\s-H\s+-p "\[sudo via ansible, key=.+?\] password:" -u foo /bin/bash -c 'echo BECOME-SUCCESS-.+? ; /bin/foo'""", cmd), cmd
+
+ sudo.set_options(direct={
+ 'become_user': 'foo',
+ 'become_flags': '-snH',
+ 'become_pass': 'testpass',
+ })
+
+ cmd = sudo.build_become_command('/bin/foo', sh)
+ assert re.match(r"""sudo\s+-sH\s+-p "\[sudo via ansible, key=.+?\] password:" -u foo /bin/bash -c 'echo BECOME-SUCCESS-.+? ; /bin/foo'""", cmd), cmd
+
+ sudo.set_options(direct={
+ 'become_user': 'foo',
+ 'become_flags': '--non-interactive -s -H',
+ 'become_pass': 'testpass',
+ })
+
+ cmd = sudo.build_become_command('/bin/foo', sh)
+ assert re.match(r"""sudo\s+-s\s-H\s+-p "\[sudo via ansible, key=.+?\] password:" -u foo /bin/bash -c 'echo BECOME-SUCCESS-.+? ; /bin/foo'""", cmd), cmd
+
+ sudo.set_options(direct={
+ 'become_user': 'foo',
+ 'become_flags': '--non-interactive -nC5 -s -H',
+ 'become_pass': 'testpass',
+ })
+
+ cmd = sudo.build_become_command('/bin/foo', sh)
+ assert re.match(r"""sudo\s+-C5\s-s\s-H\s+-p "\[sudo via ansible, key=.+?\] password:" -u foo /bin/bash -c 'echo BECOME-SUCCESS-.+? ; /bin/foo'""", cmd), cmd