Skip to content

Commit c77fbda

Browse files
ngnpopefelixxm
authored andcommitted
Added more tests for django.http.request.split_domain_port().
1 parent 2406805 commit c77fbda

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tests/requests_tests/tests.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,37 @@ def test_get_host_suggestion_of_allowed_host(self):
10131013
):
10141014
request.get_host()
10151015

1016-
def test_split_domain_port_removes_trailing_dot(self):
1017-
domain, port = split_domain_port("example.com.:8080")
1018-
self.assertEqual(domain, "example.com")
1019-
self.assertEqual(port, "8080")
1016+
def test_split_domain_port(self):
1017+
for host, expected in [
1018+
("<invalid>", ("", "")),
1019+
("<invalid>:8080", ("", "")),
1020+
("example.com 8080", ("", "")),
1021+
("example.com:invalid", ("", "")),
1022+
("[::1]", ("[::1]", "")),
1023+
("[::1]:8080", ("[::1]", "8080")),
1024+
("[::ffff:127.0.0.1]", ("[::ffff:127.0.0.1]", "")),
1025+
("[::ffff:127.0.0.1]:8080", ("[::ffff:127.0.0.1]", "8080")),
1026+
(
1027+
"[1851:0000:3238:DEF1:0177:0000:0000:0125]",
1028+
("[1851:0000:3238:def1:0177:0000:0000:0125]", ""),
1029+
),
1030+
(
1031+
"[1851:0000:3238:DEF1:0177:0000:0000:0125]:8080",
1032+
("[1851:0000:3238:def1:0177:0000:0000:0125]", "8080"),
1033+
),
1034+
("127.0.0.1", ("127.0.0.1", "")),
1035+
("127.0.0.1:8080", ("127.0.0.1", "8080")),
1036+
("example.com", ("example.com", "")),
1037+
("example.com:8080", ("example.com", "8080")),
1038+
("example.com.", ("example.com", "")),
1039+
("example.com.:8080", ("example.com", "8080")),
1040+
("xn--n28h.test", ("xn--n28h.test", "")),
1041+
("xn--n28h.test:8080", ("xn--n28h.test", "8080")),
1042+
("subdomain.example.com", ("subdomain.example.com", "")),
1043+
("subdomain.example.com:8080", ("subdomain.example.com", "8080")),
1044+
]:
1045+
with self.subTest(host=host):
1046+
self.assertEqual(split_domain_port(host), expected)
10201047

10211048

10221049
class BuildAbsoluteURITests(SimpleTestCase):

0 commit comments

Comments
 (0)