Skip to content

Commit 5ba9054

Browse files
authored
Fix #635: ignore update workflow when project does not match config (#636)
1 parent bd3755c commit 5ba9054

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

jbi/runner.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,23 @@ def execute_action(
202202

203203
else:
204204
# Check that issue exists (and is readable)
205-
if not jira.get_service().get_issue(
205+
jira_issue = jira.get_service().get_issue(
206206
action_context, action_context.jira.issue
207-
):
207+
)
208+
if not jira_issue:
208209
raise IgnoreInvalidRequestError(
209210
f"ignore unreadable issue {action_context.jira.issue}"
210211
)
211212

213+
# Make sure that associated project in configuration matches the
214+
# project of the linked Jira issue (see #635)
215+
if (
216+
project_key := jira_issue["fields"]["project"]["key"]
217+
) != action_context.jira.project:
218+
raise IgnoreInvalidRequestError(
219+
f"ignore linked project {project_key!r} (!={action_context.jira.project!r})"
220+
)
221+
212222
if event.target == "bug":
213223
action_context = action_context.update(
214224
operation=Operation.UPDATE,

tests/unit/test_runner.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ def webhook_comment_example(
3333

3434

3535
def test_bugzilla_object_is_always_fetched(
36-
mocked_bugzilla, webhook_create_example, actions_factory, bug_factory
36+
mocked_jira, mocked_bugzilla, webhook_create_example, actions_factory, bug_factory
3737
):
3838
# See https://github.com/mozilla/jira-bugzilla-integration/issues/292
3939
fetched_bug = bug_factory(
4040
id=webhook_create_example.bug.id,
4141
see_also=[f"{get_settings().jira_base_url}browse/JBI-234"],
4242
)
4343
mocked_bugzilla.get_bug.return_value = fetched_bug
44+
mocked_jira.get_issue.return_value = {"fields": {"project": {"key": "JBI"}}}
4445

4546
execute_action(
4647
request=webhook_create_example,
@@ -50,6 +51,30 @@ def test_bugzilla_object_is_always_fetched(
5051
mocked_bugzilla.get_bug.assert_called_once_with(webhook_create_example.bug.id)
5152

5253

54+
def test_request_is_ignored_because_project_mismatch(
55+
webhook_create_example: BugzillaWebhookRequest,
56+
actions_factory,
57+
mocked_jira,
58+
mocked_bugzilla,
59+
bug_factory,
60+
):
61+
bug = bug_factory(
62+
id=webhook_create_example.bug.id,
63+
see_also=[f"{get_settings().jira_base_url}browse/JBI-234"],
64+
)
65+
webhook_create_example.bug = bug
66+
mocked_bugzilla.get_bug.return_value = bug
67+
mocked_jira.get_issue.return_value = {"fields": {"project": {"key": "FXDROID"}}}
68+
69+
with pytest.raises(IgnoreInvalidRequestError) as exc_info:
70+
execute_action(
71+
request=webhook_create_example,
72+
actions=actions_factory(),
73+
)
74+
75+
assert str(exc_info.value) == "ignore linked project 'FXDROID' (!='JBI')"
76+
77+
5378
def test_request_is_ignored_because_private(
5479
webhook_create_example: BugzillaWebhookRequest,
5580
actions_factory,

0 commit comments

Comments
 (0)