From a71c9fbeb034a5a8c545c8e19679f0eb86703321 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 08:02:52 +0100 Subject: refactor(core): consolidate endpoint URL validation Replace overlapping WTForms URL and regex checks with a single `HTTPURL` validator that enforces parseable HTTP(S) URLs without rewriting whitespace. Add coverage for malformed hosts and ports plus case-insensitive schemes. --- tests/test_forms.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/test_forms.py') diff --git a/tests/test_forms.py b/tests/test_forms.py index 87b02cd..20e655c 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -63,6 +63,18 @@ class URLForm(Form): "target must begin with http or https", id="target-scheme", ), + pytest.param( + {"source": "http:///source.example/post", "target": VALID_TARGET}, + "source", + "Invalid URL.", + id="source-missing-host", + ), + pytest.param( + {"source": VALID_SOURCE, "target": "https://dennisfink.me:invalid/"}, + "target", + "Invalid URL.", + id="target-invalid-port", + ), ], ) def test_endpoint_form_rejects_invalid_field_syntax( @@ -75,6 +87,23 @@ def test_endpoint_form_rejects_invalid_field_syntax( assert expected_error in form.errors[invalid_field] +@pytest.mark.parametrize("scheme", ["http", "https", "HTTP", "HTTPS"]) +def test_endpoint_form_accepts_http_schemes_case_insensitively( + app: Flask, scheme: str +) -> None: + with app.test_request_context("/endpoint", method="POST"): + form = EndpointForm( + formdata=MultiDict( + { + "source": f"{scheme}://source.example/post", + "target": f"{scheme}://dennisfink.me/blog/example/", + } + ), + meta={"csrf": False}, + ) + assert form.validate() + + def test_endpoint_form_accepts_valid_data(app: Flask) -> None: with app.test_request_context("/endpoint", method="POST"): form = EndpointForm( -- cgit v1.3.1