|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
| 6 | +import hyperbrowser.config as config_module |
6 | 7 | from hyperbrowser.config import ClientConfig |
7 | 8 | from hyperbrowser.exceptions import HyperbrowserError |
8 | 9 |
|
@@ -437,6 +438,63 @@ def test_client_config_normalize_base_url_preserves_invalid_port_original_error( |
437 | 438 | ClientConfig.normalize_base_url("https://example.local:bad") |
438 | 439 |
|
439 | 440 | assert exc_info.value.original_error is not None |
| 441 | + |
| 442 | + |
| 443 | +def test_client_config_normalize_base_url_wraps_unexpected_port_runtime_errors( |
| 444 | + monkeypatch: pytest.MonkeyPatch, |
| 445 | +): |
| 446 | + class _ParsedURL: |
| 447 | + scheme = "https" |
| 448 | + netloc = "example.local" |
| 449 | + hostname = "example.local" |
| 450 | + query = "" |
| 451 | + fragment = "" |
| 452 | + username = None |
| 453 | + password = None |
| 454 | + path = "" |
| 455 | + |
| 456 | + @property |
| 457 | + def port(self) -> int: |
| 458 | + raise RuntimeError("unexpected port parser failure") |
| 459 | + |
| 460 | + monkeypatch.setattr(config_module, "urlparse", lambda _value: _ParsedURL()) |
| 461 | + |
| 462 | + with pytest.raises( |
| 463 | + HyperbrowserError, match="base_url must contain a valid port number" |
| 464 | + ) as exc_info: |
| 465 | + ClientConfig.normalize_base_url("https://example.local") |
| 466 | + |
| 467 | + assert exc_info.value.original_error is not None |
| 468 | + |
| 469 | + |
| 470 | +def test_client_config_normalize_base_url_preserves_hyperbrowser_port_errors( |
| 471 | + monkeypatch: pytest.MonkeyPatch, |
| 472 | +): |
| 473 | + class _ParsedURL: |
| 474 | + scheme = "https" |
| 475 | + netloc = "example.local" |
| 476 | + hostname = "example.local" |
| 477 | + query = "" |
| 478 | + fragment = "" |
| 479 | + username = None |
| 480 | + password = None |
| 481 | + path = "" |
| 482 | + |
| 483 | + @property |
| 484 | + def port(self) -> int: |
| 485 | + raise HyperbrowserError("custom port parser failure") |
| 486 | + |
| 487 | + monkeypatch.setattr(config_module, "urlparse", lambda _value: _ParsedURL()) |
| 488 | + |
| 489 | + with pytest.raises( |
| 490 | + HyperbrowserError, match="custom port parser failure" |
| 491 | + ) as exc_info: |
| 492 | + ClientConfig.normalize_base_url("https://example.local") |
| 493 | + |
| 494 | + assert exc_info.value.original_error is None |
| 495 | + |
| 496 | + |
| 497 | +def test_client_config_normalize_base_url_rejects_encoded_paths_and_hosts(): |
440 | 498 | with pytest.raises( |
441 | 499 | HyperbrowserError, match="base_url path must not contain relative path segments" |
442 | 500 | ): |
|
0 commit comments