def NotifyAboutEnd(self): super(GetFile, self).NotifyAboutEnd() if not self.runner.ShouldSendNotifications(): return stat_entry = self.state.stat_entry if not stat_entry: stat_entry = rdf_client.StatEntry(pathspec=self.args.pathspec) urn = stat_entry.AFF4Path(self.client_id) components = urn.Split() file_ref = None if len(components) > 3: file_ref = rdf_objects.VfsFileReference( client_id=components[0], path_type=components[2].upper(), path_components=components[3:]) if not self.state.get("success"): notification.Notify( self.token.username, rdf_objects.UserNotification.Type.TYPE_VFS_FILE_COLLECTION_FAILED, "File transfer failed.", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=file_ref)) else: notification.Notify( self.token.username, rdf_objects.UserNotification.Type.TYPE_VFS_FILE_COLLECTED, "File transferred successfully.", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=file_ref))
def NotifyAboutEnd(self): if not self.runner.ShouldSendNotifications(): return status_text = "Recursive Directory Listing complete %d nodes, %d dirs" urn = self.state.first_directory if not urn: try: urn = self.args.pathspec.AFF4Path(self.client_id) except ValueError: pass if urn: components = urn.Split() file_ref = None if len(components) > 3: file_ref = rdf_objects.VfsFileReference( client_id=components[0], path_type=components[2].upper(), path_components=components[3:]) notification.Notify( self.token.username, rdf_objects.UserNotification.Type. TYPE_VFS_RECURSIVE_LIST_DIRECTORY_COMPLETED, status_text % (self.state.file_count, self.state.dir_count), rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=file_ref))
def testRegistryPathIsConvertedToURNCorrectly(self): v = rdf_objects.VfsFileReference(client_id=self.client_id, path_type="REGISTRY", path_components=["a", "b", "c"]) self.assertEqual( v.ToURN(), rdfvalue.RDFURN("aff4:/%s/registry/a/b/c" % self.client_id))
def testTempPathIsConvertedToURNCorrectly(self): v = objects.VfsFileReference( client_id=self.client_id, path_type="TEMP", path_components=["a", "b", "c"]) self.assertEqual(v.ToURN(), rdfvalue.RDFURN("aff4:/%s/temp/a/b/c" % self.client_id))
def testVfsNotificationIsParsedCorrectly(self): n = self.InitFromObj_( rdf_objects.UserNotification.Type.TYPE_VFS_FILE_COLLECTED, rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=rdf_objects.VfsFileReference( client_id=self.client_id.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, path_components=["foo", "bar"]))) self.assertEqual(n.reference.type, "VFS") self.assertEqual(n.reference.vfs.client_id, self.client_id) self.assertEqual(n.reference.vfs.vfs_path, "fs/os/foo/bar")
def GenerateNotifications(cls, client_id, token): """Generates fake notifications of different notification types.""" session_id = flow.GRRFlow.StartFlow( client_id=client_id, flow_name=discovery.Interrogate.__name__, token=token) with aff4.FACTORY.Open(session_id, mode="rw", token=token) as flow_obj: notification.Notify( token.username, rdf_objects.UserNotification.Type.TYPE_CLIENT_INTERROGATED, "Fake discovery message", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=client_id.Basename()))) # ViewObject: VirtualFileSystem notification.Notify( token.username, rdf_objects.UserNotification.Type.TYPE_VFS_FILE_COLLECTED, "File fetch completed", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=rdf_objects.VfsFileReference( client_id=client_id.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, path_components=["proc", "10", "exe"]))) gui_test_lib.CreateFileVersion(client_id, "fs/os/proc/10/exe", "", timestamp=gui_test_lib.TIME_0, token=token) # ViewObject: Flow notification.Notify( token.username, rdf_objects.UserNotification.Type.TYPE_FLOW_RUN_COMPLETED, "Fake view flow message", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.FLOW, flow=rdf_objects.FlowReference( client_id=client_id.Basename(), flow_id=flow_obj.urn.Basename()))) # FlowError flow_obj.GetRunner().Error("Fake flow error") return session_id
def _SendNotifications(username, client_id): with test_lib.FakeTime(42): notification.Notify( username, rdf_objects.UserNotification.Type.TYPE_CLIENT_INTERROGATED, "<some message>", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference(client_id=client_id.Basename()))) with test_lib.FakeTime(44): notification.Notify( username, rdf_objects.UserNotification.Type.TYPE_VFS_FILE_COLLECTION_FAILED, "<some other message>", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=rdf_objects.VfsFileReference( client_id=client_id.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, path_components=["foo"])))
def NotifyAboutEnd(self): if not self.runner.ShouldSendNotifications(): return if self.state.urn: components = self.state.urn.Split() file_ref = None if len(components) > 3: file_ref = rdf_objects.VfsFileReference( client_id=components[0], path_type=components[2].upper(), path_components=components[3:]) notification.Notify( self.token.username, notification.UserNotification.Type. TYPE_VFS_LIST_DIRECTORY_COMPLETED, "List of {0} completed.".format( utils.SmartStr(self.args.pathspec)), rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.VFS_FILE, vfs_file=file_ref)) else: super(IteratedListDirectory, self).NotifyAboutEnd()
def testConvertingPathVfsPathStringWithUnknownTypeRaises(self): with self.assertRaises(ValueError): rdf_objects.VfsFileReference().ToPath()
def testTempPathIsConvertedVfsPathStringCorrectly(self): v = rdf_objects.VfsFileReference(client_id=self.client_id, path_type="TEMP", path_components=["a", "b", "c"]) self.assertEqual(v.ToPath(), "temp/a/b/c")
def testRegistryPathIsConvertedVfsPathStringCorrectly(self): v = rdf_objects.VfsFileReference(client_id=self.client_id, path_type="REGISTRY", path_components=["a", "b", "c"]) self.assertEqual(v.ToPath(), "registry/a/b/c")
def testTskPathIsConvertedVfsPathStringCorrectly(self): v = objects.VfsFileReference( client_id=self.client_id, path_type="TSK", path_components=["a", "b", "c"]) self.assertEqual(v.ToPath(), "fs/tsk/a/b/c")
def testConvertingPathToURNWithUnknownTypeRaises(self): with self.assertRaises(ValueError): objects.VfsFileReference().ToURN()