mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Added more tests for django.http.request.split_domain_port().
This commit is contained in:
parent
24068058a6
commit
c77fbda7ce
@ -1013,10 +1013,37 @@ class HostValidationTests(SimpleTestCase):
|
||||
):
|
||||
request.get_host()
|
||||
|
||||
def test_split_domain_port_removes_trailing_dot(self):
|
||||
domain, port = split_domain_port("example.com.:8080")
|
||||
self.assertEqual(domain, "example.com")
|
||||
self.assertEqual(port, "8080")
|
||||
def test_split_domain_port(self):
|
||||
for host, expected in [
|
||||
("<invalid>", ("", "")),
|
||||
("<invalid>:8080", ("", "")),
|
||||
("example.com 8080", ("", "")),
|
||||
("example.com:invalid", ("", "")),
|
||||
("[::1]", ("[::1]", "")),
|
||||
("[::1]:8080", ("[::1]", "8080")),
|
||||
("[::ffff:127.0.0.1]", ("[::ffff:127.0.0.1]", "")),
|
||||
("[::ffff:127.0.0.1]:8080", ("[::ffff:127.0.0.1]", "8080")),
|
||||
(
|
||||
"[1851:0000:3238:DEF1:0177:0000:0000:0125]",
|
||||
("[1851:0000:3238:def1:0177:0000:0000:0125]", ""),
|
||||
),
|
||||
(
|
||||
"[1851:0000:3238:DEF1:0177:0000:0000:0125]:8080",
|
||||
("[1851:0000:3238:def1:0177:0000:0000:0125]", "8080"),
|
||||
),
|
||||
("127.0.0.1", ("127.0.0.1", "")),
|
||||
("127.0.0.1:8080", ("127.0.0.1", "8080")),
|
||||
("example.com", ("example.com", "")),
|
||||
("example.com:8080", ("example.com", "8080")),
|
||||
("example.com.", ("example.com", "")),
|
||||
("example.com.:8080", ("example.com", "8080")),
|
||||
("xn--n28h.test", ("xn--n28h.test", "")),
|
||||
("xn--n28h.test:8080", ("xn--n28h.test", "8080")),
|
||||
("subdomain.example.com", ("subdomain.example.com", "")),
|
||||
("subdomain.example.com:8080", ("subdomain.example.com", "8080")),
|
||||
]:
|
||||
with self.subTest(host=host):
|
||||
self.assertEqual(split_domain_port(host), expected)
|
||||
|
||||
|
||||
class BuildAbsoluteURITests(SimpleTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user