From 4946f0ea9eb28c3798da6ebbd2aa8348ca632120 Mon Sep 17 00:00:00 2001 From: GappleBee Date: Sat, 23 Nov 2024 00:27:18 +0000 Subject: [PATCH] Fixed get_port test cases. --- tests/requests_tests/tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/requests_tests/tests.py b/tests/requests_tests/tests.py index eb158bc862..fea8613a44 100644 --- a/tests/requests_tests/tests.py +++ b/tests/requests_tests/tests.py @@ -1240,10 +1240,11 @@ class HostValidationTests(SimpleTestCase): } request.get_host() - @override_settings(USE_X_FORWARDED_PORT=False) + @override_settings(USE_X_FORWARDED_PORT=False, ALLOWED_HOSTS=["internal.com"]) def test_get_port(self): request = HttpRequest() request.META = { + "SERVER_NAME": "internal.com", "SERVER_PORT": "8080", "HTTP_X_FORWARDED_PORT": "80", } @@ -1252,14 +1253,16 @@ class HostValidationTests(SimpleTestCase): request = HttpRequest() request.META = { + "SERVER_NAME": "internal.com", "SERVER_PORT": "8080", } self.assertEqual(request.get_port(), "8080") - @override_settings(USE_X_FORWARDED_PORT=True) + @override_settings(USE_X_FORWARDED_PORT=True, ALLOWED_HOSTS=["internal.com"]) def test_get_port_with_x_forwarded_port(self): request = HttpRequest() request.META = { + "SERVER_NAME": "internal.com", "SERVER_PORT": "8080", "HTTP_X_FORWARDED_PORT": "80", } @@ -1268,6 +1271,7 @@ class HostValidationTests(SimpleTestCase): request = HttpRequest() request.META = { + "SERVER_NAME": "internal.com", "SERVER_PORT": "8080", } self.assertEqual(request.get_port(), "8080")