Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/psrt_ghsa_bot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ def apply_to_repo(
print(f" 🧹 Closed {ghsa_id}")
continue

# Maintain a dictionary of updates to make and then submit them all at once.
patch_data = {}

# If the summary contains '[ACCEPT{ED}]' we can move the ticket to draft
if state == "triage" and re.search(r"\[ACCEPT(?:ED)?\]", summary.upper()) is not None:
Comment thread
zooba marked this conversation as resolved.
patch_data["state"] = state = "draft"
print(f" ✅ Will accept {ghsa_id}")

# Advisories that are in the 'draft' state without a private
# fork active will have a fork requested.
if state == "draft" and security_advisory.get("private_fork") is None:
Expand All @@ -175,9 +183,6 @@ def apply_to_repo(
print(f" ⚠️ Error creating private fork: {e.response.json()}")
raise e

# Maintain a dictionary of updates to make and then submit them all at once.
patch_data = {}

# Advisories that are in the 'draft' state without a CVE ID
# should have one allocated by the PSF CVE Numbering Authority.
if state == "draft" and security_advisory.get("cve_id") is None:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,35 @@ def test_closes_advisory_with_close_or_complete_tag(summary) -> None:
)


@pytest.mark.parametrize(
"summary",
[
"[ACCEPT] Python is better than C",
"[ACCEPTED] 0.1 + 0.2 is broken?!?!?!?!?!",
"fix soemthing in datetime module [ACCEPTED]",
"blah blah [accepted] lowercase blah",
],
)
def test_accepts_advisory_with_accept_tag(summary, cve_id, cve_reserve_response) -> None:
security_advisory = _create_advisory_dict("triage", None, ["psrt"], summary=summary)

github = mock.Mock()
cve_api = mock.Mock()
cve_api.reserve.return_value = cve_reserve_response

with mock.patch("psrt_ghsa_bot.app.get_repository_advisories") as get_repo_advs:
get_repo_advs.return_value = [security_advisory]

app.apply_to_repo(github, "owner", "repo", cve_api)

github.rest.security_advisories.update_repository_advisory.assert_called_once_with(
owner="owner",
repo="repo",
ghsa_id="GHSA-xxxx-xxxx-xxxx",
data={"state": "draft", "cve_id": cve_id},
)


def test_load_psrt_members_from_devguide() -> None:
with mock.patch("psrt_ghsa_bot.app.urllib3.request") as urllib3_request:
resp = mock.Mock()
Expand Down
Loading