From 52dea94b01b4ea709a643638b2676d6e1c15de40 Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Wed, 21 Oct 2026 22:28:27 +0530 Subject: [PATCH] test(security): cover malformed URL ports (cherry picked from commit 57d62172813310bd4e5819a0fe494efc216d138e) --- tests/test_security.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_security.py b/tests/test_security.py index 1479b19c5..93de72d79 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -65,6 +65,16 @@ def test_validate_url_rejects_missing_hostname(url): validate_url(url) +@pytest.mark.parametrize("url", [ + "http://example.com:abc/path", + "https://example.com:65536/path", + "http://example.com:0/path", +]) +def test_validate_url_rejects_invalid_port(url): + with pytest.raises(ValueError, match="port"): + validate_url(url) + + # --------------------------------------------------------------------------- # safe_fetch - scheme and redirect guards (mocked network) # ---------------------------------------------------------------------------