Exemple #1
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.workers = 0

        test_tool = tools.CLITool()
        workers.WorkersArgumentsHelper.ParseOptions(options, test_tool)

        self.assertEqual(test_tool._number_of_extraction_workers,
                         options.workers)

        with self.assertRaises(errors.BadConfigObject):
            workers.WorkersArgumentsHelper.ParseOptions(options, None)

        with self.assertRaises(errors.BadConfigOption):
            options.workers = 'bogus'
            workers.WorkersArgumentsHelper.ParseOptions(options, test_tool)

        with self.assertRaises(errors.BadConfigOption):
            options.workers = -1
            workers.WorkersArgumentsHelper.ParseOptions(options, test_tool)

        with self.assertRaises(errors.BadConfigOption):
            options.worker_memory_limit = 'bogus'
            workers.WorkersArgumentsHelper.ParseOptions(options, test_tool)

        with self.assertRaises(errors.BadConfigOption):
            options.worker_memory_limit = -1
            workers.WorkersArgumentsHelper.ParseOptions(options, test_tool)
Exemple #2
0
    def testParseProfilingOptions(self):
        """Tests the _ParseProfilingOptions function."""
        test_tool = tools.CLITool()

        options = test_lib.TestOptions()
        options.profiling_sample_rate = '100'

        test_tool._ParseProfilingOptions(options)
        self.assertEqual(test_tool._profilers, set([]))

        options.profilers = 'list'
        test_tool._ParseProfilingOptions(options)
        self.assertEqual(test_tool._profilers, set([]))

        with shared_test_lib.TempDirectory() as temp_directory:
            options.profilers = 'processing'
            options.profiling_directory = temp_directory
            test_tool._ParseProfilingOptions(options)
            self.assertEqual(test_tool._profilers, set(['processing']))
            self.assertEqual(test_tool._profiling_directory, temp_directory)
            self.assertEqual(test_tool._profiling_sample_rate, 100)

        with self.assertRaises(errors.BadConfigOption):
            options.profiling_sample_rate = 'a'
            test_tool._ParseProfilingOptions(options)

        with self.assertRaises(errors.BadConfigOption):
            options.profiling_sample_rate = 100
            test_tool._ParseProfilingOptions(options)

        with self.assertRaises(errors.BadConfigOption):
            options.profiling_sample_rate = '/bogus'
            options.profiling_sample_rate = 100
            test_tool._ParseProfilingOptions(options)
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.date_filters = [
            'ctime,2012-05-25 15:59:00,2012-05-25 15:59:20'
        ]

        test_tool = tools.CLITool()

        with self.assertRaises(errors.BadConfigObject):
            date_filters.DateFiltersArgumentsHelper.ParseOptions(options, None)

        with self.assertRaises(errors.BadConfigObject):
            test_tool._filter_collection = None
            date_filters.DateFiltersArgumentsHelper.ParseOptions(
                options, test_tool)

        test_tool._filter_collection = (
            file_entry_filters.FileEntryFilterCollection())

        date_filters.DateFiltersArgumentsHelper.ParseOptions(
            options, test_tool)
        self.assertTrue(test_tool._filter_collection.HasFilters())

        with self.assertRaises(errors.BadConfigOption):
            options.date_filters = ['ctime,2012-05-25 15:59:00']
            date_filters.DateFiltersArgumentsHelper.ParseOptions(
                options, test_tool)

        with self.assertRaises(errors.BadConfigOption):
            options.date_filters = [
                'ctime,2012-05-25 15:59:00,2012-05-A5 15:59:20'
            ]
            date_filters.DateFiltersArgumentsHelper.ParseOptions(
                options, test_tool)
Exemple #4
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        test_file_path = self._GetTestFilePath(['yara.rules'])
        invalid_rules_path = self._GetTestFilePath(['another_file'])
        non_existent_rules_path = '/tmp/non_existant'
        self._SkipIfPathNotExists(test_file_path)

        options = cli_test_lib.TestOptions()
        options.yara_rules_path = test_file_path

        test_tool = tools.CLITool()
        yara_rules.YaraRulesArgumentsHelper.ParseOptions(options, test_tool)

        self.assertIsNotNone(test_tool._yara_rules_string)

        with self.assertRaises(errors.BadConfigObject):
            yara_rules.YaraRulesArgumentsHelper.ParseOptions(options, None)

        options.yara_rules_path = non_existent_rules_path
        with self.assertRaises(errors.BadConfigOption):
            yara_rules.YaraRulesArgumentsHelper.ParseOptions(
                options, test_tool)

        options.yara_rules_path = invalid_rules_path
        with self.assertRaises(errors.BadConfigOption):
            yara_rules.YaraRulesArgumentsHelper.ParseOptions(
                options, test_tool)
