def testHandlerRespectsTimestamp(self): # TODO(hanuszczak): Enable this test in relational database mode once # timestamp-specific file listing is supported by the data store. if data_store.RelationalDBReadEnabled(): raise unittest.SkipTest( "relational backend does not support timestamp-" "specific file listing") # file_path is "fs/os/etc", a directory. self.CreateFileVersions(self.client_id, self.file_path + "/file") args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path=self.file_path, timestamp=self.time_2) result = self.handler.Handle(args, token=self.token) self.assertEqual(len(result.items), 1) self.assertEqual(result.items[0].last_collected_size, 13) args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path=self.file_path, timestamp=self.time_1) result = self.handler.Handle(args, token=self.token) self.assertEqual(len(result.items), 1) self.assertEqual(result.items[0].last_collected_size, 11) args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path=self.file_path, timestamp=self.time_0) result = self.handler.Handle(args, token=self.token) self.assertEqual(len(result.items), 0)
def testHandlerRespectsTimestamp(self): # file_path is "fs/os/etc", a directory. self.CreateFileVersions(self.client_id, self.file_path + "/file") args = vfs_plugin.ApiListFilesArgs( client_id=self.client_id, file_path=self.file_path, timestamp=self.time_2) result = self.handler.Handle(args, context=self.context) self.assertLen(result.items, 1) self.assertIsInstance(result.items[0].last_collected_size, int) self.assertEqual(result.items[0].last_collected_size, 13) args = vfs_plugin.ApiListFilesArgs( client_id=self.client_id, file_path=self.file_path, timestamp=self.time_1) result = self.handler.Handle(args, context=self.context) self.assertLen(result.items, 1) self.assertEqual(result.items[0].last_collected_size, 11) args = vfs_plugin.ApiListFilesArgs( client_id=self.client_id, file_path=self.file_path, timestamp=self.time_0) result = self.handler.Handle(args, context=self.context) self.assertEmpty(result.items)
def Run(self): client_id = self.SetupClient(0).Basename() fixture_test_lib.ClientFixture(client_id, token=self.token, age=42) self.Check( "ListFiles", vfs_plugin.ApiListFilesArgs(client_id=client_id, file_path="fs/tsk/c/bin")) self.Check( "ListFiles", vfs_plugin.ApiListFilesArgs(client_id=client_id, file_path="fs/tsk/c/bin", timestamp=self.time_2))
def Run(self): client_id = self.SetupClient(0) with test_lib.FakeTime(42): fixture_test_lib.ClientFixture(client_id) self.Check( "ListFiles", vfs_plugin.ApiListFilesArgs(client_id=client_id, file_path="fs/tsk/c/bin")) self.Check( "ListFiles", vfs_plugin.ApiListFilesArgs(client_id=client_id, file_path="fs/tsk/c/bin", timestamp=self.time_2))
def testRoot(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="/") result = self.handler.Handle(args, context=self.context) self.assertSameElements([(item.name, item.path) for item in result.items], [("fs", "fs"), ("temp", "temp")])
def testVfsMethodsAreAccessChecked(self): args = api_vfs.ApiListFilesArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.ListFiles, "CheckClientAccess", args=args) args = api_vfs.ApiGetVfsFilesArchiveArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetVfsFilesArchive, "CheckClientAccess", args=args) args = api_vfs.ApiGetFileDetailsArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetFileDetails, "CheckClientAccess", args=args) args = api_vfs.ApiGetFileTextArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetFileText, "CheckClientAccess", args=args) args = api_vfs.ApiGetFileBlobArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetFileBlob, "CheckClientAccess", args=args) args = api_vfs.ApiGetFileVersionTimesArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetFileVersionTimes, "CheckClientAccess", args=args) args = api_vfs.ApiGetFileDownloadCommandArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetFileDownloadCommand, "CheckClientAccess", args=args) args = api_vfs.ApiCreateVfsRefreshOperationArgs( client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.CreateVfsRefreshOperation, "CheckClientAccess", args=args) args = api_vfs.ApiGetVfsTimelineArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetVfsTimeline, "CheckClientAccess", args=args) args = api_vfs.ApiGetVfsTimelineAsCsvArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.GetVfsTimelineAsCsv, "CheckClientAccess", args=args) args = api_vfs.ApiUpdateVfsFileContentArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.UpdateVfsFileContent, "CheckClientAccess", args=args)
def testHandlerListsFilesAndDirectories(self): fixture_test_lib.ClientFixture(self.client_id) # Fetch all children of a directory. args = vfs_plugin.ApiListFilesArgs( client_id=self.client_id, file_path=self.file_path) result = self.handler.Handle(args, context=self.context) self.assertLen(result.items, 4) for item in result.items: # Check that all files are really in the right directory. self.assertIn(self.file_path, item.path)
def testHandlerFiltersDirectoriesIfFlagIsSet(self): fixture_test_lib.ClientFixture(self.client_id) # Only fetch sub-directories. args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path=self.file_path, directories_only=True) result = self.handler.Handle(args, context=self.context) self.assertLen(result.items, 1) self.assertEqual(result.items[0].is_directory, True) self.assertIn(self.file_path, result.items[0].path)
def testRaisesIfFirstComponentIsNotAllowlisted(self): args = vfs_plugin.ApiListFilesArgs( client_id=self.client_id, file_path="/analysis") with self.assertRaises(ValueError): self.handler.Handle(args, context=self.context)
def testDoesNotRaiseIfPathIsRoot(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="/") self.handler.Handle(args, context=self.context)
def testDoesNotRaiseIfFirstComponentIsEmpty(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="") self.handler.Handle(args, context=self.context)