aboutsummaryrefslogtreecommitdiff
path: root/tests/forms
diff options
context:
space:
mode:
Diffstat (limited to 'tests/forms')
-rw-r--r--tests/forms/test_init.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/forms/test_init.py b/tests/forms/test_init.py
index 2a68509..42e6a2c 100644
--- a/tests/forms/test_init.py
+++ b/tests/forms/test_init.py
@@ -144,7 +144,7 @@ def test_endpoint_handles_malformed_ipv6_without_crashing(app: Flask) -> None:
meta={"csrf": False},
)
assert not form.validate()
- assert "Invalid input." in form.errors["target"]
+ assert "Invalid URL." in form.errors["target"]
def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields(
@@ -168,3 +168,38 @@ def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields(
assert not form.validate()
assert "target" in form.errors
assert any("bytes" in message for message in form.errors["target"])
+
+
+@pytest.mark.parametrize("field_name", ["source", "target"])
+@pytest.mark.parametrize(
+ "invalid_url",
+ [
+ pytest.param("http://ex☃mple.test/", id="invalid-idn"),
+ pytest.param("https://example.com/a\nb", id="newline"),
+ pytest.param("https://example.com/a\rb", id="carriage-return"),
+ pytest.param("https://example.com/\x00b", id="nul"),
+ pytest.param("https://example.com/a b", id="ascii-space"),
+ pytest.param("https://example.com/a\u00a0b", id="unicode-whitespace"),
+ pytest.param("https://example.com/\x7fb", id="del"),
+ ],
+)
+def test_endpoint_rejects_invalid_httpx_urls_and_whitespace(
+ app: Flask, field_name: str, invalid_url: str
+) -> None:
+ data = {"source": VALID_SOURCE, "target": VALID_TARGET}
+ data[field_name] = invalid_url
+ with app.test_request_context("/endpoint", method="POST"):
+ form = EndpointForm(formdata=MultiDict(data), meta={"csrf": False})
+ assert not form.validate()
+ assert "Invalid URL." in form.errors[field_name]
+
+
+def test_endpoint_accepts_encoded_path_space(app: Flask) -> None:
+ with app.test_request_context("/endpoint", method="POST"):
+ form = EndpointForm(
+ formdata=MultiDict(
+ {"source": "https://source.example/a%20b", "target": VALID_TARGET}
+ ),
+ meta={"csrf": False},
+ )
+ assert form.validate()