Make QSS multiple notification messaging nicer

This commit is contained in:
Joseph Schorr 2017-03-01 16:11:11 -05:00
parent eff1827d9d
commit 9e6c368f7a
2 changed files with 11 additions and 4 deletions

View file

@ -169,8 +169,15 @@ class VulnerabilityFoundEvent(NotificationEvent):
def get_summary(self, event_data, notification_data):
multiple_vulns = event_data.get(VulnerabilityFoundEvent.MULTIPLE_VULNERABILITY_KEY)
if multiple_vulns is not None:
msg = '%s vulnerabilities were detected in repository %s in %s tags'
return msg % (len(multiple_vulns), event_data['repository'], len(event_data['tags']))
top_priority = multiple_vulns[0].get('priority', 'Unknown')
matching = [v for v in multiple_vulns if v.get('priority', 'Unknown') == top_priority]
msg = '%s %s' % (len(matching), top_priority)
if len(matching) < len(multiple_vulns):
msg += ' and %s more' % (len(multiple_vulns) - len(matching))
msg += ' vulnerabilities were detected in repository %s in %s tags'
return msg % (event_data['repository'], len(event_data['tags']))
else:
msg = '%s vulnerability detected in repository %s in %s tags'
return msg % (event_data['vulnerability']['priority'], event_data['repository'],

View file

@ -353,8 +353,8 @@ class TestSecurityScanner(unittest.TestCase):
# Ensure we get the correct event message out as well.
event = VulnerabilityFoundEvent()
self.assertEquals('2 vulnerabilities were detected in repository devtable/simple in 2 tags',
event.get_summary(body['event_data'], {}))
msg = '1 Low and 1 more vulnerabilities were detected in repository devtable/simple in 2 tags'
self.assertEquals(msg, event.get_summary(body['event_data'], {}))
else:
self.assertIsNone(queue_item)