Fix NPE raised if a vulnerability notification doesn't have a level filter

Fixes #1990
This commit is contained in:
Joseph Schorr 2016-10-14 12:10:54 -04:00
parent 7f9e01a1fe
commit 886489c666
2 changed files with 44 additions and 4 deletions

View file

@ -1,6 +1,7 @@
import unittest
from endpoints.notificationevent import BuildSuccessEvent, NotificationEvent
from endpoints.notificationevent import (BuildSuccessEvent, NotificationEvent,
VulnerabilityFoundEvent)
from util.morecollections import AttrDict
class TestCreate(unittest.TestCase):
@ -10,6 +11,7 @@ class TestCreate(unittest.TestCase):
self.assertIsNotNone(NotificationEvent.get_event('build_success'))
self.assertIsNotNone(NotificationEvent.get_event('build_failure'))
self.assertIsNotNone(NotificationEvent.get_event('build_start'))
self.assertIsNotNone(NotificationEvent.get_event('vulnerability_found'))
class TestShouldPerform(unittest.TestCase):
@ -147,6 +149,35 @@ class TestShouldPerform(unittest.TestCase):
}, notification_data))
def test_vulnerability_notification_nolevel(self):
notification_data = AttrDict({
'event_config_json': '{}',
})
# No level specified.
self.assertTrue(VulnerabilityFoundEvent().should_perform({}, notification_data))
def test_vulnerability_notification_nopvulninfo(self):
notification_data = AttrDict({
'event_config_json': '{"level": 3}',
})
# No vuln info.
self.assertFalse(VulnerabilityFoundEvent().should_perform({}, notification_data))
def test_vulnerability_notification_normal(self):
notification_data = AttrDict({
'event_config_json': '{"level": 3}',
})
info = {"vulnerability": {"priority": "Critical"}}
self.assertTrue(VulnerabilityFoundEvent().should_perform(info, notification_data))
if __name__ == '__main__':
unittest.main()