Beispiel #1
0
    def testReadAndWriteSerializedEventSource(self):
        """Test ReadSerialized and WriteSerialized of EventSource."""
        test_path_spec = fake_path_spec.FakePathSpec(location='/opt/plaso.txt')

        expected_event_source = event_sources.EventSource(
            path_spec=test_path_spec)

        json_string = (json_serializer.JSONAttributeContainerSerializer.
                       WriteSerialized(expected_event_source))

        self.assertIsNotNone(json_string)

        event_source = (json_serializer.JSONAttributeContainerSerializer.
                        ReadSerialized(json_string))

        self.assertIsNotNone(event_source)
        self.assertIsInstance(event_source, event_sources.EventSource)

        expected_event_source_dict = {
            'path_spec': test_path_spec.comparable,
        }

        event_source_dict = event_source.CopyToDict()
        path_spec = event_source_dict.get('path_spec', None)
        if path_spec:
            event_source_dict['path_spec'] = path_spec.comparable

        self.assertEqual(sorted(event_source_dict.items()),
                         sorted(expected_event_source_dict.items()))
Beispiel #2
0
  def testGetAttributeNames(self):
    """Tests the GetAttributeNames function."""
    attribute_container = event_sources.EventSource()

    expected_attribute_names = [
        'data_type', 'file_entry_type', 'path_spec']

    attribute_names = sorted(attribute_container.GetAttributeNames())

    self.assertEqual(attribute_names, expected_attribute_names)
Beispiel #3
0
  def testAddEventSource(self):
    """Tests the AddEventSource function."""
    event_source = event_sources.EventSource()

    with shared_test_lib.TempDirectory() as temp_directory:
      temp_file = os.path.join(temp_directory, u'storage.plaso')
      storage_file = gzip_file.GZIPStorageFile()
      storage_file.Open(path=temp_file, read_only=False)

      storage_file.AddEventSource(event_source)

      storage_file.Close()
Beispiel #4
0
  def testAddEventSource(self):
    """Tests the AddEventSource function."""
    session = sessions.Session()
    event_source = event_sources.EventSource()

    storage_writer = fake_storage.FakeStorageWriter(session)
    storage_writer.Open()

    storage_writer.AddEventSource(event_source)

    storage_writer.Close()

    with self.assertRaises(IOError):
      storage_writer.AddEventSource(event_source)
Beispiel #5
0
  def testHasAttributeContainers(self):
    """Tests the HasAttributeContainers function."""
    test_reader = reader.StorageReader()
    test_reader._store = fake_store.FakeStore()
    test_reader._store.Open()

    try:
      event_source = event_sources.EventSource()
      test_reader._store.AddAttributeContainer(event_source)

      result = test_reader.HasAttributeContainers(event_source.CONTAINER_TYPE)
      self.assertTrue(result)

    finally:
      test_reader._store.Close()
Beispiel #6
0
    def testGetNumberOfAttributeContainers(self):
        """Tests the GetNumberOfAttributeContainers function."""
        test_reader = reader.StorageReader()
        test_reader._store = fake_store.FakeStore()
        test_reader._store.Open()

        try:
            event_source = event_sources.EventSource()
            test_reader._store.AddAttributeContainer(event_source)

            number_of_containers = test_reader.GetNumberOfAttributeContainers(
                event_source.CONTAINER_TYPE)
            self.assertEqual(number_of_containers, 1)

        finally:
            test_reader._store.Close()
Beispiel #7
0
    def testGetAttributeContainers(self):
        """Tests the GetAttributeContainers function."""
        test_reader = reader.StorageReader()
        test_reader._store = fake_store.FakeStore()
        test_reader._store.Open()

        try:
            event_source = event_sources.EventSource()
            test_reader._store.AddAttributeContainer(event_source)

            test_generator = test_reader.GetAttributeContainers(
                event_source.CONTAINER_TYPE)
            test_containers = list(test_generator)
            self.assertEqual(len(test_containers), 1)

        finally:
            test_reader._store.Close()
Beispiel #8
0
  def testGetEventSources(self):
    """Tests the GetEventSources function."""
    event_source = event_sources.EventSource()

    with shared_test_lib.TempDirectory() as temp_directory:
      temp_file = os.path.join(temp_directory, u'storage.plaso')
      storage_file = gzip_file.GZIPStorageFile()
      storage_file.Open(path=temp_file, read_only=False)

      storage_file.AddEventSource(event_source)

      storage_file.Close()

      storage_file = gzip_file.GZIPStorageFile()
      storage_file.Open(path=temp_file)

      test_event_sources = list(storage_file.GetEventSources())
      self.assertEqual(len(test_event_sources), 1)

      storage_file.Close()
Beispiel #9
0
    def testGetAttributeContainerByIndex(self):
        """Tests the GetAttributeContainerByIndex function."""
        test_reader = reader.StorageReader()
        test_reader._store = fake_store.FakeStore()
        test_reader._store.Open()

        try:
            event_source = event_sources.EventSource()
            test_reader._store.AddAttributeContainer(event_source)

            test_container = test_reader.GetAttributeContainerByIndex(
                event_source.CONTAINER_TYPE, 0)
            self.assertIsNotNone(test_container)

            test_container = test_reader.GetAttributeContainerByIndex(
                event_source.CONTAINER_TYPE, 99)
            self.assertIsNone(test_container)

        finally:
            test_reader._store.Close()