diff --git a/CommunityStore/trusted_stores.py b/CommunityStore/trusted_stores.py index 2fa6100..03d50e1 100644 --- a/CommunityStore/trusted_stores.py +++ b/CommunityStore/trusted_stores.py @@ -8,8 +8,6 @@ FALLBACK_OWNERS = ("4FusionLab",) FILENAME = "trusted-stores.json" URL = "https://raw.githubusercontent.com/4FusionLab/CommunityStore/refs/heads/main/" + FILENAME -MAX_BYTES = 16 * 1024 -MAX_OWNERS = 32 def merge_owners(*groups): @@ -25,11 +23,12 @@ def parse(data): if (not isinstance(data, dict) or type(data.get("schemaVersion")) is not int or data["schemaVersion"] != 1): raise ValueError("Invalid trusted sources schema") - owners = data.get("owners") - if (not isinstance(owners, list) or len(owners) > MAX_OWNERS - or any(not isinstance(owner, str) or not ORG.fullmatch(owner) for owner in owners)): - raise ValueError("Invalid trusted GitHub owners") - return tuple(merge_owners(owners)) + groups = (data.get("owners"), data.get("additionalOwners", [])) + for group in groups: + if not isinstance(group, list) or any( + not isinstance(owner, str) or not ORG.fullmatch(owner) for owner in group): + raise ValueError("Invalid trusted GitHub owners") + return tuple(merge_owners(*groups)) def fetch(): @@ -38,7 +37,4 @@ def fetch(): with urlopen(request, timeout=5) as response: if response.geturl() != URL: raise ValueError("Unexpected trusted sources URL") - body = response.read(MAX_BYTES + 1) - if len(body) > MAX_BYTES: - raise ValueError("Trusted sources file too large") - return parse(json.loads(body)) + return parse(json.load(response)) diff --git a/scripts/build_catalog.py b/scripts/build_catalog.py index bfa3f75..710f8b4 100644 --- a/scripts/build_catalog.py +++ b/scripts/build_catalog.py @@ -168,9 +168,7 @@ def build(output): session = releases.GitHubSession(token) if token else None with releases.use_session(session): directory = json.loads((ROOT / trusted_stores.FILENAME).read_text(encoding="utf-8")) - owners = trusted_stores.parse(directory) - additional = trusted_stores.parse({**directory, "owners": directory.get("additionalOwners", [])}) - catalogs, count, stars = build_catalog(trusted_stores.merge_owners(owners, additional)) + catalogs, count, stars = build_catalog(trusted_stores.parse(directory)) output.mkdir(parents=True) publish_artwork(catalogs, output / "artwork") for (platform, arch), owners in catalogs.items(): diff --git a/tests/test_trusted_stores.py b/tests/test_trusted_stores.py index e7be99f..badcd83 100644 --- a/tests/test_trusted_stores.py +++ b/tests/test_trusted_stores.py @@ -25,12 +25,25 @@ def test_parse_deduplicates_and_rejects_malformed_documents_as_a_whole(self): None, {"schemaVersion": True, "owners": []}, {"schemaVersion": 2, "owners": []}, {"schemaVersion": 1, "owners": "Example"}, {"schemaVersion": 1, "owners": ["Example", 7]}, {"schemaVersion": 1, "owners": ["Example", "https://github.com/Other"]}, - {"schemaVersion": 1, "owners": ["Example"] * (trusted_stores.MAX_OWNERS + 1)}, + {"schemaVersion": 1, "owners": [], "additionalOwners": "Example"}, + {"schemaVersion": 1, "owners": [], "additionalOwners": [None]}, ): with self.subTest(data=data), self.assertRaises(ValueError): trusted_stores.parse(data) - def test_fetch_uses_public_raw_endpoint_and_bounds_input(self): + def test_full_directory_and_flat_offline_cache_round_trip(self): + owners = [f"publisher-{index:05}" for index in range(2500)] + directory = {"schemaVersion": 1, "owners": owners[:32], + "additionalOwners": ["PUBLISHER-00000", *owners[32:]]} + payload = json.dumps(directory).encode() + response = io.BytesIO(payload) + response.geturl = lambda: trusted_stores.URL + with patch.object(trusted_stores, "urlopen", return_value=response): + fetched = trusted_stores.fetch() + self.assertEqual(fetched, tuple(owners)) + self.assertEqual(trusted_stores.parse({"schemaVersion": 1, "owners": list(fetched)}), fetched) + + def test_fetch_uses_public_raw_endpoint_and_validates_response(self): data = b'{"schemaVersion":1,"owners":["NewOwner"]}' def response(body, url=trusted_stores.URL): @@ -45,7 +58,7 @@ def response(body, url=trusted_stores.URL): self.assertIsNone(request.get_header("Authorization")) for invalid in ( response(data, "https://example.com/trusted-stores.json"), - response(b" " * trusted_stores.MAX_BYTES + data), + response(b"invalid JSON"), ): with patch.object(trusted_stores, "urlopen", return_value=invalid), self.assertRaises(ValueError): trusted_stores.fetch()