Skip to content

Commit 758a34d

Browse files
jawwad-aliclaude
andcommitted
test(presets): drop duplicate geturl mock; add legacy fetch_catalog per-hop test
- Remove the duplicate mock_response.geturl.return_value assignment left by the geturl mock-completion pass (the explanatory comment was stranded between the two identical assignments); keep a single assignment after the comment. - Add test_fetch_catalog_legacy_validates_every_redirect_hop so the legacy fetch_catalog() path is verified to supply the redirect_validator (rejecting an insecure intermediate hop), not just the terminal geturl() — parity with _fetch_single_catalog and the #3524 sibling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c2abf66 commit 758a34d

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

tests/test_presets.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,23 @@ def geturl(self):
18461846
with pytest.raises(PresetError, match="HTTPS"):
18471847
catalog.fetch_catalog(force_refresh=True)
18481848

1849+
def test_fetch_catalog_legacy_validates_every_redirect_hop(self, project_dir):
1850+
"""The legacy fetch_catalog() path also validates every INTERMEDIATE hop
1851+
(not just the terminal URL): it must supply a redirect_validator that
1852+
rejects an insecure hop, so an https -> http -> https chain is caught."""
1853+
catalog = PresetCatalog(project_dir)
1854+
captured = {}
1855+
1856+
def fake_open(url, timeout=None, redirect_validator=None):
1857+
captured["rv"] = redirect_validator
1858+
redirect_validator(url, "http://evil.test/hop")
1859+
raise AssertionError("redirect_validator should have raised")
1860+
1861+
catalog._open_url = fake_open
1862+
with pytest.raises(PresetError, match="HTTPS"):
1863+
catalog.fetch_catalog(force_refresh=True)
1864+
assert captured["rv"] is not None
1865+
18491866
@pytest.mark.parametrize(
18501867
"payload",
18511868
[
@@ -1879,7 +1896,6 @@ def test_fetch_single_catalog_rejects_malformed_payload(self, project_dir, paylo
18791896
mock_response.read.return_value = json.dumps(payload).encode()
18801897
mock_response.__enter__ = lambda s: s
18811898
mock_response.__exit__ = MagicMock(return_value=False)
1882-
mock_response.geturl.return_value = "https://example.com/catalog.json"
18831899
# A real urllib response reports the final URL (== request URL with no
18841900
# redirect); the fetcher re-validates it after redirects.
18851901
mock_response.geturl.return_value = "https://example.com/catalog.json"

0 commit comments

Comments
 (0)