Skip to content

Commit cb7c36c

Browse files
fix: reject host-less catalog URLs in base and preset validators (#3209) (#3227)
`CatalogStackBase._validate_catalog_url` (inherited by `IntegrationCatalog`) and `PresetCatalog._validate_catalog_url` checked `parsed.netloc`, which is truthy for host-less URLs like `https://:8080` (port only) or `https://user@` (userinfo only). Such URLs slipped past validation despite the error message promising "a valid URL with a host", then failed later with a confusing fetch error. Switch both validators to `parsed.hostname` (None for those inputs), matching the workflow, step, and bundler catalog validators that already do this. Add regression tests covering port-only and userinfo-only URLs for both validators. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 8025481 commit cb7c36c

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎src/specify_cli/catalogs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _validate_catalog_url(cls, url: str) -> None:
8080
)
8181
# Check hostname, not netloc: netloc is truthy for host-less URLs like
8282
# "https://:8080" or "https://user@", so the host guarantee this error
83-
# promises would not actually hold. hostname is None in those cases.
83+
# promises would not actually hold. hostname is None in those cases (#3209).
8484
if not parsed.hostname:
8585
raise cls._error("Catalog URL must be a valid URL with a host.")
8686

‎src/specify_cli/presets/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ def _validate_catalog_url(self, url: str) -> None:
18631863
)
18641864
# Check hostname, not netloc: netloc is truthy for host-less URLs like
18651865
# "https://:8080" or "https://user@", so the host guarantee this error
1866-
# promises would not actually hold. hostname is None in those cases.
1866+
# promises would not actually hold. hostname is None in those cases (#3209).
18671867
if not parsed.hostname:
18681868
raise PresetValidationError(
18691869
"Catalog URL must be a valid URL with a host."

‎tests/integrations/test_integration_catalog.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ def test_missing_host_rejected(self):
7070
@pytest.mark.parametrize(
7171
"url",
7272
[
73-
"https://:8080", # port only, no host
74-
"https://:0", # port only, no host
75-
"https://user@", # userinfo only, no host
76-
"https://user:pw@", # userinfo only, no host
73+
"https://:8080", # port only, no host
74+
"https://:8080/catalog.json", # port only, with path
75+
"https://:0", # port only, no host
76+
"https://user@", # userinfo only, no host
77+
"https://user:pass@", # userinfo only, no host
7778
],
7879
)
7980
def test_hostless_url_with_truthy_netloc_rejected(self, url):
8081
# These have a truthy netloc (":8080", "user@") but no actual host,
8182
# so a netloc-based check would wrongly accept them despite the
82-
# "valid URL with a host" promise. hostname is None for all of them.
83+
# "valid URL with a host" promise. hostname is None for all of them (#3209).
8384
with pytest.raises(IntegrationCatalogError, match="valid URL"):
8485
IntegrationCatalog._validate_catalog_url(url)
8586

‎tests/test_presets.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,14 +1427,15 @@ def test_validate_catalog_url_localhost_http_allowed(self, project_dir):
14271427
@pytest.mark.parametrize(
14281428
"url",
14291429
[
1430-
"https://:8080", # port only, no host
1431-
"https://:0", # port only, no host
1432-
"https://user@", # userinfo only, no host
1433-
"https://user:pw@", # userinfo only, no host
1430+
"https://:8080", # port only, no host
1431+
"https://:8080/catalog.json", # port only, with path
1432+
"https://:0", # port only, no host
1433+
"https://user@", # userinfo only, no host
1434+
"https://user:pass@", # userinfo only, no host
14341435
],
14351436
)
14361437
def test_validate_catalog_url_hostless_rejected(self, project_dir, url):
1437-
"""Reject host-less URLs whose netloc is truthy but hostname is None.
1438+
"""Reject host-less URLs whose netloc is truthy but hostname is None (#3209).
14381439
14391440
``urlparse('https://:8080').netloc`` is ``':8080'`` (truthy) but its
14401441
``hostname`` is ``None``, so a netloc-based check would accept a URL

0 commit comments

Comments
 (0)