예제 #1
0
  def testListOutputModules(self):
    """Tests the ListOutputModules function."""
    output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
    test_tool = psort.PsortTool(output_writer=output_writer)

    test_tool.ListOutputModules()

    output = output_writer.ReadOutput()

    number_of_tables = 0
    lines = []
    for line in output.split(b'\n'):
      line = line.strip()
      lines.append(line)

      if line.startswith(b'*****') and line.endswith(b'*****'):
        number_of_tables += 1

    self.assertIn(u'Output Modules', lines[1])

    # pylint: disable=protected-access
    lines = frozenset(lines)
    disabled_outputs = list(test_tool._front_end.GetDisabledOutputClasses())
    enabled_outputs = list(test_tool._front_end.GetOutputClasses())

    expected_number_of_tables = 0
    if disabled_outputs:
      expected_number_of_tables += 1
    if enabled_outputs:
      expected_number_of_tables += 1

    self.assertEqual(number_of_tables, expected_number_of_tables)
    expected_line = b'rawpy : "raw" (or native) Python output.'
    self.assertIn(expected_line, lines)
예제 #2
0
  def testParseArguments(self):
    """Tests the ParseArguments function."""
    output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
    test_tool = psort.PsortTool(output_writer=output_writer)

    result = test_tool.ParseArguments()
    self.assertFalse(result)
예제 #3
0
  def testListAnalysisPlugins(self):
    """Tests the ListAnalysisPlugins function."""
    output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
    test_tool = psort.PsortTool(output_writer=output_writer)

    test_tool.ListAnalysisPlugins()

    output = output_writer.ReadOutput()

    number_of_tables = 0
    lines = []
    for line in output.split(b'\n'):
      line = line.strip()
      lines.append(line)

      if line.startswith(b'*****') and line.endswith(b'*****'):
        number_of_tables += 1

    self.assertIn(u'Analysis Plugins', lines[1])

    lines = frozenset(lines)

    self.assertEqual(number_of_tables, 1)

    expected_line = (
        b'browser_search : Analyze browser search entries from events.')
    self.assertIn(expected_line, lines)
예제 #4
0
  def testListLanguageIdentifiers(self):
    """Tests the ListLanguageIdentifiers function."""
    output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
    test_tool = psort.PsortTool(output_writer=output_writer)

    test_tool.ListLanguageIdentifiers()

    output = output_writer.ReadOutput()

    number_of_tables = 0
    lines = []
    for line in output.split(b'\n'):
      line = line.strip()
      lines.append(line)

      if line.startswith(b'*****') and line.endswith(b'*****'):
        number_of_tables += 1

    self.assertIn(u'Language identifiers', lines[1])

    lines = frozenset(lines)

    self.assertEqual(number_of_tables, 1)

    expected_line = b'en : English'
    self.assertIn(expected_line, lines)
예제 #5
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._input_reader = TestInputReader()
        self._output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')

        self._test_tool = psort.PsortTool(input_reader=self._input_reader,
                                          output_writer=self._output_writer)
예제 #6
0
  def testAddProcessingOptions(self):
    """Tests the AddProcessingOptions function."""
    argument_parser = argparse.ArgumentParser(
        prog=u'psort_test.py',
        description=u'Test argument parser.', add_help=False,
        formatter_class=cli_test_lib.SortedArgumentsHelpFormatter)

    test_tool = psort.PsortTool()
    test_tool.AddProcessingOptions(argument_parser)

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_PROCESSING_OPTIONS)
예제 #7
0
  def testAddOutputModuleOptions(self):
    """Tests the AddOutputModuleOptions function."""
    argument_parser = argparse.ArgumentParser(
        prog=u'psort_test.py',
        description=u'Test argument parser.', add_help=False,
        formatter_class=cli_test_lib.SortedArgumentsHelpFormatter)

    test_tool = psort.PsortTool()
    test_tool.AddOutputModuleOptions(argument_parser, [u'dynamic'])

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_OUTPUT_MODULE_OPTIONS)
예제 #8
0
  def testAddAnalysisPluginOptions(self):
    """Tests the AddAnalysisPluginOptions function."""
    argument_parser = argparse.ArgumentParser(
        prog=u'psort_test.py',
        description=u'Test argument parser.', add_help=False,
        formatter_class=cli_test_lib.SortedArgumentsHelpFormatter)

    test_tool = psort.PsortTool()
    test_tool.AddAnalysisPluginOptions(argument_parser, [])

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_ANALYSIS_PLUGIN_OPTIONS)
예제 #9
0
    def testProcessStorageWithMissingParameters(self):
        """Test the ProcessStorage function with half-configured output module."""
        input_reader = TestInputReader()
        output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
        test_tool = psort.PsortTool(input_reader=input_reader,
                                    output_writer=output_writer)

        options = cli_test_lib.TestOptions()
        options.storage_file = self._GetTestFilePath(
            [u'psort_test.json.plaso'])
        options.output_format = u'test_missing'

        output_manager.OutputManager.RegisterOutput(
            TestOutputModuleMissingParameters)
        helpers_manager.ArgumentHelperManager.RegisterHelper(
            TestOutputModuleArgumentHelper)

        lines = []
        with shared_test_lib.TempDirectory() as temp_directory:
            temp_file_name = os.path.join(temp_directory, u'output.txt')
            options.write = temp_file_name

            test_tool.ParseOptions(options)
            test_tool.ProcessStorage()

            with open(temp_file_name, 'rb') as file_object:
                for line in file_object.readlines():
                    lines.append(line.strip())

        self.assertTrue(input_reader.read_called)
        self.assertEqual(TestOutputModuleMissingParameters.missing, u'foobar')
        self.assertEqual(TestOutputModuleMissingParameters.parameters,
                         u'foobar')

        expected_line = u'FILE/OS ctime OS:/tmp/test/test_data/syslog Type: file'
        self.assertIn(expected_line, lines)

        output_manager.OutputManager.DeregisterOutput(
            TestOutputModuleMissingParameters)
        helpers_manager.ArgumentHelperManager.DeregisterHelper(
            TestOutputModuleArgumentHelper)
예제 #10
0
  def testParseOptions(self):
    """Tests the ParseOptions function."""
    output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
    test_tool = psort.PsortTool(output_writer=output_writer)

    options = cli_test_lib.TestOptions()
    options.output_format = u'null'
    options.storage_file = self._GetTestFilePath([u'psort_test.json.plaso'])

    test_tool.ParseOptions(options)

    options = cli_test_lib.TestOptions()

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

    options = cli_test_lib.TestOptions()
    options.storage_file = self._GetTestFilePath([u'psort_test.json.plaso'])

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