Skip to content

Commit 360aa74

Browse files
Reject blank API keys in environment config loader
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 3b69550 commit 360aa74

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

hyperbrowser/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ClientConfig:
1616
@classmethod
1717
def from_env(cls) -> "ClientConfig":
1818
api_key = os.environ.get("HYPERBROWSER_API_KEY")
19-
if api_key is None:
19+
if api_key is None or not api_key.strip():
2020
raise HyperbrowserError(
2121
"HYPERBROWSER_API_KEY environment variable is required"
2222
)

tests/test_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def test_client_config_from_env_raises_hyperbrowser_error_without_api_key(monkey
1111
ClientConfig.from_env()
1212

1313

14+
def test_client_config_from_env_raises_hyperbrowser_error_for_blank_api_key(monkeypatch):
15+
monkeypatch.setenv("HYPERBROWSER_API_KEY", " ")
16+
17+
with pytest.raises(HyperbrowserError, match="HYPERBROWSER_API_KEY"):
18+
ClientConfig.from_env()
19+
20+
1421
def test_client_config_from_env_reads_api_key_and_base_url(monkeypatch):
1522
monkeypatch.setenv("HYPERBROWSER_API_KEY", "test-key")
1623
monkeypatch.setenv("HYPERBROWSER_BASE_URL", "https://example.local")

0 commit comments

Comments
 (0)