Exemple #5
0
  def testPrintColumnValue(self):
    """Tests the PrintColumnValue function."""
    output_writer = test_lib.TestOutputWriter()
    cli_tool = tools.CLITool(output_writer=output_writer)

    cli_tool.PrintColumnValue(u'Name', u'Description')
    string = output_writer.ReadOutput()
    expected_string = b'                     Name : Description\n'
    self.assertEqual(string, expected_string)

    cli_tool.PrintColumnValue(u'Name', u'Description', column_width=10)
    string = output_writer.ReadOutput()
    expected_string = b'      Name : Description\n'
    self.assertEqual(string, expected_string)

    with self.assertRaises(ValueError):
      cli_tool.PrintColumnValue(u'Name', u'Description', column_width=-10)

    # TODO: determine if this is the desired behavior.
    cli_tool.PrintColumnValue(u'Name', u'Description', column_width=100)
    string = output_writer.ReadOutput()
    expected_string = (
        b'                                                                     '
        b'                           Name : \n'
        b'                                                                     '
        b'                                  Description\n')
    self.assertEqual(string, expected_string)
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.artifact_filter_string = 'TestFiles, TestFiles2'
        expected_output = ['TestFiles', 'TestFiles2']

        test_tool = tools.CLITool()
        artifact_filters.ArtifactFiltersArgumentsHelper.ParseOptions(
            options, test_tool)

        self.assertEqual(test_tool._artifact_filters, expected_output)

        options.artifact_filters_file = self._GetTestFilePath(
            ['artifacts', 'artifact_names'])

        with self.assertRaises(errors.BadConfigOption):
            artifact_filters.ArtifactFiltersArgumentsHelper.ParseOptions(
                options, test_tool)

        expected_output = ['TestFiles', 'TestFiles2', 'TestFiles3']

        options.artifact_filter_string = None
        artifact_filters.ArtifactFiltersArgumentsHelper.ParseOptions(
            options, test_tool)

        self.assertEqual(test_tool._artifact_filters, expected_output)

        options.file_filter = self._GetTestFilePath(['testdir', 'filter2.txt'])
        with self.assertRaises(errors.BadConfigOption):
            artifact_filters.ArtifactFiltersArgumentsHelper.ParseOptions(
                options, test_tool)

        with self.assertRaises(errors.BadConfigObject):
            artifact_filters.ArtifactFiltersArgumentsHelper.ParseOptions(
                options, None)
Exemple #7
0
    def testGetCommandLineArguments(self):
        """Tests the GetCommandLineArguments function."""
        cli_tool = tools.CLITool()
        cli_tool.preferred_encoding = 'UTF-8'

        command_line_arguments = cli_tool.GetCommandLineArguments()
        self.assertIsNotNone(command_line_arguments)
Exemple #8
0
    def testParseNumericOption(self):
        """Tests the ParseNumericOption function."""
        output_writer = test_lib.TestBinaryOutputWriter()
        cli_tool = tools.CLITool(output_writer=output_writer)

        options = test_lib.TestOptions()

        numeric_value = cli_tool.ParseNumericOption(options, 'buffer_size')
        self.assertIsNone(numeric_value)

        numeric_value = cli_tool.ParseNumericOption(options,
                                                    'buffer_size',
                                                    default_value=0)
        self.assertEqual(numeric_value, 0)

        options.buffer_size = '10'

        numeric_value = cli_tool.ParseNumericOption(options, 'buffer_size')
        self.assertEqual(numeric_value, 10)

        numeric_value = cli_tool.ParseNumericOption(options,
                                                    'buffer_size',
                                                    base=16)
        self.assertEqual(numeric_value, 16)

        options.buffer_size = 'bogus'

        with self.assertRaises(errors.BadConfigOption):
            cli_tool.ParseNumericOption(options, 'buffer_size')

        options.buffer_size = (1, 'bogus')

        with self.assertRaises(errors.BadConfigOption):
            cli_tool.ParseNumericOption(options, 'buffer_size')
