def testTimelineIsReturnedInChunks(self): # Change chunk size to see if the handler behaves correctly. self.handler.CHUNK_SIZE = 1 args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path=self.folder_path) result = self.handler.Handle(args, token=self.token) # Check rows returned correctly. self.assertTrue(hasattr(result, "GenerateContent")) for i in reversed(range(0, 5)): with test_lib.FakeTime(i): next_chunk = next(result.GenerateContent()).strip() timestamp = rdfvalue.RDFDatetime.Now() if i == 4: # The first row includes the column headings. self.assertEqual( next_chunk, "Timestamp,Datetime,Message,Timestamp_desc\r\n" "%d,%s,%s,MODIFICATION" % (timestamp.AsMicroSecondsFromEpoch(), str(timestamp), self.file_path)) else: self.assertEqual( next_chunk, "%d,%s,%s,MODIFICATION" % (timestamp.AsMicroSecondsFromEpoch(), str(timestamp), self.file_path))
def testEmptyTimelineIsReturnedOnNonexistantPath(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="fs/non-existant/file/path") result = self.handler.Handle(args, token=self.token) self.assertTrue(hasattr(result, "GenerateContent")) with self.assertRaises(StopIteration): next(result.GenerateContent())
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 testClickingOnDownloadTimelineButtonInitiatesDownload(self, mock_method): # Open VFS view for client 1 on a specific location. self.Open("/#c=C.0000000000000001&main=VirtualFileSystemView" "&t=_fs-os-c-proc") self.Click("css=button[name=downloadTimeline]:not([disabled])") self.WaitUntilEqual(1, lambda: mock_method.call_count) mock_method.assert_called_once_with( api_vfs.ApiGetVfsTimelineAsCsvArgs( client_id="C.0000000000000001", file_path="fs/os/c/proc"), token=mock.ANY)
def testRaisesIfFirstComponentNotInWhitelist(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="/analysis") with self.assertRaises(ValueError): self.handler.Handle(args, token=self.token)
def testRaisesOnRootPath(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="/") with self.assertRaises(ValueError): self.handler.Handle(args, token=self.token)