tests: stub tests for doas/mitogen_doas
parent
cbd4129cb9
commit
fd326f5ad7
@ -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']
|
@ -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
|
@ -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:])
|
@ -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()
|
Loading…
Reference in New Issue