def test_get_corresponding_flaw_bugs_jira(self): product = 'Security Response' component = 'vulnerability' valid_flaw = BugzillaBug(flexmock(product=product, component=component, id=9999)) invalid_flaw = BugzillaBug(flexmock(product=product, component='foo', id=9998)) flaw_bugs = [valid_flaw, invalid_flaw] tracker_bugs = [ JIRABug(flexmock(key='OCPBUGS-1', fields=flexmock(labels=[f"flaw:bz#{valid_flaw.id}", f"flaw:bz#{invalid_flaw.id}"]))), JIRABug(flexmock(key='OCPBUGS-2', fields=flexmock(labels=[f"flaw:bz#{invalid_flaw.id}"]))), JIRABug(flexmock(key='OCPBUGS-3', fields=flexmock(labels=[f"flaw:bz#{valid_flaw.id}"]))) ] flexmock(BugzillaBugTracker).should_receive("login").and_return(None) flexmock(JIRABugTracker).should_receive("login").and_return(None) flexmock(BugzillaBugTracker).should_receive("get_bugs").and_return(flaw_bugs) bug_tracker = JIRABugTracker({}) flaw_bug_tracker = BugzillaBugTracker({}) expected = ( {'OCPBUGS-1': [valid_flaw.id], 'OCPBUGS-2': [], 'OCPBUGS-3': [valid_flaw.id]}, {valid_flaw.id: valid_flaw} ) actual = bug_tracker.get_corresponding_flaw_bugs(tracker_bugs, flaw_bug_tracker) self.assertEqual(expected, actual)
def test_is_first_fix_any_any(self): tr = '4.8.0' bug_a = BugzillaBug(flexmock( id=1, keywords=constants.TRACKER_BUG_KEYWORDS, whiteboard='component:runc', product=constants.BUGZILLA_PRODUCT_OCP, target_release=['4.7.z'], status='RELEASE_PENDING')) bug_b = BugzillaBug(flexmock( id=2, keywords=constants.TRACKER_BUG_KEYWORDS, whiteboard='component:runc', product=constants.BUGZILLA_PRODUCT_OCP, target_release=[tr], status='ON_QA')) bug_c = BugzillaBug(flexmock( id=3, keywords=constants.TRACKER_BUG_KEYWORDS, whiteboard='component:crio', product=constants.BUGZILLA_PRODUCT_OCP, target_release=[tr], status='ON_QA')) tracker_bug_objs = [bug_a, bug_b, bug_c] tracker_bug_ids = [t.id for t in tracker_bug_objs] flaw_bug = BugzillaBug(flexmock(id=4, depends_on=tracker_bug_ids)) flexmock(BugzillaBugTracker).should_receive("login") bug_tracker = BugzillaBugTracker({}) bug_tracker.should_receive("get_bugs").with_args(tracker_bug_ids).and_return(tracker_bug_objs) expected = True actual = bzutil.is_first_fix_any(bug_tracker, flaw_bug, tr) self.assertEqual(expected, actual)
def test_whiteboard_component_bz(self): bug = BugzillaBug(mock.MagicMock(id=1, whiteboard="foo")) self.assertIsNone(bug.whiteboard_component) bug = BugzillaBug(mock.MagicMock(id=2, whiteboard="component: ")) self.assertIsNone(bug.whiteboard_component) for expected in ["something", "openvswitch2.15", "trailing_blank "]: bug = BugzillaBug(mock.MagicMock(whiteboard=f"component: {expected}")) expected = expected.strip() actual = bug.whiteboard_component self.assertEqual(actual, expected.strip())
def test_is_first_fix_any_no_valid_trackers(self): tr = '4.8.0' tracker_bug_ids = [1, 2] bug_a = BugzillaBug(flexmock( id=1, product=constants.BUGZILLA_PRODUCT_OCP, keywords=['foo']) ) tracker_bug_objs = [bug_a] flaw_bug = BugzillaBug(flexmock(id=6, depends_on=tracker_bug_ids)) flexmock(BugzillaBugTracker).should_receive("login") bug_tracker = BugzillaBugTracker({}) bug_tracker.should_receive("get_bugs").with_args(tracker_bug_ids).and_return(tracker_bug_objs) expected = True actual = bzutil.is_first_fix_any(bug_tracker, flaw_bug, tr) self.assertEqual(expected, actual)
def test_is_first_fix_any_missing_whiteboard_component(self): tr = '4.8.0' tracker_bug_ids = [1, 2] bug_a = BugzillaBug(flexmock( id=1, product=constants.BUGZILLA_PRODUCT_OCP, keywords=constants.TRACKER_BUG_KEYWORDS, whiteboard='', target_release=[tr] )) tracker_bug_objs = [bug_a] flaw_bug = BugzillaBug(flexmock(id=6, depends_on=tracker_bug_ids)) flexmock(BugzillaBugTracker).should_receive("login") bug_tracker = BugzillaBugTracker({}) bug_tracker.should_receive("get_bugs").with_args(tracker_bug_ids).and_return(tracker_bug_objs) expected = False actual = bzutil.is_first_fix_any(bug_tracker, flaw_bug, tr) self.assertEqual(expected, actual)
def test_get_corresponding_flaw_bugs_bz_strict(self): tracker_bugs = [ BugzillaBug(flexmock(blocks=[1, 2], id=10)), BugzillaBug(flexmock(blocks=[2, 3], id=11)), BugzillaBug(flexmock(blocks=[], id=12)) ] product = 'Security Response' component = 'vulnerability' bug_a = BugzillaBug(flexmock(product=product, component='wrong_component', id=1)) bug_b = BugzillaBug(flexmock(product='wrong_product', component=component, id=2)) bug_c = BugzillaBug(flexmock(product=product, component=component, id=3)) flaw_bugs = [bug_a, bug_b, bug_c] flexmock(BugzillaBugTracker).should_receive("login").and_return(None) flexmock(BugzillaBugTracker).should_receive("get_bugs").and_return(flaw_bugs) bug_tracker = BugzillaBugTracker({}) self.assertRaisesRegex( exceptions.ElliottFatalError, r'^No flaw bugs could be found for these trackers: {10, 12}$', bug_tracker.get_corresponding_flaw_bugs, tracker_bugs, strict=True)
def test_get_corresponding_flaw_bugs_bz(self): product = 'Security Response' component = 'vulnerability' valid_flaw_a = BugzillaBug(flexmock(product=product, component=component, id=1)) valid_flaw_b = BugzillaBug(flexmock(product=product, component=component, id=2)) invalid_flaw_c = BugzillaBug(flexmock(product='foo', component=component, id=3)) invalid_flaw_d = BugzillaBug(flexmock(product=product, component='bar', id=4)) flaw_bugs = [valid_flaw_a, valid_flaw_b] tracker_bugs = [ BugzillaBug(flexmock(blocks=[valid_flaw_a.id, valid_flaw_b.id], id=10)), BugzillaBug(flexmock(blocks=[valid_flaw_b.id, invalid_flaw_c.id, invalid_flaw_d.id], id=11)), ] flexmock(BugzillaBugTracker).should_receive("login").and_return(None) flexmock(BugzillaBugTracker).should_receive("get_bugs").and_return(flaw_bugs) bug_tracker = BugzillaBugTracker({}) expected = ( {10: [valid_flaw_a.id, valid_flaw_b.id], 11: [valid_flaw_b.id]}, {valid_flaw_a.id: valid_flaw_a, valid_flaw_b.id: valid_flaw_b} ) actual = bug_tracker.get_corresponding_flaw_bugs(tracker_bugs) self.assertEqual(expected, actual)
def test_is_tracker_bug_bz(self): bug = flexmock(id='1', keywords=constants.TRACKER_BUG_KEYWORDS) expected = True actual = BugzillaBug(bug).is_tracker_bug() self.assertEqual(expected, actual)
def test_is_tracker_bug_fail_bz(self): bug = flexmock(id='1', keywords=['SomeOtherKeyword']) expected = False actual = BugzillaBug(bug).is_tracker_bug() self.assertEqual(expected, actual)
def test_associate_builds_with_cves_bz( self, fake_urils_associate_builds_with_cves: AsyncMock): errata_api = AsyncMock(spec=AsyncErrataAPI) advisory = Mock(errata_id=12345, errata_builds={ "Fake-Product-Version1": { "a-1.0.0-1.el8": {}, "b-1.0.0-1.el8": {}, "c-1.0.0-1.el8": {}, "d-1.0.0-1.el8": {}, }, "Fake-Product-Version2": { "a-1.0.0-1.el7": {}, "e-1.0.0-1.el7": {}, "f-1.0.0-1.el7": {}, } }) tracker_flaws = { 1: [101, 103], 2: [101, 103], 3: [102, 103], 4: [101, 103], 5: [102], } attached_tracker_bugs = [ BugzillaBug( Mock(id=1, keywords=["Security", "SecurityTracking"], whiteboard="component: a")), BugzillaBug( Mock(id=2, keywords=["Security", "SecurityTracking"], whiteboard="component: b")), BugzillaBug( Mock(id=3, keywords=["Security", "SecurityTracking"], whiteboard="component: c")), BugzillaBug( Mock(id=4, keywords=["Security", "SecurityTracking"], whiteboard="component: d")), BugzillaBug( Mock(id=5, keywords=["Security", "SecurityTracking"], whiteboard="component: e")), ] flaw_id_bugs = { 101: BugzillaBug( Mock(id=101, keywords=["Security"], alias=["CVE-2099-1"])), 102: BugzillaBug( Mock(id=102, keywords=["Security"], alias=["CVE-2099-2"])), 103: BugzillaBug( Mock(id=103, keywords=["Security"], alias=["CVE-2099-3"])), } actual = get_event_loop().run_until_complete( attach_cve_flaws_cli.associate_builds_with_cves( errata_api, advisory, attached_tracker_bugs, tracker_flaws, flaw_id_bugs, dry_run=False)) fake_urils_associate_builds_with_cves.assert_awaited_once_with( errata_api, 12345, [ 'a-1.0.0-1.el8', 'b-1.0.0-1.el8', 'c-1.0.0-1.el8', 'd-1.0.0-1.el8', 'a-1.0.0-1.el7', 'e-1.0.0-1.el7', 'f-1.0.0-1.el7' ], { 'CVE-2099-1': {'a', 'd', 'b'}, 'CVE-2099-3': {'a', 'd', 'b', 'c'}, 'CVE-2099-2': {'c', 'e'} }, dry_run=False) self.assertEqual(actual, None)