Exemple #9
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.output_format = 'dynamic'
        options.write = 'output.dynamic'

        test_tool = tools.CLITool()

        output_modules.OutputModulesArgumentsHelper.ParseOptions(
            options, test_tool)

        self.assertEqual(test_tool._output_format, options.output_format)
        self.assertEqual(test_tool._output_filename, options.write)

        # Test with a configuration object missing.
        with self.assertRaises(errors.BadConfigObject):
            output_modules.OutputModulesArgumentsHelper.ParseOptions(
                options, None)

        # Test with output format missing.
        options = cli_test_lib.TestOptions()

        with self.assertRaises(errors.BadConfigOption):
            output_modules.OutputModulesArgumentsHelper.ParseOptions(
                options, test_tool)

        # Test with output file missing.
        options.output_format = 'dynamic'

        with self.assertRaises(errors.BadConfigOption):
            output_modules.OutputModulesArgumentsHelper.ParseOptions(
                options, test_tool)
Exemple #10
0
    def testPrintSeparatorLine(self):
        """Tests the PrintSeparatorLine function."""
        output_writer = test_lib.TestOutputWriter()
        cli_tool = tools.CLITool(output_writer=output_writer)

        cli_tool.PrintSeparatorLine()
        string = output_writer.ReadOutput()
        self.assertEqual(string, self._EXPECTED_SEPARATOR_LINE)
Exemple #11
0
    def testParseLogFileOptions(self):
        """Tests the _ParseLogFileOptions function."""
        test_tool = tools.CLITool()

        options = test_lib.TestOptions()
        options.log_file = 'file.log'

        test_tool._ParseLogFileOptions(options)
Exemple #12
0
    def testParseInformationalOptions(self):
        """Tests the _ParseInformationalOptions function."""
        test_tool = tools.CLITool()

        options = test_lib.TestOptions()
        options.debug = True
        options.quiet = True

        test_tool._ParseInformationalOptions(options)
Exemple #13
0
    def testListTimeZones(self):
        """Tests the ListTimeZones function."""
        output_writer = test_lib.TestBinaryOutputWriter()
        cli_tool = tools.CLITool(output_writer=output_writer)

        cli_tool.ListTimeZones()

        string = output_writer.ReadOutput()
        self.assertTrue(string[:4], self._EXPECTED_TIME_ZONE_OPTIONS)
Exemple #14
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()

    test_tool = tools.CLITool()
    zeromq.ZeroMQArgumentsHelper.ParseOptions(options, test_tool)

    with self.assertRaises(errors.BadConfigObject):
      zeromq.ZeroMQArgumentsHelper.ParseOptions(options, None)
