File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ class ClientConfig:
1313 base_url : str = "https://api.hyperbrowser.ai"
1414 headers : Optional [Dict [str , str ]] = None
1515
16+ def __post_init__ (self ) -> None :
17+ if not isinstance (self .api_key , str ):
18+ raise HyperbrowserError ("api_key must be a string" )
19+ if not isinstance (self .base_url , str ):
20+ raise HyperbrowserError ("base_url must be a string" )
21+ self .api_key = self .api_key .strip ()
22+ self .base_url = self .base_url .strip ().rstrip ("/" )
23+
1624 @classmethod
1725 def from_env (cls ) -> "ClientConfig" :
1826 api_key = os .environ .get ("HYPERBROWSER_API_KEY" )
Original file line number Diff line number Diff line change @@ -26,3 +26,18 @@ def test_client_config_from_env_reads_api_key_and_base_url(monkeypatch):
2626
2727 assert config .api_key == "test-key"
2828 assert config .base_url == "https://example.local"
29+
30+
31+ def test_client_config_normalizes_whitespace_and_trailing_slash ():
32+ config = ClientConfig (api_key = " test-key " , base_url = " https://example.local/ " )
33+
34+ assert config .api_key == "test-key"
35+ assert config .base_url == "https://example.local"
36+
37+
38+ def test_client_config_rejects_non_string_values ():
39+ with pytest .raises (HyperbrowserError , match = "api_key must be a string" ):
40+ ClientConfig (api_key = None ) # type: ignore[arg-type]
41+
42+ with pytest .raises (HyperbrowserError , match = "base_url must be a string" ):
43+ ClientConfig (api_key = "test-key" , base_url = None ) # type: ignore[arg-type]
You can’t perform that action at this time.
0 commit comments