Esempio n. 1
0
    def test_logging_values(self):
        param1 = create_script_param_config('p1')
        param2 = create_script_param_config('p2', param='-x')
        param3 = create_script_param_config('p3', param='-y', no_value=True)
        param4 = create_script_param_config('p4', param='-z', type='int')
        config_model = create_config_model(
            'my_script', script_command='echo', parameters=[param1, param2, param3, param4])

        execution_id = self.executor_service.start_script(
            config_model,
            {'p1': 'abc', 'p3': True, 'p4': 987},
            'userX',
            create_audit_names(ip='localhost', auth_username='******'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper._write_script_output('some text\n')
        executor.process_wrapper._write_script_output('another text')
        executor.process_wrapper.finish(0)

        wait_observable_close_notification(executor.get_anonymized_output_stream(), 2)

        entry = self.logging_service.find_history_entry(execution_id, 'userX')
        self.assertIsNotNone(entry)
        self.assertEqual('userX', entry.user_id)
        self.assertEqual('sandy', entry.user_name)
        self.assertEqual('my_script', entry.script_name)
        self.assertEqual('echo abc -y -z 987', entry.command)
        self.assertEqual('my_script', entry.script_name)

        log = self.logging_service.find_log(execution_id)
        self.assertEqual('some text\nanother text', log)
    def test_can_access_different_user(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)

        another_user = create_audit_names('another_user')
        self.assertFalse(
            execution_service.can_access(execution_id, another_user))
    def test_logging_values(self):
        param1 = create_script_param_config('p1')
        param2 = create_script_param_config('p2', param='-x')
        param3 = create_script_param_config('p3', param='-y', no_value=True)
        param4 = create_script_param_config('p4', param='-z', type='int')
        config_model = create_config_model(
            'my_script', script_command='echo', parameters=[param1, param2, param3, param4])

        execution_id = self.executor_service.start_script(
            config_model,
            {'p1': 'abc', 'p3': True, 'p4': 987},
            'userX',
            create_audit_names(ip='localhost', auth_username='******'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper._write_script_output('some text\n')
        executor.process_wrapper._write_script_output('another text')
        executor.process_wrapper.finish(0)

        wait_observable_close_notification(executor.get_anonymized_output_stream(), 2)

        entry = self.logging_service.find_history_entry(execution_id)
        self.assertIsNotNone(entry)
        self.assertEqual('userX', entry.user_id)
        self.assertEqual('sandy', entry.user_name)
        self.assertEqual('my_script', entry.script_name)
        self.assertEqual('echo abc -y -z 987', entry.command)
        self.assertEqual('my_script', entry.script_name)

        log = self.logging_service.find_log(execution_id)
        self.assertEqual('some text\nanother text', log)
Esempio n. 4
0
    def perform_execution(self,
                          output_files,
                          parameter_values=None,
                          parameters=None):
        if parameter_values is None:
            parameter_values = {}

        if parameters is None:
            parameters = [
                create_script_param_config(key)
                for key in parameter_values.keys()
            ]

        config_model = create_config_model('my_script',
                                           output_files=output_files,
                                           parameters=parameters)

        execution_id = self.executor_service.start_script(
            config_model, parameter_values, 'userX',
            create_audit_names(ip='127.0.0.1'))
        self.executor_service.stop_script(execution_id)

        finish_condition = threading.Event()
        self.executor_service.add_finish_listener(
            lambda: finish_condition.set(), execution_id)
        finish_condition.wait(2)

        downloadable_files = self.feature.get_downloadable_files(execution_id)

        return downloadable_files
 def test_custom_name_with_all_audit_names(self):
     filename = self.create_filename(filename_pattern='$IP-$HOSTNAME-$USERNAME-$AUDIT_NAME',
                                     all_audit_names=create_audit_names(
                                         ip='192.168.2.3',
                                         auth_username='******',
                                         proxy_username='******',
                                         hostname='local-pc'))
     self.assertEqual('192.168.2.3-local-pc-bugy-bugy.log', filename)
 def test_custom_name_with_all_audit_names(self):
     filename = self.create_filename(
         filename_pattern='$IP-$HOSTNAME-$USERNAME-$AUDIT_NAME',
         all_audit_names=create_audit_names(ip='192.168.2.3',
                                            auth_username='******',
                                            proxy_username='******',
                                            hostname='local-pc'))
     self.assertEqual('192.168.2.3-local-pc-bugy-bugy.log', filename)
    def test_active_executions_with_different_user(self):
        execution_service = self.create_execution_service()
        self._start(execution_service)
        self._start(execution_service)

        another_user = create_audit_names('another_user')
        self.assertCountEqual(
            [], execution_service.get_active_executions(another_user))
Esempio n. 8
0
    def test_start_logging_on_execution_start(self):
        execution_id = self.executor_service.start_script(
            create_config_model('my_script'), {}, 'userX',
            create_audit_names(ip='localhost'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper.finish(0)

        entry = self.logging_service.find_history_entry(execution_id)
        self.assertIsNotNone(entry)
    def create_filename(filename_pattern=None,
                        date_format=None,
                        id=12345,
                        script_name='my_script',
                        datetime=_DATETIME,
                        all_audit_names=None):
        if all_audit_names is None:
            all_audit_names = create_audit_names(auth_username='******')

        creator = LogNameCreator(filename_pattern, date_format)
        return creator.create_filename(id, all_audit_names, script_name, datetime)
    def create_filename(filename_pattern=None,
                        date_format=None,
                        id=12345,
                        script_name='my_script',
                        datetime=_DATETIME,
                        all_audit_names=None):
        if all_audit_names is None:
            all_audit_names = create_audit_names(auth_username='******')

        creator = LogNameCreator(filename_pattern, date_format)
        return creator.create_filename(id, all_audit_names, script_name,
                                       datetime)
Esempio n. 11
0
    def test_start_logging_on_execution_start(self):
        execution_id = self.executor_service.start_script(
            create_config_model('my_script'),
            {},
            'userX',
            create_audit_names(ip='localhost'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper.finish(0)

        entry = self.logging_service.find_history_entry(execution_id)
        self.assertIsNotNone(entry)
Esempio n. 12
0
    def test_exit_code(self):
        config_model = create_config_model('my_script',
                                           script_command='ls',
                                           parameters=[])

        execution_id = self.executor_service.start_script(
            config_model, {}, 'userX', create_audit_names(ip='localhost'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper._write_script_output('some text\n')
        executor.process_wrapper._write_script_output('another text')
        executor.process_wrapper.finish(14)

        wait_observable_close_notification(
            executor.get_anonymized_output_stream(), 2)

        entry = self.logging_service.find_history_entry(execution_id)
        self.assertEqual(14, entry.exit_code)
Esempio n. 13
0
    def test_exit_code(self):
        config_model = create_config_model(
            'my_script', script_command='ls', parameters=[])

        execution_id = self.executor_service.start_script(
            config_model,
            {},
            'userX',
            create_audit_names(ip='localhost'))

        executor = self.executor_service.get_active_executor(execution_id)
        executor.process_wrapper._write_script_output('some text\n')
        executor.process_wrapper._write_script_output('another text')
        executor.process_wrapper.finish(14)

        wait_observable_close_notification(executor.get_anonymized_output_stream(), 2)

        entry = self.logging_service.find_history_entry(execution_id)
        self.assertEqual(14, entry.exit_code)
    def perform_execution(self, output_files, parameter_values=None, parameters=None):
        if parameter_values is None:
            parameter_values = {}

        if parameters is None:
            parameters = [create_script_param_config(key) for key in parameter_values.keys()]

        config_model = create_config_model('my_script', output_files=output_files, parameters=parameters)

        execution_id = self.executor_service.start_script(
            config_model, parameter_values, 'userX', create_audit_names(ip='127.0.0.1'))
        self.executor_service.stop_script(execution_id)

        finish_condition = threading.Event()
        self.executor_service.add_finish_listener(lambda: finish_condition.set(), execution_id)
        finish_condition.wait(2)

        downloadable_files = self.feature.get_downloadable_files(execution_id)

        return downloadable_files
 def test_replace_whitespaces(self):
     filename = self.create_filename(date_format='%H %M %S',
                                     script_name='hello world',
                                     all_audit_names=create_audit_names(auth_username='******'))
     self.assertEqual('hello_world_a_b_08_30_26.log', filename)
 def test_replace_whitespaces(self):
     filename = self.create_filename(
         date_format='%H %M %S',
         script_name='hello world',
         all_audit_names=create_audit_names(auth_username='******'))
     self.assertEqual('hello_world_a_b_08_30_26.log', filename)
from parameterized import parameterized

from auth.authorization import Authorizer, ANY_USER, EmptyGroupProvider
from auth.user import User
from execution import executor
from execution.execution_service import ExecutionService
from execution.executor import create_process_wrapper
from model.model_helper import AccessProhibitedException
from model.script_config import ConfigModel
from tests import test_utils
from tests.test_utils import mock_object, create_audit_names, _MockProcessWrapper, _IdGeneratorMock
from utils import audit_utils

DEFAULT_USER_ID = 'test_user'
DEFAULT_AUDIT_NAMES = create_audit_names(auth_username=DEFAULT_USER_ID)
DEFAULT_USER = User(DEFAULT_USER_ID, DEFAULT_AUDIT_NAMES)

execution_owners = {}


class ExecutionServiceTest(unittest.TestCase):
    def test_start_script(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)

        self.assertEqual(self.get_last_id(), execution_id)

    def test_is_running_after_start(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)
Esempio n. 18
0
import copy
import unittest

from execution import executor
from execution.execution_service import ExecutionService
from model.script_config import ConfigModel
from tests import test_utils
from tests.test_utils import mock_object, create_audit_names, _MockProcessWrapper, _IdGeneratorMock

DEFAULT_USER = '******'
DEFAULT_AUDIT_NAMES = create_audit_names(auth_username=DEFAULT_USER)


class ExecutionServiceTest(unittest.TestCase):
    def test_start_script(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)

        self.assertEqual(self.get_last_id(), execution_id)

    def test_is_running_after_start(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)

        self.assertTrue(execution_service.is_running(execution_id))

    def test_is_running_after_stop(self):
        execution_service = self.create_execution_service()
        execution_id = self._start(execution_service)
        process = self.get_process(execution_id)
        process.stop()