aboutsummaryrefslogtreecommitdiff
path: root/tests/forms
diff options
context:
space:
mode:
Diffstat (limited to 'tests/forms')
-rw-r--r--tests/forms/test_validators.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py
index 10796e9..ae4c8f2 100644
--- a/tests/forms/test_validators.py
+++ b/tests/forms/test_validators.py
@@ -12,6 +12,7 @@ from wtforms import Form, StringField, ValidationError
from webmentions_ssg.forms.validators import (
AllowedHostname,
NotEqualTo,
+ PublicIPLiteral,
PublicURL,
URLMaxBytes,
)
@@ -119,6 +120,21 @@ def test_public_url_uses_custom_message(monkeypatch: pytest.MonkeyPatch) -> None
PublicURL("Public URL required")(form, form.url)
+@pytest.mark.parametrize(
+ "address",
+ ["64:ff9b::a9fe:a9fe", "::10.0.0.1", "2002:a9fe:a9fe::1", "::ffff:169.254.169.254"],
+)
+def test_public_ip_literal_rejects_ipv6_transition_addresses(address: str) -> None:
+ form = URLForm(MultiDict({"url": f"https://[{address}]/"}))
+ with pytest.raises(ValidationError, match="URL must use a public address"):
+ PublicIPLiteral()(form, form.url)
+
+
+def test_public_ip_literal_accepts_public_ipv6_address() -> None:
+ form = URLForm(MultiDict({"url": "https://[2606:2800:220:1:248:1893:25c8:1946]/"}))
+ PublicIPLiteral()(form, form.url)
+
+
def test_allowed_hostname_handles_invalid_ipv6(app: Flask) -> None:
form = URLForm(MultiDict({"url": "http://[::1"}))
with app.app_context(), pytest.raises(ValidationError, match="Invalid input"):