grr/server/grr_response_server/flows/general/administrative_test.py
def testAlertEmailIsSentWhenClientKilledDuringHunt(self):
    """Test that client killed messages are handled correctly for hunts."""
    client_id = self.SetupClient(0)
    self.email_messages = []

    def SendEmail(address, sender, title, message, **_):
      self.email_messages.append(
          dict(address=address, sender=sender, title=title, message=message))

    with hunts_implementation.StartHunt(
        hunt_name=hunts_standard.GenericHunt.__name__,
        flow_runner_args=rdf_flow_runner.FlowRunnerArgs(
            flow_name=flow_test_lib.FlowWithOneClientRequest.__name__),
        client_rate=0,
        crash_alert_email="crashes@example.com",
        token=self.token) as hunt:
      hunt.Run()
      hunt.StartClients(hunt.session_id, [client_id])

    with utils.Stubber(email_alerts.EMAIL_ALERTER, "SendEmail", SendEmail):
      client = flow_test_lib.CrashClientMock(client_id, self.token)
      hunt_test_lib.TestHuntHelper(
          client, [client_id], token=self.token, check_flow_errors=False)

    self.assertLen(self.email_messages, 2)
    self.assertListEqual(
        [self.email_messages[0]["address"], self.email_messages[1]["address"]],
        ["crashes@example.com", config.CONFIG["Monitoring.alert_email"]])
Test that client killed messages are handled correctly for hunts.
Test that client killed messages are handled correctly for hunts.
Test that client killed messages are handled correctly for hunts .
def testAlertEmailIsSentWhenClientKilledDuringHunt(self):
    client_id = self.SetupClient(0)
    self.email_messages = []
    def SendEmail(address, sender, title, message, **_):
      self.email_messages.append(
          dict(address=address, sender=sender, title=title, message=message))
    with hunts_implementation.StartHunt(
        hunt_name=hunts_standard.GenericHunt.__name__,
        flow_runner_args=rdf_flow_runner.FlowRunnerArgs(
            flow_name=flow_test_lib.FlowWithOneClientRequest.__name__),
        client_rate=0,
        crash_alert_email="crashes@example.com",
        token=self.token) as hunt:
      hunt.Run()
      hunt.StartClients(hunt.session_id, [client_id])
    with utils.Stubber(email_alerts.EMAIL_ALERTER, "SendEmail", SendEmail):
      client = flow_test_lib.CrashClientMock(client_id, self.token)
      hunt_test_lib.TestHuntHelper(
          client, [client_id], token=self.token, check_flow_errors=False)
    self.assertLen(self.email_messages, 2)
    self.assertListEqual(
        [self.email_messages[0]["address"], self.email_messages[1]["address"]],
        ["crashes@example.com", config.CONFIG["Monitoring.alert_email"]])
def testAlertEmailIsSentWhenClientKilledDuringHunt ( self ) : client_id = self . SetupClient ( 0 ) self . email_messages = [ ] def SendEmail ( address , sender , title , message , ** _ ) : self . email_messages . append ( dict ( address = address , sender = sender , title = title , message = message ) ) with hunts_implementation . StartHunt ( hunt_name = hunts_standard . GenericHunt . __name__ , flow_runner_args = rdf_flow_runner . FlowRunnerArgs ( flow_name = flow_test_lib . FlowWithOneClientRequest . __name__ ) , client_rate = 0 , crash_alert_email = "crashes@example.com" , token = self . token ) as hunt : hunt . Run ( ) hunt . StartClients ( hunt . session_id , [ client_id ] ) with utils . Stubber ( email_alerts . EMAIL_ALERTER , "SendEmail" , SendEmail ) : client = flow_test_lib . CrashClientMock ( client_id , self . token ) hunt_test_lib . TestHuntHelper ( client , [ client_id ] , token = self . token , check_flow_errors = False ) self . assertLen ( self . email_messages , 2 ) self . assertListEqual ( [ self . email_messages [ 0 ] [ "address" ] , self . email_messages [ 1 ] [ "address" ] ] , [ "crashes@example.com" , config . CONFIG [ "Monitoring.alert_email" ] ] )
Test that client killed messages are handled correctly for hunts.
Test that client killed messages are handled correctly for hunts .
"""Test that client killed messages are handled correctly for hunts."""
self