Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21383 -- Added request details in SuspiciousOperation messages

  • Loading branch information...
commit e6dd70b4dba3b7d812fecda7288c9707990ea71b 1 parent 7e71482
Claude Paroz authored
7  django/core/handlers/base.py
@@ -174,7 +174,12 @@ def get_response(self, request):
174 174
             # The security logger receives events for all SuspiciousOperations
175 175
             security_logger = logging.getLogger('django.security.%s' %
176 176
                             e.__class__.__name__)
177  
-            security_logger.error(force_text(e))
  177
+            security_logger.error(
  178
+                force_text(e),
  179
+                extra={
  180
+                    'status_code': 400,
  181
+                    'request': request
  182
+                })
178 183
 
179 184
             try:
180 185
                 callback, param_dict = resolver.resolve400()
4  django/test/utils.py
@@ -407,8 +407,8 @@ def patch_logger(logger_name, log_level):
407 407
     """
408 408
     calls = []
409 409
 
410  
-    def replacement(msg):
411  
-        calls.append(msg)
  410
+    def replacement(msg, *args, **kwargs):
  411
+        calls.append(msg % args)
412 412
     logger = logging.getLogger(logger_name)
413 413
     orig = getattr(logger, log_level)
414 414
     setattr(logger, log_level, replacement)
9  tests/logging_tests/tests.py
@@ -370,3 +370,12 @@ def test_suspicious_operation_uses_sublogger(self):
370 370
             self.client.get('/suspicious_spec/')
371 371
             self.assertEqual(len(calls), 1)
372 372
             self.assertEqual(calls[0], 'dubious')
  373
+
  374
+    @override_settings(
  375
+        ADMINS=(('admin', 'admin@example.com'),),
  376
+        DEBUG=False,
  377
+    )
  378
+    def test_suspicious_email_admins(self):
  379
+        self.client.get('/suspicious/')
  380
+        self.assertEqual(len(mail.outbox), 1)
  381
+        self.assertIn('path:/suspicious/,', mail.outbox[0].body)

0 notes on commit e6dd70b

Please sign in to comment.
Something went wrong with that request. Please try again.