Esempio n. 1
0
    def _TestProcessPathSpec(self,
                             storage_writer,
                             path_spec,
                             expected_event_counters,
                             extraction_worker=None,
                             knowledge_base_values=None,
                             process_archives=False):
        """Tests processing a path specification.

    Args:
      storage_writer (StorageWriter): storage writer.
      path_spec (dfvfs.PathSpec): path specification.
      expected_event_counters (dict[str, int|list[int]]): expected event
          counters per event data type.
      extraction_worker (Optional[EventExtractorWorker]): worker to process the
          path specification. If None, a new worker will be created.
      knowledge_base_values (Optional[dict]): knowledge base values.
      process_archives (Optional[bool]): whether archive files should be
          processed.
    """
        knowledge_base_object = knowledge_base.KnowledgeBase()
        if knowledge_base_values:
            for identifier, value in knowledge_base_values.items():
                knowledge_base_object.SetValue(identifier, value)

        resolver_context = context.Context()
        mediator = parsers_mediator.ParserMediator(
            storage_writer,
            knowledge_base_object,
            resolver_context=resolver_context)

        if not extraction_worker:
            configuration = configurations.ExtractionConfiguration()
            configuration.process_archives = process_archives

            extraction_worker = worker.EventExtractionWorker()
            extraction_worker.SetExtractionConfiguration(configuration)

        storage_writer.Open()

        try:
            storage_writer.WriteSessionStart()

            extraction_worker.ProcessPathSpec(mediator, path_spec)
            event_source = storage_writer.GetFirstWrittenEventSource()
            while event_source:
                extraction_worker.ProcessPathSpec(mediator,
                                                  event_source.path_spec)
                event_source = storage_writer.GetNextWrittenEventSource()

            storage_writer.WriteSessionCompletion()

            if expected_event_counters:
                self.CheckEventCounters(storage_writer,
                                        expected_event_counters)

        finally:
            storage_writer.Close()
Esempio n. 2
0
 def testInitialization(self):
     """Tests the __init__ function."""
     configuration = configurations.ExtractionConfiguration()
     self.assertIsNotNone(configuration)