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.AsMicrosecondsSinceEpoch(), str(timestamp), self.file_path)) else: self.assertEqual( next_chunk, "%d,%s,%s,MODIFICATION" % (timestamp.AsMicrosecondsSinceEpoch(), str(timestamp), self.file_path))
def testEmptyTimelineIsReturnedOnNonexistantPath(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="fs/os/non-existent/file/path") result = self.handler.Handle(args, context=self.context) 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 testTimelineInBodyFormatCorrectlyReturned(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path=self.folder_path, format=vfs_plugin.ApiGetVfsTimelineAsCsvArgs.Format.BODY) result = self.handler.Handle(args, context=self.context) content = b"".join(result.GenerateContent()) expected_csv = u"|%s|0|----------|0|0|0|0|4|0|0\n" % self.file_path self.assertEqual(content, expected_csv.encode("utf-8"))
def testTimelineInBodyFormatCorrectlyReturned(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path=self.folder_path, format=vfs_plugin.ApiGetVfsTimelineAsCsvArgs.Format.BODY) result = self.handler.Handle(args, token=self.token) content = "".join(result.GenerateContent()) self.assertEqual(content, "|%s|0|----------|0|0|0|0|4|0|0\r\n" % self.file_path)
def testTimelineEntriesWithHashOnlyAreIgnoredOnBodyExport(self): client_id = self.SetupClient(1) hash_entry = rdf_crypto.Hash(sha256=b"quux") self.SetupFileMetadata( client_id, u"fs/os/foo/bar", stat_entry=None, hash_entry=hash_entry) args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=client_id, file_path=u"fs/os/foo", format=vfs_plugin.ApiGetVfsTimelineAsCsvArgs.Format.BODY) result = self.handler.Handle(args, context=self.context) content = b"".join(result.GenerateContent()) self.assertEqual(content, b"")
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=timelineDropdown]:not([disabled])") self.Click("css=a[name=downloadTimeline]") self.WaitUntil(lambda: mock_method.call_count) # Mock method will be called twice: once for HEAD request (to check # permissions) and once for GET request. mock_method.assert_called_with(api_vfs.ApiGetVfsTimelineAsCsvArgs( client_id="C.0000000000000001", file_path="fs/os/c/proc"), token=mock.ANY)
def testTimelineInBodyFormatWithHashCorrectlyReturned(self): client_id = self.SetupClient(1) stat_entry = rdf_client_fs.StatEntry(st_size=1337) stat_entry.pathspec.path = u"foo/bar" stat_entry.pathspec.pathtype = rdf_paths.PathSpec.PathType.OS hash_entry = rdf_crypto.Hash(md5=b"quux", sha256=b"norf") self.SetupFileMetadata(client_id, u"fs/os/foo/bar", stat_entry=stat_entry, hash_entry=hash_entry) args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=client_id, file_path=u"fs/os/foo", format=vfs_plugin.ApiGetVfsTimelineAsCsvArgs.Format.BODY) result = self.handler.Handle(args, context=self.context) content = b"".join(result.GenerateContent()) expected_csv = u"71757578|fs/os/foo/bar|0|----------|0|0|1337|0|0|0|0\n" self.assertEqual(content, expected_csv.encode("utf-8"))
def testRaisesIfFirstComponentNotInAllowlist(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="/analysis") with self.assertRaises(ValueError): self.handler.Handle(args, context=self.context)
def testRaisesOnRootPath(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="/") with self.assertRaises(ValueError): self.handler.Handle(args, context=self.context)
def testRaisesOnEmptyPath(self): args = vfs_plugin.ApiGetVfsTimelineAsCsvArgs( client_id=self.client_id, file_path="") with self.assertRaises(ValueError): self.handler.Handle(args, token=self.token)