mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
Fix more become plugins (#708)
* Fix more become plugins. * Don't re-use var. * Other way around.
This commit is contained in:
parent
bc5dde0e25
commit
08f10d5758
10 changed files with 113 additions and 8 deletions
|
@ -14,6 +14,27 @@ from ansible import context
|
|||
from .helper import call_become_plugin
|
||||
|
||||
|
||||
def test_doas_basic(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
||||
default_cmd = "/bin/foo"
|
||||
default_exe = "/bin/bash"
|
||||
doas_exe = 'doas'
|
||||
doas_flags = '-n'
|
||||
|
||||
success = 'BECOME-SUCCESS-.+?'
|
||||
|
||||
task = {
|
||||
'become_method': 'community.general.doas',
|
||||
}
|
||||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -c 'echo %s; %s'""" % (doas_exe, doas_flags, default_exe, success,
|
||||
default_cmd), cmd) is not None)
|
||||
|
||||
|
||||
def test_doas(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
|
|
@ -14,6 +14,27 @@ from ansible import context
|
|||
from .helper import call_become_plugin
|
||||
|
||||
|
||||
def test_dzdo_basic(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
||||
default_cmd = "/bin/foo"
|
||||
default_exe = "/bin/bash"
|
||||
dzdo_exe = 'dzdo'
|
||||
dzdo_flags = '-H -S -n'
|
||||
|
||||
success = 'BECOME-SUCCESS-.+?'
|
||||
|
||||
task = {
|
||||
'become_method': 'community.general.dzdo',
|
||||
}
|
||||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s %s -c 'echo %s; %s'""" % (dzdo_exe, dzdo_flags, default_exe,
|
||||
success, default_cmd), cmd) is not None
|
||||
|
||||
|
||||
def test_dzdo(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
|
|
@ -14,6 +14,28 @@ from ansible import context
|
|||
from .helper import call_become_plugin
|
||||
|
||||
|
||||
def test_ksu_basic(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
||||
default_cmd = "/bin/foo"
|
||||
default_exe = "/bin/bash"
|
||||
ksu_exe = 'ksu'
|
||||
ksu_flags = ''
|
||||
|
||||
success = 'BECOME-SUCCESS-.+?'
|
||||
|
||||
task = {
|
||||
'become_user': 'foo',
|
||||
'become_method': 'community.general.ksu',
|
||||
}
|
||||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -e %s -c 'echo %s; %s'""" % (ksu_exe, task['become_user'], ksu_flags,
|
||||
default_exe, success, default_cmd), cmd) is not None)
|
||||
|
||||
|
||||
def test_ksu(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
|
|
@ -14,6 +14,27 @@ from ansible import context
|
|||
from .helper import call_become_plugin
|
||||
|
||||
|
||||
def test_pbrun_basic(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
||||
default_cmd = "/bin/foo"
|
||||
default_exe = "/bin/bash"
|
||||
pbrun_exe = 'pbrun'
|
||||
pbrun_flags = ''
|
||||
|
||||
success = 'BECOME-SUCCESS-.+?'
|
||||
|
||||
task = {
|
||||
'become_method': 'community.general.pbrun',
|
||||
}
|
||||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s 'echo %s; %s'""" % (pbrun_exe, pbrun_flags,
|
||||
success, default_cmd), cmd) is not None
|
||||
|
||||
|
||||
def test_pbrun(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
|
|
@ -14,6 +14,26 @@ from ansible import context
|
|||
from .helper import call_become_plugin
|
||||
|
||||
|
||||
def test_pfexec_basic(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
||||
default_cmd = "/bin/foo"
|
||||
default_exe = "/bin/bash"
|
||||
pfexec_exe = 'pfexec'
|
||||
pfexec_flags = '-H -S -n'
|
||||
|
||||
success = 'BECOME-SUCCESS-.+?'
|
||||
|
||||
task = {
|
||||
'become_method': 'community.general.pfexec',
|
||||
}
|
||||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match('''%s %s "'echo %s; %s'"''' % (pfexec_exe, pfexec_flags, success, default_cmd), cmd) is not None
|
||||
|
||||
|
||||
def test_pfexec(mocker, parser, reset_cli_args):
|
||||
options = parser.parse_args([])
|
||||
context._init_global_context(options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue