Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21383 -- Added request details in SuspiciousOperation messages

  • Loading branch information...
commit e6dd70b4dba3b7d812fecda7288c9707990ea71b 1 parent 7e71482
Claude Paroz claudep authored
7 django/core/handlers/base.py
View
@@ -174,7 +174,12 @@ def get_response(self, request):
# The security logger receives events for all SuspiciousOperations
security_logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
- security_logger.error(force_text(e))
+ security_logger.error(
+ force_text(e),
+ extra={
+ 'status_code': 400,
+ 'request': request
+ })
try:
callback, param_dict = resolver.resolve400()
4 django/test/utils.py
View
@@ -407,8 +407,8 @@ def patch_logger(logger_name, log_level):
"""
calls = []
- def replacement(msg):
- calls.append(msg)
+ def replacement(msg, *args, **kwargs):
+ calls.append(msg % args)
logger = logging.getLogger(logger_name)
orig = getattr(logger, log_level)
setattr(logger, log_level, replacement)
9 tests/logging_tests/tests.py
View
@@ -370,3 +370,12 @@ def test_suspicious_operation_uses_sublogger(self):
self.client.get('/suspicious_spec/')
self.assertEqual(len(calls), 1)
self.assertEqual(calls[0], 'dubious')
+
+ @override_settings(
+ ADMINS=(('admin', 'admin@example.com'),),
+ DEBUG=False,
+ )
+ def test_suspicious_email_admins(self):
+ self.client.get('/suspicious/')
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertIn('path:/suspicious/,', mail.outbox[0].body)
Please sign in to comment.
Something went wrong with that request. Please try again.