def test_run_command_injection_error(): out, err, rc = run_command( executable_cmd='whoami', cmdline_args=[';hostname'], runner_mode='subprocess', ) assert rc == 1 assert "usage: whoami" in err or "whoami: extra operand ‘;hostname’" in err
def test_run_command(test_data_dir): private_data_dir = os.path.join(test_data_dir, 'debug') inventory = os.path.join(private_data_dir, 'inventory', 'inv_1') playbook = os.path.join(private_data_dir, 'project', 'debug.yml') out, err = run_command(private_data_dir=private_data_dir, executable_cmd='ansible-playbook', cmdline_args=[playbook, '-i', inventory]) assert "Hello world!" in out assert err == ''
def test_run_command_injection_error_within_container(runtime): out, err, rc = run_command( executable_cmd='whoami', cmdline_args=[';hostname'], runner_mode='subprocess', process_isolation_executable=runtime, process_isolation=True, container_image=defaults.default_container_image, ) assert rc == 1 assert "whoami: extra operand ';hostname'" in err
def test_run_command(project_fixtures): private_data_dir = project_fixtures / 'debug' inventory = private_data_dir / 'inventory' / 'inv_1' playbook = private_data_dir / 'project' / 'debug.yml' out, err, rc = run_command( private_data_dir=private_data_dir, executable_cmd='ansible-playbook', cmdline_args=[str(playbook), '-i', str(inventory)] ) assert "Hello world!" in out assert rc == 0 assert err == ''
def test_run_ansible_command_within_container(test_data_dir, container_runtime_installed): private_data_dir = os.path.join(test_data_dir, 'debug') inventory = os.path.join(private_data_dir, 'inventory', 'inv_1') playbook = os.path.join(private_data_dir, 'project', 'debug.yml') container_kwargs = { 'process_isolation_executable': container_runtime_installed, 'process_isolation': True, 'container_image': defaults.default_container_image } out, err = run_command(private_data_dir=private_data_dir, executable_cmd='ansible-playbook', cmdline_args=[playbook, '-i', inventory], **container_kwargs) assert "Hello world!" in out assert err == ''
def test_run_script_within_container(test_data_dir, container_runtime_installed): private_data_dir = os.path.join(test_data_dir, 'debug') script_path = os.path.join(test_data_dir, 'files') container_volume_mounts = ["{}:{}:Z".format(script_path, script_path)] container_kwargs = { 'process_isolation_executable': container_runtime_installed, 'process_isolation': True, 'container_image': defaults.default_container_image, 'container_volume_mounts': container_volume_mounts } out, _ = run_command( private_data_dir=private_data_dir, executable_cmd='python3', cmdline_args=[os.path.join(script_path, 'test_ee.py')], **container_kwargs) assert "os-release" in out
def test_run_ansible_command_within_container(project_fixtures, runtime): private_data_dir = project_fixtures / 'debug' inventory = private_data_dir / 'inventory' / 'inv_1' playbook = private_data_dir / 'project' / 'debug.yml' container_kwargs = { 'process_isolation_executable': runtime, 'process_isolation': True, 'container_image': defaults.default_container_image } out, err, rc = run_command( private_data_dir=private_data_dir, executable_cmd='ansible-playbook', cmdline_args=[str(playbook), '-i', str(inventory)], **container_kwargs ) assert "Hello world!" in out assert rc == 0 assert err == ''
def test_run_script_within_container(project_fixtures, runtime): private_data_dir = project_fixtures / 'debug' script_path = project_fixtures / 'files' container_volume_mounts = ["{}:{}:Z".format(script_path, script_path)] container_kwargs = { 'process_isolation_executable': runtime, 'process_isolation': True, 'container_image': defaults.default_container_image, 'container_volume_mounts': container_volume_mounts } out, _, rc = run_command( private_data_dir=private_data_dir, executable_cmd='python3', cmdline_args=[str(script_path / 'test_ee.py')], **container_kwargs ) assert "os-release" in out assert rc == 0