Skip to content

Commit 2485dd7

Browse files
Require hostname presence in base URL validation
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 15e4e2b commit 2485dd7

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

hyperbrowser/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def normalize_base_url(base_url: str) -> str:
6161
raise HyperbrowserError(
6262
"base_url must start with 'https://' or 'http://' and include a host"
6363
)
64+
if parsed_base_url.hostname is None:
65+
raise HyperbrowserError(
66+
"base_url must start with 'https://' or 'http://' and include a host"
67+
)
6468
if parsed_base_url.query or parsed_base_url.fragment:
6569
raise HyperbrowserError(
6670
"base_url must not include query parameters or fragments"

tests/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def test_client_config_rejects_empty_or_invalid_base_url():
210210

211211
with pytest.raises(HyperbrowserError, match="include a host"):
212212
ClientConfig(api_key="test-key", base_url="http://")
213+
with pytest.raises(HyperbrowserError, match="include a host"):
214+
ClientConfig(api_key="test-key", base_url="https://:443")
213215
with pytest.raises(
214216
HyperbrowserError, match="base_url must contain a valid port number"
215217
):
@@ -373,6 +375,8 @@ def test_client_config_normalize_base_url_validates_and_normalizes():
373375

374376
with pytest.raises(HyperbrowserError, match="base_url must start with"):
375377
ClientConfig.normalize_base_url("example.local")
378+
with pytest.raises(HyperbrowserError, match="include a host"):
379+
ClientConfig.normalize_base_url("https://:443")
376380
with pytest.raises(
377381
HyperbrowserError, match="base_url must contain a valid port number"
378382
):

tests/test_url_building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def test_client_build_url_rejects_runtime_invalid_base_url_changes():
103103
with pytest.raises(HyperbrowserError, match="include a host"):
104104
client._build_url("/session")
105105

106+
client.config.base_url = "https://:443"
107+
with pytest.raises(HyperbrowserError, match="include a host"):
108+
client._build_url("/session")
109+
106110
client.config.base_url = "https://example.local?foo=bar"
107111
with pytest.raises(
108112
HyperbrowserError, match="must not include query parameters"

0 commit comments

Comments
 (0)