diff --git a/tests/ansible/integration/stub_connections/all.yml b/tests/ansible/integration/stub_connections/all.yml index 5a3f37cf..a9744ab7 100644 --- a/tests/ansible/integration/stub_connections/all.yml +++ b/tests/ansible/integration/stub_connections/all.yml @@ -1,6 +1,7 @@ - import_playbook: kubectl.yml - import_playbook: lxc.yml - import_playbook: lxd.yml +- import_playbook: mitogen_doas.yml +- import_playbook: mitogen_sudo.yml - import_playbook: setns_lxc.yml - import_playbook: setns_lxd.yml -- import_playbook: sudo.yml diff --git a/tests/ansible/integration/stub_connections/mitogen_doas.yml b/tests/ansible/integration/stub_connections/mitogen_doas.yml new file mode 100644 index 00000000..40d4f4b0 --- /dev/null +++ b/tests/ansible/integration/stub_connections/mitogen_doas.yml @@ -0,0 +1,21 @@ + +- name: integration/stub_connections/mitogen_doas.yml + hosts: test-targets + gather_facts: false + any_errors_fatal: true + tasks: + - meta: end_play + when: not is_mitogen + + - custom_python_detect_environment: + vars: + ansible_connection: mitogen_doas + ansible_become_exe: stub-doas.py + ansible_user: someuser + register: out + + - debug: var=out.env.ORIGINAL_ARGV + - assert: + that: + - out.env.THIS_IS_STUB_DOAS == '1' + - (out.env.ORIGINAL_ARGV|from_json)[1:3] == ['-u', 'someuser'] diff --git a/tests/ansible/integration/stub_connections/sudo.yml b/tests/ansible/integration/stub_connections/mitogen_sudo.yml similarity index 90% rename from tests/ansible/integration/stub_connections/sudo.yml rename to tests/ansible/integration/stub_connections/mitogen_sudo.yml index b5e6f263..b82b3ac2 100644 --- a/tests/ansible/integration/stub_connections/sudo.yml +++ b/tests/ansible/integration/stub_connections/mitogen_sudo.yml @@ -1,5 +1,5 @@ -- name: integration/stub_connections/sudo.yml +- name: integration/stub_connections/mitogen_sudo.yml hosts: test-targets gather_facts: false any_errors_fatal: true diff --git a/tests/data/stubs/stub-doas.py b/tests/data/stubs/stub-doas.py new file mode 100755 index 00000000..08caf044 --- /dev/null +++ b/tests/data/stubs/stub-doas.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +import json +import os +import sys + +os.environ['ORIGINAL_ARGV'] = json.dumps(sys.argv) +os.environ['THIS_IS_STUB_DOAS'] = '1' +os.execv(sys.executable, sys.argv[sys.argv.index('--') + 1:]) diff --git a/tests/doas_test.py b/tests/doas_test.py new file mode 100644 index 00000000..0e27c2ab --- /dev/null +++ b/tests/doas_test.py @@ -0,0 +1,31 @@ + +import os + +import mitogen +import mitogen.parent + +import unittest2 + +import testlib + + +class ConstructorTest(testlib.RouterMixin, testlib.TestCase): + doas_path = testlib.data_path('stubs/stub-doas.py') + + def test_okay(self): + context = self.router.doas( + doas_path=self.doas_path, + username='someuser', + ) + argv = eval(context.call(os.getenv, 'ORIGINAL_ARGV')) + self.assertEquals(argv[:4], [ + self.doas_path, + '-u', + 'someuser', + '--', + ]) + self.assertEquals('1', context.call(os.getenv, 'THIS_IS_STUB_DOAS')) + + +if __name__ == '__main__': + unittest2.main()