diff options
author | Tom Usher | 2022-12-07 16:25:10 +0000 |
---|---|---|
committer | GitHub | 2022-12-07 09:25:10 -0700 |
commit | 1440ee9cebe2599239ed910b3f19cba6f79ff92c (patch) | |
tree | 495d1a309d1da46da6821bbdba70d4e4af157641 /tests/users | |
parent | 25b8bf6a2e5cdbf921ca8ba4a994f57c1c859844 (diff) | |
download | takahe-1440ee9cebe2599239ed910b3f19cba6f79ff92c.tar.gz takahe-1440ee9cebe2599239ed910b3f19cba6f79ff92c.tar.bz2 takahe-1440ee9cebe2599239ed910b3f19cba6f79ff92c.zip |
Support deeper subdomains in domain validation (#110)
Use a new validator class with regex based on the URLValidator from Django
Diffstat (limited to 'tests/users')
-rw-r--r-- | tests/users/views/test_domains.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/users/views/test_domains.py b/tests/users/views/test_domains.py new file mode 100644 index 0000000..13d4b11 --- /dev/null +++ b/tests/users/views/test_domains.py @@ -0,0 +1,40 @@ +import pytest +from django.core.exceptions import ValidationError + +from users.views.admin.domains import DomainValidator + +VALID_DOMAINS = [ + "takahe.social", + "subdomain.takahe.social", + "another.subdomain.takahe.social", + "jointakahe.org", + "xn--c6h.com", + "takahe.xn--social", + "example.com", + "www.example.com", + "example.co.uk", +] + +INVALID_DOMAINS = [ + "example.c", + "example,com", + "example,com.com", + "example", + ".com", + "example.com/example", + "-example.com", + "example-.com", + "example.com-", + "https://example.com", +] + + +@pytest.mark.parametrize("domain", VALID_DOMAINS) +def test_domain_validation_accepts_valid_domains(domain): + DomainValidator()(domain) + + +@pytest.mark.parametrize("domain", INVALID_DOMAINS) +def test_domain_validation_raises_exception_for_invalid_domains(domain): + with pytest.raises(ValidationError): + DomainValidator()(domain) |