Skip to content

Commit 569e065

Browse files
Validate env base URL resolver input type
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 260d09e commit 569e065

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

hyperbrowser/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def parse_headers_from_env(raw_headers: Optional[str]) -> Optional[Dict[str, str
7171
def resolve_base_url_from_env(raw_base_url: Optional[str]) -> str:
7272
if raw_base_url is None:
7373
return "https://api.hyperbrowser.ai"
74+
if not isinstance(raw_base_url, str):
75+
raise HyperbrowserError("HYPERBROWSER_BASE_URL must be a string")
7476
if not raw_base_url.strip():
7577
raise HyperbrowserError("HYPERBROWSER_BASE_URL must not be empty when set")
7678
return ClientConfig.normalize_base_url(raw_base_url)

tests/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ def test_client_config_resolve_base_url_from_env_defaults_and_rejects_blank():
290290
ClientConfig.resolve_base_url_from_env(" ")
291291
with pytest.raises(HyperbrowserError, match="include a host"):
292292
ClientConfig.resolve_base_url_from_env("https://")
293+
with pytest.raises(
294+
HyperbrowserError, match="HYPERBROWSER_BASE_URL must be a string"
295+
):
296+
ClientConfig.resolve_base_url_from_env(123) # type: ignore[arg-type]
293297

294298

295299
def test_client_config_normalize_base_url_validates_and_normalizes():

0 commit comments

Comments
 (0)