import copy import json import unittest import security_public_sync as sync from security_public_api import PublicDataError, PublicErrorCode from security_release_notes import BASE_URL, END, START TAG = "autogpt-platform-beta-v0.9.0" def advisory(ghsa="GHSA-aaaa-bbbb-cccc"): return { "ghsa_id": ghsa, "state": "published", "published_at": "2026-10-24T12:00:00Z", "withdrawn_at": None, "summary": "Example fix", "description": f"Fixed in [{TAG}]({BASE_URL}/releases/tag/{TAG}).", "vulnerabilities": [{"patched_versions": "0.9.0"}], "credits_detailed": [ {"user": {"login": "researcher"}, "state": "accepted", "type": "reporter"} ], } def release_tags(item): return sync.public_snapshot([item])["advisories"][0]["release_tags"] def notes(items, existing=""): return sync.public_release_notes(sync.public_snapshot(items), TAG, existing) class ReleaseAttributionTest(unittest.TestCase): def test_publication_and_consent_boundaries(self): public = advisory() public["credits_detailed"] += [ {"user": {"login": "pending"}, "state": "pending", "type": "reporter"}, {"user": {"login": "declined"}, "state": "declined", "type": "reporter"}, { "user": {"login": "maintainer"}, "state": "accepted", "type": "remediation_developer", }, ] excluded = [dict(advisory(), state=s) for s in ("triage", "draft", "closed")] excluded += [ dict(advisory(), published_at=None), dict(advisory(), withdrawn_at="2026-10-24"), ] snapshot = sync.public_snapshot([public, *excluded]) self.assertEqual(len(snapshot["advisories"]), 1) result = sync.public_release_notes(snapshot, TAG, "") self.assertIn("@researcher", result) for forbidden in ("@pending", "@declined", "@maintainer", "Example fix"): self.assertNotIn(forbidden, result) def test_deleted_credit_users_are_skipped_and_bad_ids_fail_closed(self): valid = advisory() valid["credits_detailed"] += [ {"user": None, "state": "accepted", "type": "reporter"}, {"state": "accepted", "type": "reporter"}, ] self.assertEqual( sync.public_snapshot([valid])["advisories"][0]["researchers"], ["researcher"], ) missing = advisory() del missing["ghsa_id"] for broken in (missing, advisory(None), advisory("GHSA-not-valid")): with self.subTest(ghsa=broken.get("ghsa_id")), self.assertRaises( PublicDataError ) as raised: sync.public_snapshot([valid, broken]) self.assertIs(raised.exception.code, PublicErrorCode.ADVISORY_ID) def test_only_valid_cve_identifiers_are_rendered(self): item = advisory() item["cve_id"] = "CVE-2026-12345" self.assertIn("(CVE-2026-12345)", notes([item])) for cve in (None, "CVE-2026-12", "CVE-2026-12345