def testMergeAttributeContainersWithDeserializationError(self): """Tests MergeAttributeContainers with a deserialization error.""" session = sessions.Session() with shared_test_lib.TempDirectory() as temp_directory: task_storage_path = os.path.join(temp_directory, 'task.sqlite') self._CreateTaskStorageFile( task_storage_path, self._TEST_EVENTS_WITH_DESERIALIZATION_ERROR) session_storage_path = os.path.join(temp_directory, 'plaso.sqlite') storage_writer = sqlite_writer.SQLiteStorageFileWriter( session_storage_path) task_storage_reader = sqlite_reader.SQLiteStorageFileReader( task_storage_path) test_reader = merge_reader.StorageMergeReader( session, storage_writer, task_storage_reader) storage_writer.Open(path=task_storage_path) result = test_reader.MergeAttributeContainers() self.assertTrue(result) storage_writer.Close()
def CreateStorageReaderForFile(cls, path): """Creates a storage reader based on the file. Args: path (str): path to the storage file. Returns: StorageReader: a storage reader or None if the storage file cannot be opened or the storage format is not supported. """ if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path): return sqlite_reader.SQLiteStorageFileReader(path)
def testBuild(self): """Tests the _Build function.""" test_index = event_tag_index.EventTagIndex() self.assertIsNone(test_index._index) test_file_path = self._GetTestFilePath(['psort_test.plaso']) self._SkipIfPathNotExists(test_file_path) storage_reader = sqlite_file_reader.SQLiteStorageFileReader( test_file_path) test_index._Build(storage_reader) storage_reader.Close() self.assertIsNotNone(test_index._index)
def CreateTaskStorageReader(cls, storage_format, task, path): """Creates a task storage reader. Args: storage_format (str): storage format. task (Task): task the storage changes are part of. path (str): path to the storage file. Returns: StorageReader: a storage reader or None if the storage file cannot be opened or the storage format is not supported. """ if storage_format == definitions.STORAGE_FORMAT_SQLITE: return sqlite_reader.SQLiteStorageFileReader(path) if storage_format == definitions.STORAGE_FORMAT_REDIS: return redis_reader.RedisStorageReader(task.session_identifier, task.identifier) return None
def testGetEventTagByIdentifier(self): """Tests the GetEventTagByIdentifier function.""" test_index = event_tag_index.EventTagIndex() with shared_test_lib.TempDirectory() as temp_directory: temp_file = os.path.join(temp_directory, 'storage.plaso') self._CreateTestStorageFileWithTags(temp_file) storage_reader = sqlite_file_reader.SQLiteStorageFileReader( temp_file) event_identifier = identifiers.SQLTableIdentifier('event', 1) event_tag = test_index.GetEventTagByIdentifier( storage_reader, event_identifier) self.assertIsNotNone(event_tag) event_identifier = identifiers.SQLTableIdentifier('event', 99) event_tag = test_index.GetEventTagByIdentifier( storage_reader, event_identifier) self.assertIsNone(event_tag) storage_reader.Close()
def testMergeAttributeContainers(self): """Tests the MergeAttributeContainers function.""" with shared_test_lib.TempDirectory() as temp_directory: task_storage_path = os.path.join(temp_directory, 'task.sqlite') self._CreateTaskStorageFile(task_storage_path, self._TEST_EVENTS) session_storage_path = os.path.join(temp_directory, 'plaso.sqlite') storage_writer = sqlite_writer.SQLiteStorageFileWriter( session_storage_path) task_storage_reader = sqlite_reader.SQLiteStorageFileReader( task_storage_path) test_reader = merge_reader.StorageMergeReader( storage_writer, task_storage_reader, 'test_task') storage_writer.Open(path=task_storage_path) result = test_reader.MergeAttributeContainers() self.assertTrue(result) storage_writer.Close()