summaryrefslogtreecommitdiff
path: root/tests/requests_tests/tests.py
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-07-27 16:09:09 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-02 13:06:23 +0200
commitc77fbda7ceaf00d09c322b6e0d0b0b82b4f32e98 (patch)
treead53cece5bb5d916abe1f31ced34787fa06ae6b1 /tests/requests_tests/tests.py
parent24068058a63c506c300629fcc491601abc968926 (diff)
Added more tests for django.http.request.split_domain_port().
Diffstat (limited to 'tests/requests_tests/tests.py')
-rw-r--r--tests/requests_tests/tests.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/requests_tests/tests.py b/tests/requests_tests/tests.py
index 79f82741db..099f600867 100644
--- a/tests/requests_tests/tests.py
+++ b/tests/requests_tests/tests.py
@@ -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):