Skip to content

Commit 3fbe68e

Browse files
Cover control-character API keys loaded from environment
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent e7bb37a commit 3fbe68e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/test_client_api_key.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,21 @@ def test_async_client_rejects_control_character_api_key():
9090
HyperbrowserError, match="api_key must not contain control characters"
9191
):
9292
AsyncHyperbrowser(api_key="bad\nkey")
93+
94+
95+
def test_sync_client_rejects_control_character_env_api_key(monkeypatch):
96+
monkeypatch.setenv("HYPERBROWSER_API_KEY", "bad\nkey")
97+
98+
with pytest.raises(
99+
HyperbrowserError, match="api_key must not contain control characters"
100+
):
101+
Hyperbrowser()
102+
103+
104+
def test_async_client_rejects_control_character_env_api_key(monkeypatch):
105+
monkeypatch.setenv("HYPERBROWSER_API_KEY", "bad\nkey")
106+
107+
with pytest.raises(
108+
HyperbrowserError, match="api_key must not contain control characters"
109+
):
110+
AsyncHyperbrowser()

tests/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ def test_client_config_from_env_raises_hyperbrowser_error_for_blank_api_key(
2323
ClientConfig.from_env()
2424

2525

26+
def test_client_config_from_env_rejects_control_character_api_key(monkeypatch):
27+
monkeypatch.setenv("HYPERBROWSER_API_KEY", "bad\nkey")
28+
29+
with pytest.raises(
30+
HyperbrowserError, match="api_key must not contain control characters"
31+
):
32+
ClientConfig.from_env()
33+
34+
2635
def test_client_config_from_env_reads_api_key_and_base_url(monkeypatch):
2736
monkeypatch.setenv("HYPERBROWSER_API_KEY", "test-key")
2837
monkeypatch.setenv("HYPERBROWSER_BASE_URL", "https://example.local")

0 commit comments

Comments
 (0)