Beispiel #1
0
 def testGetPriority(self, header_value, expected_priority):
     """Tests _GetPriority."""
     self.test_msg.replace_header(AlertEmailHeader.PRIORITY, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertCaseInsensitiveEqual(props['priority'], expected_priority)
Beispiel #2
0
 def testDefaultStatus(self, header_value, expected_status):
     """Checks if _GetStatus return Available in default."""
     self.test_msg.replace_header(AlertEmailHeader.STATUS, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertCaseInsensitiveEqual(props['status'], expected_status)
Beispiel #3
0
 def testDefaultCCIDs(self, header_value, expected_cc_ids):
     """Checks if _GetCCIDs returns an empty list in default."""
     self.test_msg.replace_header(AlertEmailHeader.CC, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertEqual(props['cc_ids'], expected_cc_ids)
Beispiel #4
0
 def testDefaultOwnerID(self, header_value, expected_owner_id):
     """Checks if _GetOwnerID returns None in default."""
     self.test_msg.replace_header(AlertEmailHeader.OWNER, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertEqual(props['owner_id'], expected_owner_id)
Beispiel #5
0
 def testGetIssueType(self, header_value, expected_issue_type):
     """Tests _GetIssueType."""
     self.test_msg.replace_header(AlertEmailHeader.TYPE, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertCaseInsensitiveEqual(props['issue_type'],
                                     expected_issue_type)
Beispiel #6
0
 def testGetOSes(self, header_value, expected_oses):
     """Tests _GetOSes."""
     self.test_msg.replace_header(AlertEmailHeader.OS, header_value)
     props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                            self.project_id,
                                            self.incident_id,
                                            self.trooper_queue,
                                            self.test_msg)
     self.assertEqual(
         sorted(os if os is None else os.lower() for os in props['oses']),
         sorted(os if os is None else os.lower() for os in expected_oses))
Beispiel #7
0
    def testGetStatusWithoutOwner(self, status, means_open, expected_status):
        """Tests GetStatus without an owner."""
        self.test_msg.replace_header(AlertEmailHeader.STATUS, status)
        self.mox.StubOutWithMock(tracker_helpers, 'MeansOpenInProject')
        tracker_helpers.MeansOpenInProject(
            status, mox.IgnoreArg()).AndReturn(means_open)

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.assertCaseInsensitiveEqual(props['status'], expected_status)
        self.mox.VerifyAll()
Beispiel #8
0
    def testDefaultComponent(self, header_value):
        """Checks if the default component is Infra."""
        self.test_msg.replace_header(AlertEmailHeader.COMPONENT, header_value)
        self.mox.StubOutWithMock(tracker_helpers, 'LookupComponentIDs')
        tracker_helpers.LookupComponentIDs(
            ['Infra'], mox.IgnoreArg()).AndReturn([self.component_id])

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.assertEqual(props['component_ids'], [self.component_id])
        self.mox.VerifyAll()
Beispiel #9
0
    def testGetOwnerID(self, owner, expected_owner_id):
        """Tests _GetOwnerID returns the ID of the owner."""
        self.test_msg.replace_header(AlertEmailHeader.CC, '')
        self.test_msg.replace_header(AlertEmailHeader.OWNER, owner)

        self.mox.StubOutWithMock(self.services.user, 'LookupExistingUserIDs')
        self.services.user.LookupExistingUserIDs(self.cnxn, [owner]).AndReturn(
            {owner: expected_owner_id})

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.mox.VerifyAll()
        self.assertEqual(props['owner_id'], expected_owner_id)
Beispiel #10
0
    def testGetCCIDs(self, ccers, expected_cc_ids):
        """Tests _GetCCIDs returns the IDs of the email addresses to be cc-ed."""
        self.test_msg.replace_header(AlertEmailHeader.CC,
                                     ','.join(sorted(ccers.keys())))
        self.test_msg.replace_header(AlertEmailHeader.OWNER, '')

        self.mox.StubOutWithMock(self.services.user, 'LookupExistingUserIDs')
        self.services.user.LookupExistingUserIDs(self.cnxn, sorted(
            ccers.keys())).AndReturn(ccers)

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.mox.VerifyAll()
        self.assertEqual(sorted(props['cc_ids']), sorted(expected_cc_ids))
Beispiel #11
0
    def testProcessEmailNotification_ExistingIssue(self):
        """When an alert for an ongoing incident comes in, add a comment."""
        self.mox.StubOutWithMock(alert2issue, 'IsWhitelisted')
        alert2issue.IsWhitelisted(self.from_addr).AndReturn(True)

        # FindAlertIssue() returns None for a new incident.
        self.mox.StubOutWithMock(alert2issue, 'FindAlertIssue')
        alert2issue.FindAlertIssue(self.services, self.cnxn,
                                   self.project.project_id,
                                   self.incident_label).AndReturn(self.issue)

        # Mock GetAlertProperties() to create the issue with the expected
        # properties.
        self.mox.StubOutWithMock(alert2issue, 'GetAlertProperties')
        alert2issue.GetAlertProperties(self.services, self.cnxn,
                                       self.project_id, self.incident_id,
                                       self.trooper_queue,
                                       self.msg).AndReturn(self.alert_props)

        self.mox.ReplayAll()

        # Before processing the notification, ensures that there is only 1 comment
        # in the test issue.
        comments = self._verifyIssue(self.test_issue_local_id,
                                     self.alert_props)
        self.assertEqual(len(comments), 1)

        # Process
        alert2issue.ProcessEmailNotification(self.services, self.cnxn,
                                             self.project, self.project_addr,
                                             self.from_addr, self.auth,
                                             self.msg_subject, self.msg_body,
                                             self.incident_id, self.msg,
                                             self.trooper_queue)

        # Now, it should have a new comment added.
        comments = self._verifyIssue(self.test_issue_local_id,
                                     self.alert_props)
        self.assertEqual(len(comments), 2)
        self.assertEqual(
            comments[1].content, 'Filed by %s on behalf of %s\n\n%s' %
            (self.from_addr, self.from_addr, self.msg_body))

        self.mox.VerifyAll()
Beispiel #12
0
    def testGetStatusWithOwner(self, status, expected_status):
        """Tests GetStatus with an owner."""
        owner = '*****@*****.**'
        self.test_msg.replace_header(AlertEmailHeader.OWNER, owner)
        self.test_msg.replace_header(AlertEmailHeader.CC, '')
        self.test_msg.replace_header(AlertEmailHeader.STATUS, status)

        self.mox.StubOutWithMock(self.services.user, 'LookupExistingUserIDs')
        self.services.user.LookupExistingUserIDs(self.cnxn,
                                                 [owner]).AndReturn({owner: 1})

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.assertCaseInsensitiveEqual(props['status'], expected_status)
        self.mox.VerifyAll()
Beispiel #13
0
    def testGetComponentIDs(self, components, expected_component_ids):
        """Tests _GetComponentIDs."""
        self.test_msg.replace_header(AlertEmailHeader.COMPONENT,
                                     ','.join(sorted(components.keys())))

        self.mox.StubOutWithMock(tracker_helpers, 'LookupComponentIDs')
        tracker_helpers.LookupComponentIDs(sorted(
            components.keys()), mox.IgnoreArg()).AndReturn([
                components[key] for key in sorted(components.keys())
                if components[key]
            ])

        self.mox.ReplayAll()
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)
        self.assertEqual(sorted(props['component_ids']),
                         sorted(expected_component_ids))
        self.mox.VerifyAll()
Beispiel #14
0
    def testGetLabels(self, header_value, expected_labels):
        """Tests _GetLabels."""
        self.test_msg.replace_header(AlertEmailHeader.LABEL, header_value)
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)

        # Check if there are any duplicates
        labels = set(props['labels'])
        self.assertEqual(sorted(props['labels']), sorted(list(labels)))

        # Check the labels that shouldb always be included
        self.assertIn('Restrict-View-Google'.lower(), labels)
        self.assertIn(props['trooper_queue'], labels)
        self.assertIn(props['incident_label'], labels)
        self.assertIn(props['priority'], labels)
        self.assertIn(props['issue_type'], labels)
        self.assertSubset(set(props['oses']), labels)

        # All the custom labels should be present.
        self.assertSubset(set(expected_labels), labels)
Beispiel #15
0
    def testLabelsWithNecessaryValues(self):
        """Checks if the labels contain all the necessary values."""
        props = alert2issue.GetAlertProperties(self.services, self.cnxn,
                                               self.project_id,
                                               self.incident_id,
                                               self.trooper_queue,
                                               self.test_msg)

        # This test assumes that the test message contains non-empty values for
        # all the headers.
        self.assertTrue(props['incident_label'])
        self.assertTrue(props['priority'])
        self.assertTrue(props['issue_type'])
        self.assertTrue(props['oses'])

        # Here are a list of the labels that props['labels'] should contain
        self.assertIn('Restrict-View-Google'.lower(), props['labels'])
        self.assertIn(self.trooper_queue, props['labels'])
        self.assertIn(props['incident_label'], props['labels'])
        self.assertIn(props['priority'], props['labels'])
        self.assertIn(props['issue_type'], props['labels'])
        for os in props['oses']:
            self.assertIn(os, props['labels'])
Beispiel #16
0
    def testIssueCreated_ForNewIncident(self):
        """Tests if a new issue is created for a new incident."""
        self.mox.StubOutWithMock(alert2issue, 'IsWhitelisted')
        alert2issue.IsWhitelisted(self.from_addr).AndReturn(True)

        # FindAlertIssue() returns None for a new incident.
        self.mox.StubOutWithMock(alert2issue, 'FindAlertIssue')
        alert2issue.FindAlertIssue(self.services, self.cnxn,
                                   self.project.project_id,
                                   self.incident_label).AndReturn(None)

        # Mock GetAlertProperties() to create the issue with the expected
        # properties.
        self.mox.StubOutWithMock(alert2issue, 'GetAlertProperties')
        alert2issue.GetAlertProperties(self.services, self.cnxn,
                                       self.project_id, self.incident_id,
                                       self.trooper_queue,
                                       self.msg).AndReturn(self.alert_props)

        self.mox.ReplayAll()
        alert2issue.ProcessEmailNotification(self.services, self.cnxn,
                                             self.project, self.project_addr,
                                             self.from_addr, self.auth,
                                             self.msg_subject, self.msg_body,
                                             self.incident_id, self.msg,
                                             self.trooper_queue)

        # the local ID of the newly created issue should be +1 from the highest ID
        # in the existing issues.
        comments = self._verifyIssue(self.test_issue_local_id + 1,
                                     self.alert_props)
        self.assertEqual(
            comments[0].content, 'Filed by %s on behalf of %s\n\n%s' %
            (self.from_addr, self.from_addr, self.msg_body))

        self.mox.VerifyAll()