def setUp(self): super(ApiDeletePendingUserNotificationHandlerTest, self).setUp() self.handler = user_plugin.ApiDeletePendingUserNotificationHandler() self.client_id = self.SetupClient(0) with test_lib.FakeTime(self.TIME_0): notification.Notify( self.token.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=self.client_id.Basename()))) notification.Notify( self.token.username, rdf_objects.UserNotification.Type.TYPE_CLIENT_INTERROGATED, "<some message with identical time>", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=self.client_id.Basename()))) with test_lib.FakeTime(self.TIME_1): notification.Notify( self.token.username, rdf_objects.UserNotification.Type.TYPE_CLIENT_APPROVAL_GRANTED, "<some other message>", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=self.client_id.Basename())))
def NotifyAboutEnd(self): notification.Notify( self.token.username, rdf_objects.UserNotification.Type.TYPE_CLIENT_INTERROGATED, "", rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=self.client_id.Basename())))
def testClientApprovalGrantedNotificationIsParsedCorrectly(self): n = self.InitFromObj_( rdf_objects.UserNotification.Type.TYPE_CLIENT_APPROVAL_GRANTED, rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=self.client_id.Basename()))) self.assertEqual(n.reference.type, "CLIENT") self.assertEqual(n.reference.client.client_id, self.client_id)
def testDiscoveryNotificationIsParsedCorrectly(self): n = self.InitFromObj_( rdf_objects.UserNotification.Type.TYPE_CLIENT_INTERROGATED, rdf_objects.ObjectReference( reference_type=rdf_objects.ObjectReference.Type.CLIENT, client=rdf_objects.ClientReference( client_id=self.client_id.Basename()))) self.assertEqual(n.reference.type, "CLIENT") self.assertEqual(n.reference.client.client_id, self.client_id)
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 ObjectReference(self): return objects.ObjectReference( reference_type=objects.ObjectReference.Type.CLIENT, client=objects.ClientReference( client_id=utils.SmartStr(self.client_id)))