File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,6 +188,8 @@ def normalize_base_url(base_url: str) -> str:
188188 or not isinstance (parsed_base_url_port , int )
189189 ):
190190 raise HyperbrowserError ("base_url parser returned invalid URL components" )
191+ if parsed_base_url_port is not None and not (0 <= parsed_base_url_port <= 65535 ):
192+ raise HyperbrowserError ("base_url parser returned invalid URL components" )
191193
192194 decoded_base_path = ClientConfig ._decode_url_component_with_limit (
193195 parsed_base_url_path , component_label = "base_url path"
Original file line number Diff line number Diff line change @@ -644,6 +644,56 @@ def port(self):
644644 ClientConfig .normalize_base_url ("https://example.local" )
645645
646646
647+ def test_client_config_normalize_base_url_rejects_out_of_range_port_values (
648+ monkeypatch : pytest .MonkeyPatch ,
649+ ):
650+ class _ParsedURL :
651+ scheme = "https"
652+ netloc = "example.local"
653+ hostname = "example.local"
654+ query = ""
655+ fragment = ""
656+ username = None
657+ password = None
658+ path = "/api"
659+
660+ @property
661+ def port (self ) -> int :
662+ return 70000
663+
664+ monkeypatch .setattr (config_module , "urlparse" , lambda _value : _ParsedURL ())
665+
666+ with pytest .raises (
667+ HyperbrowserError , match = "base_url parser returned invalid URL components"
668+ ):
669+ ClientConfig .normalize_base_url ("https://example.local" )
670+
671+
672+ def test_client_config_normalize_base_url_rejects_negative_port_values (
673+ monkeypatch : pytest .MonkeyPatch ,
674+ ):
675+ class _ParsedURL :
676+ scheme = "https"
677+ netloc = "example.local"
678+ hostname = "example.local"
679+ query = ""
680+ fragment = ""
681+ username = None
682+ password = None
683+ path = "/api"
684+
685+ @property
686+ def port (self ) -> int :
687+ return - 1
688+
689+ monkeypatch .setattr (config_module , "urlparse" , lambda _value : _ParsedURL ())
690+
691+ with pytest .raises (
692+ HyperbrowserError , match = "base_url parser returned invalid URL components"
693+ ):
694+ ClientConfig .normalize_base_url ("https://example.local" )
695+
696+
647697def test_client_config_normalize_base_url_wraps_hostname_access_errors (
648698 monkeypatch : pytest .MonkeyPatch ,
649699):
You can’t perform that action at this time.
0 commit comments