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 /tests/logging_tests | |
parent | 76aefe0fc918f81abaf638464c062507b2185cfd (diff) | |
download | django-84e98ba19456a03f355c3f01ba6c70d5f45ee260.tar.gz |
Added exception to SuspiciousOperation logging.
This allows better debugging and filtering of errors.
Diffstat (limited to 'tests/logging_tests')
-rw-r--r-- | tests/logging_tests/tests.py | 8 |
1 files changed, 6 insertions, 2 deletions
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): |