mirror of
https://github.com/django/django.git
synced 2025-11-02 21:03:53 +00:00
Fixed #14597 -- Added a SECURE_PROXY_SSL_HEADER setting for cases when you're behind a proxy that 'swallows' the fact that a request is HTTPS
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17209 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4d32e6abc2
commit
61f0aff811
6 changed files with 117 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import with_statement
|
|||
import os
|
||||
|
||||
from django.conf import settings, global_settings
|
||||
from django.http import HttpRequest
|
||||
from django.test import TransactionTestCase, TestCase, signals
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
|
@ -209,6 +210,36 @@ class TrailingSlashURLTests(TestCase):
|
|||
self.assertEqual('http://media.foo.com/stupid//',
|
||||
self.settings_module.MEDIA_URL)
|
||||
|
||||
class SecureProxySslHeaderTest(TestCase):
|
||||
settings_module = settings
|
||||
|
||||
def setUp(self):
|
||||
self._original_setting = self.settings_module.SECURE_PROXY_SSL_HEADER
|
||||
|
||||
def tearDown(self):
|
||||
self.settings_module.SECURE_PROXY_SSL_HEADER = self._original_setting
|
||||
|
||||
def test_none(self):
|
||||
self.settings_module.SECURE_PROXY_SSL_HEADER = None
|
||||
req = HttpRequest()
|
||||
self.assertEqual(req.is_secure(), False)
|
||||
|
||||
def test_set_without_xheader(self):
|
||||
self.settings_module.SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
|
||||
req = HttpRequest()
|
||||
self.assertEqual(req.is_secure(), False)
|
||||
|
||||
def test_set_with_xheader_wrong(self):
|
||||
self.settings_module.SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
|
||||
req = HttpRequest()
|
||||
req.META['HTTP_X_FORWARDED_PROTOCOL'] = 'wrongvalue'
|
||||
self.assertEqual(req.is_secure(), False)
|
||||
|
||||
def test_set_with_xheader_right(self):
|
||||
self.settings_module.SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
|
||||
req = HttpRequest()
|
||||
req.META['HTTP_X_FORWARDED_PROTOCOL'] = 'https'
|
||||
self.assertEqual(req.is_secure(), True)
|
||||
|
||||
class EnvironmentVariableTest(TestCase):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue