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, 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): # 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 Run(self): self.Check("ListFiles", vfs_plugin.ApiListFilesArgs( client_id=self.client_id.Basename(), file_path="fs/tsk/c/bin")) self.Check("ListFiles", vfs_plugin.ApiListFilesArgs( client_id=self.client_id.Basename(), file_path="fs/tsk/c/bin", timestamp=self.time_2))
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 testHandlerFiltersDirectoriesIfFlagIsSet(self): fixture_test_lib.ClientFixture(self.client_id, token=self.token) # 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, token=self.token) self.assertEqual(len(result.items), 1) self.assertEqual(result.items[0].is_directory, True) self.assertIn(self.file_path, result.items[0].path)
def testHandlerListsFilesAndDirectories(self): fixture_test_lib.ClientFixture(self.client_id, token=self.token) # 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, token=self.token) self.assertEqual(len(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 testRaisesIfFirstComponentIsNotWhitelisted(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="/analysis") with self.assertRaises(ValueError): self.handler.Handle(args, token=self.token)
def testDoesNotRaiseIfPathIsRoot(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="/") self.handler.Handle(args, token=self.token)
def testDoesNotRaiseIfFirstCompomentIsEmpty(self): args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="") self.handler.Handle(args, token=self.token)