Fixed #23806 -- Added a test case for settings.DISALLOWED_USER_AGENTS.

This commit is contained in:
Sean Wang 2014-11-12 21:08:35 -08:00 committed by Tim Graham
parent bfb11b9562
commit 311feae8ba
1 changed files with 10 additions and 0 deletions

View File

@ -18,6 +18,7 @@ from django.middleware.common import CommonMiddleware, BrokenLinkEmailsMiddlewar
from django.middleware.http import ConditionalGetMiddleware
from django.middleware.gzip import GZipMiddleware
from django.test import TestCase, RequestFactory, override_settings
from django.test.utils import patch_logger
from django.utils import six
from django.utils.encoding import force_str
from django.utils.six.moves import xrange
@ -238,6 +239,15 @@ class CommonMiddlewareTest(TestCase):
# Other tests
@override_settings(DISALLOWED_USER_AGENTS=[re.compile(r'foo')])
def test_disallowed_user_agents(self):
with patch_logger('django.request', 'warning') as log_messages:
request = self._get_request('slash')
request.META['HTTP_USER_AGENT'] = 'foo'
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 403)
self.assertEqual(log_messages, ['Forbidden (User agent): /slash'])
def test_non_ascii_query_string_does_not_crash(self):
"""Regression test for #15152"""
request = self._get_request('slash')