Exemple #15
0
    def testPrintHeader(self):
        """Tests the PrintHeader function."""
        original_stdout = sys.stdout

        cli_tool = tools.CLITool()

        sys.stdout = io.BytesIO()
        cli_tool.PrintHeader(u'Text')
        string = sys.stdout.getvalue()
        expected_string = (b'\n'
                           b'************************************* '
                           b'Text '
                           b'*************************************\n')
        self.assertEqual(string, expected_string)

        sys.stdout = io.BytesIO()
        cli_tool.PrintHeader(u'Another Text', character=u'x')
        string = sys.stdout.getvalue()
        expected_string = (b'\n'
                           b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx '
                           b'Another Text '
                           b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n')
        self.assertEqual(string, expected_string)

        # TODO: determine if this is the desired behavior.
        sys.stdout = io.BytesIO()
        cli_tool.PrintHeader(u'')
        string = sys.stdout.getvalue()
        expected_string = (b'\n'
                           b'*************************************** '
                           b' '
                           b'***************************************\n')
        self.assertEqual(string, expected_string)

        # TODO: determine if this is the desired behavior.
        sys.stdout = io.BytesIO()
        cli_tool.PrintHeader(None)
        string = sys.stdout.getvalue()
        expected_string = (b'\n'
                           b'************************************* '
                           b'None '
                           b'*************************************\n')
        self.assertEqual(string, expected_string)

        # TODO: determine if this is the desired behavior.
        sys.stdout = io.BytesIO()
        expected_string = (
            u'\n '
            u'In computer programming, a string is traditionally a sequence '
            u'of characters, either as a literal constant or as some kind of '
            u'variable. \n')
        cli_tool.PrintHeader(expected_string[2:-2])
        string = sys.stdout.getvalue()
        self.assertEqual(string, expected_string)

        sys.stdout = original_stdout
Exemple #16
0
    def testPrintSeparatorLine(self):
        """Tests the PrintSeparatorLine function."""
        output_writer = test_lib.TestBinaryOutputWriter()
        cli_tool = tools.CLITool(output_writer=output_writer)

        cli_tool.PrintSeparatorLine()
        string = output_writer.ReadOutput()
        expected_string = (b'----------------------------------------'
                           b'----------------------------------------\n')
        self.assertEqual(string, expected_string)
Exemple #17
0
  def testAddTimezoneOption(self):
    """Tests the AddTimezoneOption function."""
    argument_parser = argparse.ArgumentParser(
        prog=u'tool_test.py', description=u'Test argument parser.',
        add_help=False, formatter_class=argparse.RawDescriptionHelpFormatter)

    test_tool = tools.CLITool()
    test_tool.AddTimezoneOption(argument_parser)

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_TIMEZONE_OPTION)
Exemple #18
0
  def testAddInformationalOptions(self):
    """Tests the AddInformationalOptions function."""
    argument_parser = argparse.ArgumentParser(
        prog='tool_test.py', description='Test argument parser.',
        add_help=False, formatter_class=test_lib.SortedArgumentsHelpFormatter)

    test_tool = tools.CLITool()
    test_tool.AddInformationalOptions(argument_parser)

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_INFORMATIONAL_OPTIONS)
Exemple #19
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.parsers = u'winevt'

        test_tool = tools.CLITool()
        parsers.ParsersArgumentsHelper.ParseOptions(options, test_tool)

        self.assertEqual(test_tool._parser_filter_expression, options.parsers)

        with self.assertRaises(errors.BadConfigObject):
            parsers.ParsersArgumentsHelper.ParseOptions(options, None)
Exemple #20
0
    def testAddInformationalOptions(self):
        """Tests the AddInformationalOptions function."""
        argument_parser = argparse.ArgumentParser(
            prog=u'tool_test.py',
            description=u'Test argument parser.',
            add_help=False)

        test_tool = tools.CLITool()
        test_tool.AddInformationalOptions(argument_parser)

        output = argument_parser.format_help()
        self.assertEqual(output, self._EXPECTED_INFORMATIONAL_OPTIONS)
Exemple #21
0
    def testAddDataLocationOption(self):
        """Tests the AddDataLocationOption function."""
        argument_parser = argparse.ArgumentParser(
            prog=u'tool_test.py',
            description=u'Test argument parser.',
            add_help=False)

        test_tool = tools.CLITool()
        test_tool.AddDataLocationOption(argument_parser)

        output = argument_parser.format_help()
        self.assertEqual(output, self._EXPECTED_DATA_OPTION)
Exemple #22
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.yara_rules_path = self._GetTestFilePath(['yara.rules'])

        test_tool = tools.CLITool()
        yara_rules.YaraRulesArgumentsHelper.ParseOptions(options, test_tool)

        self.assertIsNotNone(test_tool._yara_rules_string)

        with self.assertRaises(errors.BadConfigObject):
            yara_rules.YaraRulesArgumentsHelper.ParseOptions(options, None)
Exemple #23
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()
    options.data_location = self._GetTestFilePath(['testdir'])

    test_tool = tools.CLITool()
    data_location.DataLocationArgumentsHelper.ParseOptions(options, test_tool)

    self.assertEqual(test_tool._data_location, options.data_location)

    with self.assertRaises(errors.BadConfigObject):
      data_location.DataLocationArgumentsHelper.ParseOptions(options, None)
