Пример #1
0
class BlockingShellTests(BaseTestCase):
    def before(self):
        environment_builder = InteractiveShellEnvironmentBuilder()
        environment_builder._create_core_mock()
        self.core_mock = environment_builder.core_mock
        self.shell = Shell(self.core_mock)

    def test_shell_exec_monitor_runs_a_command_logging_the_output(self):
        stream = StreamMock()
        self.redirect_logging_to_stream(stream)
        command = 'pwd'
        expected_command_output = self.get_abs_path(".")
        expected_time_logging_message = "Execution Start Date/Time"

        command_output = self.shell.shell_exec_monitor(command)

        assert_that(command_output, matches_regexp(expected_command_output))
        assert_that(stream.get_content(),
                    matches_regexp(expected_time_logging_message))
        assert_that(stream.get_content(),
                    matches_regexp(expected_command_output))

    def test_shell_exec_monitor_with_KeyboardInterrupt_should_cancel_the_command(
            self):
        subprocess = flexmock()
        subprocess.stdout = flexmock()
        subprocess.stdout.should_receive("readline").and_raise(
            KeyboardInterrupt).once()
        flexmock(self.shell)
        self.shell.should_receive("create_subprocess").and_return(subprocess)

        def fake_finish_command(arg1, cancelled):
            assert_that(cancelled, is_(True))

        self.shell.FinishCommand = fake_finish_command

        self.shell.shell_exec_monitor("pwd")

    def redirect_logging_to_stream(self, stream):
        logging_handler = logging.StreamHandler(stream)
        logger = getDefaultLog("info")
        logger.addHandler(logging_handler)
Пример #2
0
class BlockingShellTests(BaseTestCase):

    def before(self):
        environment_builder = InteractiveShellEnvironmentBuilder()
        environment_builder._create_core_mock()
        self.core_mock = environment_builder.core_mock
        self.shell = Shell(self.core_mock)

    def test_shell_exec_monitor_runs_a_command_logging_the_output(self):
        stream = StreamMock()
        self.redirect_logging_to_stream(stream)
        command = 'pwd'
        expected_command_output = self.get_abs_path(".")
        expected_time_logging_message = "Execution Start Date/Time"

        command_output = self.shell.shell_exec_monitor(command)

        assert_that(command_output, matches_regexp(expected_command_output))
        assert_that(stream.get_content(), matches_regexp(expected_time_logging_message))
        assert_that(stream.get_content(), matches_regexp(expected_command_output))

    def test_shell_exec_monitor_with_KeyboardInterrupt_should_cancel_the_command(self):
        subprocess = flexmock()
        subprocess.stdout = flexmock()
        subprocess.stdout.should_receive("readline").and_raise(KeyboardInterrupt).once()
        flexmock(self.shell)
        self.shell.should_receive("create_subprocess").and_return(subprocess)
        def fake_finish_command(arg1, cancelled):
            assert_that(cancelled, is_(True))
        self.shell.FinishCommand = fake_finish_command

        self.shell.shell_exec_monitor("pwd")

    def redirect_logging_to_stream(self, stream):
        logging_handler = logging.StreamHandler(stream)
        logger = get_default_logger("info")
        logger.addHandler(logging_handler)
Пример #3
0
    def initialisation_phase_2(args):
        """ Second phase of the initialization process.

        :param dict args: parsed arguments from the command line.
        """
        PluginHandler(args)
        Reporter()
        POutputDB()
        ServiceLocator.get_component("command_register").init()
        ServiceLocator.get_component("worklist_manager").init()
        Shell()
        PluginParams(args)
        SMTP()
        #DebugDB()
        ZAP_API()
Пример #4
0
    def initialisation_phase_2(args):
        """ Second phase of the initialization process.

        :param dict args: parsed arguments from the command line.
        """
        db_config = ServiceLocator.get_component("db_config")
        db_config.init()
        Timer(db_config.Get('DATE_TIME_FORMAT'))
        ServiceLocator.get_component("db_plugin").init()
        ServiceLocator.get_component("config").init()
        ServiceLocator.get_component("zest").init()
        PluginHandler(args)
        Reporter()
        POutputDB()
        ServiceLocator.get_component("command_register").init()
        ServiceLocator.get_component("worklist_manager").init()
        Shell()
        PluginParams(args)
        SMB()
        InteractiveShell()
        Selenium()
        SMTP()
        SETHandler()
        ZAP_API()
Пример #5
0
 def before(self):
     environment_builder = InteractiveShellEnvironmentBuilder()
     environment_builder._create_core_mock()
     self.core_mock = environment_builder.core_mock
     self.shell = Shell(self.core_mock)
Пример #6
0
 def _prepare_core_mock(self):
     self.core_mock = flexmock()
     self.core_mock.Shell = Shell(self.core_mock)
     self.core_mock.Config = self._build_stub_for_config()
     self.core_mock.Error = self._build_stub_for_error_handler()