diff options
| author | Matt Robenolt <matt@ydekproductions.com> | 2015-08-02 16:56:54 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-04 09:50:57 -0400 |
| commit | 4dcfbd792342667174834c40e792f1b8ac2f0609 (patch) | |
| tree | 27fd26c9e063a4aabb4427230f52f89758b25fa1 /tests | |
| parent | f6259ce776eb022d1ca05fc5f4e5bc56ca1a4728 (diff) | |
Fixed #25211 -- Added HttpRequest.get_port() and USE_X_FORWARDED_PORT setting.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/requests/tests.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py index bbf19df4ba..8a0b32d1c0 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -651,6 +651,38 @@ class HostValidationTests(SimpleTestCase): } request.get_host() + @override_settings(USE_X_FORWARDED_PORT=False) + def test_get_port(self): + request = HttpRequest() + request.META = { + 'SERVER_PORT': '8080', + 'HTTP_X_FORWARDED_PORT': '80', + } + # Shouldn't use the X-Forwarded-Port header + self.assertEqual(request.get_port(), '8080') + + request = HttpRequest() + request.META = { + 'SERVER_PORT': '8080', + } + self.assertEqual(request.get_port(), '8080') + + @override_settings(USE_X_FORWARDED_PORT=True) + def test_get_port_with_x_forwarded_port(self): + request = HttpRequest() + request.META = { + 'SERVER_PORT': '8080', + 'HTTP_X_FORWARDED_PORT': '80', + } + # Should use the X-Forwarded-Port header + self.assertEqual(request.get_port(), '80') + + request = HttpRequest() + request.META = { + 'SERVER_PORT': '8080', + } + self.assertEqual(request.get_port(), '8080') + @override_settings(DEBUG=True, ALLOWED_HOSTS=[]) def test_host_validation_disabled_in_debug_mode(self): """If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass.""" |