Exemple #24
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()
    options.preferred_language = 'is'

    test_tool = tools.CLITool()
    language.LanguageArgumentsHelper.ParseOptions(options, test_tool)

    self.assertEqual(test_tool._preferred_language, options.preferred_language)

    with self.assertRaises(errors.BadConfigObject):
      language.LanguageArgumentsHelper.ParseOptions(options, None)
Exemple #25
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()
    options.status_view_mode = cli_status_view.StatusView.MODE_WINDOW

    test_tool = tools.CLITool()
    status_view.StatusViewArgumentsHelper.ParseOptions(options, test_tool)

    self.assertEqual(test_tool._status_view_mode, options.status_view_mode)

    with self.assertRaises(errors.BadConfigObject):
      status_view.StatusViewArgumentsHelper.ParseOptions(options, None)
Exemple #26
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    test_tool = tools.CLITool()

    options = cli_test_lib.TestOptions()
    options.storage_file = self._GetTestFilePath(['test.plaso'])

    storage_file.StorageFileArgumentsHelper.ParseOptions(options, test_tool)
    self.assertEqual(test_tool._storage_file_path, options.storage_file)

    with self.assertRaises(errors.BadConfigObject):
      storage_file.StorageFileArgumentsHelper.ParseOptions(options, None)
Exemple #27
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.vfs_back_end = 'auto'

        test_tool = tools.CLITool()
        vfs_backend.VFSBackEndArgumentsHelper.ParseOptions(options, test_tool)

        self.assertEqual(test_tool._vfs_back_end, options.vfs_back_end)

        with self.assertRaises(errors.BadConfigObject):
            vfs_backend.VFSBackEndArgumentsHelper.ParseOptions(options, None)
Exemple #28
0
    def testParseOptions(self):
        """Tests the ParseOptions function."""
        options = cli_test_lib.TestOptions()
        options.file_filter = self._GetTestFilePath(['testdir', 'filter2.txt'])

        test_tool = tools.CLITool()
        filter_file.FilterFileArgumentsHelper.ParseOptions(options, test_tool)

        self.assertEqual(test_tool._filter_file, options.file_filter)

        with self.assertRaises(errors.BadConfigObject):
            filter_file.FilterFileArgumentsHelper.ParseOptions(options, None)
Exemple #29
0
  def testPrintHeader(self):
    """Tests the PrintHeader function."""
    output_writer = test_lib.TestOutputWriter()
    cli_tool = tools.CLITool(output_writer=output_writer)

    cli_tool.PrintHeader(u'Text')
    string = output_writer.ReadOutput()
    expected_string = (
        b'\n'
        b'************************************* '
        b'Text '
        b'*************************************\n')
    self.assertEqual(string, expected_string)

    cli_tool.PrintHeader(u'Another Text', character=u'x')
    string = output_writer.ReadOutput()
    expected_string = (
        b'\n'
        b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx '
        b'Another Text '
        b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n')
    self.assertEqual(string, expected_string)

    # TODO: determine if this is the desired behavior.
    cli_tool.PrintHeader(u'')
    string = output_writer.ReadOutput()
    expected_string = (
        b'\n'
        b'*************************************** '
        b' '
        b'***************************************\n')
    self.assertEqual(string, expected_string)

    # TODO: determine if this is the desired behavior.
    cli_tool.PrintHeader(None)
    string = output_writer.ReadOutput()
    expected_string = (
        b'\n'
        b'************************************* '
        b'None '
        b'*************************************\n')
    self.assertEqual(string, expected_string)

    # TODO: determine if this is the desired behavior.
    expected_string = (
        u'\n '
        u'In computer programming, a string is traditionally a sequence '
        u'of characters, either as a literal constant or as some kind of '
        u'variable. \n')
    cli_tool.PrintHeader(expected_string[2:-2])
    string = output_writer.ReadOutput()
    self.assertEqual(string, expected_string)
Exemple #30
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()

    test_tool = tools.CLITool()
    extraction.ExtractionArgumentsHelper.ParseOptions(options, test_tool)

    self.assertIsNone(test_tool._preferred_year)
    self.assertFalse(test_tool._process_archives)
    self.assertTrue(test_tool._process_compressed_streams)

    with self.assertRaises(errors.BadConfigObject):
      extraction.ExtractionArgumentsHelper.ParseOptions(options, None)