diff options
| author | Adam Johnson <me@adamj.eu> | 2022-01-12 12:27:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-12 13:27:25 +0100 |
| commit | 84e98ba19456a03f355c3f01ba6c70d5f45ee260 (patch) | |
| tree | b2666e5456d1bec14f2d7bc2f51453dce3423e20 | |
| parent | 76aefe0fc918f81abaf638464c062507b2185cfd (diff) | |
Added exception to SuspiciousOperation logging.
This allows better debugging and filtering of errors.
| -rw-r--r-- | django/core/handlers/exception.py | 1 | ||||
| -rw-r--r-- | tests/logging_tests/tests.py | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/django/core/handlers/exception.py b/django/core/handlers/exception.py index 87a6650542..8b40f92005 100644 --- a/django/core/handlers/exception.py +++ b/django/core/handlers/exception.py @@ -98,6 +98,7 @@ def response_for_exception(request, exc): security_logger = logging.getLogger('django.security.%s' % exc.__class__.__name__) security_logger.error( str(exc), + exc_info=exc, extra={'status_code': 400, 'request': request}, ) if settings.DEBUG: diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 666105baff..2764917f15 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -6,7 +6,9 @@ from admin_scripts.tests import AdminScriptTestCase from django.conf import settings from django.core import mail -from django.core.exceptions import PermissionDenied +from django.core.exceptions import ( + DisallowedHost, PermissionDenied, SuspiciousOperation, +) from django.core.files.temp import NamedTemporaryFile from django.core.management import color from django.http.multipartparser import MultiPartParserError @@ -498,6 +500,7 @@ class SecurityLoggerTest(LoggingAssertionMixin, SimpleTestCase): msg='dubious', status_code=400, logger='django.security.SuspiciousOperation', + exc_class=SuspiciousOperation, ) def test_suspicious_operation_uses_sublogger(self): @@ -507,6 +510,7 @@ class SecurityLoggerTest(LoggingAssertionMixin, SimpleTestCase): msg='dubious', status_code=400, logger='django.security.DisallowedHost', + exc_class=DisallowedHost, ) @override_settings( @@ -516,7 +520,7 @@ class SecurityLoggerTest(LoggingAssertionMixin, SimpleTestCase): def test_suspicious_email_admins(self): self.client.get('/suspicious/') self.assertEqual(len(mail.outbox), 1) - self.assertIn('Report at /suspicious/', mail.outbox[0].body) + self.assertIn('SuspiciousOperation at /suspicious/', mail.outbox[0].body) class SettingsCustomLoggingTest(AdminScriptTestCase): |
