def testQueriesRootPathForEmptyPath(self): args = vfs_plugin.ApiBrowseFilesystemArgs(client_id=self.client_id, path="") results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertEqual(results.items[0].path, "/") self.assertLen(results.items[0].children, 1)
def testHandlerRespectsTimestamp(self): args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir", timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(0)) results = self.handler.Handle(args, context=self.context) self.assertEmpty(results.items[0].children) args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir", timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(1)) results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertLen(results.items[0].children, 3) self.assertEqual(results.items[0].children[0].last_collected_size, len("NTFS")) self.assertEqual(results.items[0].children[0].stat.pathspec.pathtype, rdf_paths.PathSpec.PathType.NTFS) args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir", timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(2)) results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertLen(results.items[0].children, 4) self.assertEqual(results.items[0].children[0].last_collected_size, len("OS")) self.assertEqual(results.items[0].children[0].stat.pathspec.pathtype, rdf_paths.PathSpec.PathType.OS) args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir", timestamp=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(10)) results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertLen(results.items[0].children, 4) self.assertEqual(results.items[0].children[0].last_collected_size, len("OS")) self.assertEqual(results.items[0].children[0].stat.pathspec.pathtype, rdf_paths.PathSpec.PathType.OS)
def testHandlerListsFilesAndDirectories(self): args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir") results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertEqual(results.items[0].path, "/mixeddir") self.assertLen(results.items[0].children, 4) for item in results.items[0].children: self.assertIn("/mixeddir", item.path)
def testHandlerCanListDirectoryTree(self): args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir", include_directory_tree=True) results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 2) self.assertEqual(results.items[0].path, "/") self.assertLen(results.items[0].children, 1) self.assertEqual("mixeddir", results.items[0].children[0].name) self.assertEqual(results.items[1].path, "/mixeddir") self.assertLen(results.items[1].children, 4) self.assertEqual(["ntfs-then-os", "os-only", "os-then-ntfs", "tsk-only"], [f.name for f in results.items[1].children])
def testHandlerMergesFilesOfDifferentPathSpecs(self): args = vfs_plugin.ApiBrowseFilesystemArgs( client_id=self.client_id, path="/mixeddir") results = self.handler.Handle(args, context=self.context) self.assertLen(results.items, 1) self.assertEqual(results.items[0].path, "/mixeddir") self.assertLen(results.items[0].children, 4) children = [(f.name, f.stat.pathspec.pathtype, f.last_collected_size) for f in results.items[0].children] self.assertEqual(children, [ ("ntfs-then-os", rdf_paths.PathSpec.PathType.OS, len("OS")), ("os-only", rdf_paths.PathSpec.PathType.OS, len("OS")), ("os-then-ntfs", rdf_paths.PathSpec.PathType.NTFS, len("NTFS")), ("tsk-only", rdf_paths.PathSpec.PathType.TSK, len("TSK")), ])
def testVfsMethodsAreAccessChecked(self): args = api_vfs.ApiListFilesArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.ListFiles, "CheckClientAccess", args=args) args = api_vfs.ApiBrowseFilesystemArgs(client_id=self.client_id) self.CheckMethodIsAccessChecked(self.router.BrowseFilesystem, "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)