From 64331419c848a8b6835b25f2c600d7150f722c96 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 12 Jan 2021 09:44:36 +0100 Subject: Fixed #32311 -- Added system check for CSRF_FAILURE_VIEW setting. --- tests/check_framework/test_security.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/check_framework/test_security.py') diff --git a/tests/check_framework/test_security.py b/tests/check_framework/test_security.py index 8225b99995..9bf9bb2a0a 100644 --- a/tests/check_framework/test_security.py +++ b/tests/check_framework/test_security.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.core.checks.messages import Error from django.core.checks.security import base, csrf, sessions from django.core.management.utils import get_random_secret_key from django.test import SimpleTestCase @@ -471,3 +472,35 @@ class CheckReferrerPolicyTest(SimpleTestCase): ) def test_with_invalid_referrer_policy(self): self.assertEqual(base.check_referrer_policy(None), [base.E023]) + + +def failure_view_with_invalid_signature(): + pass + + +class CSRFFailureViewTest(SimpleTestCase): + @override_settings(CSRF_FAILURE_VIEW='') + def test_failure_view_import_error(self): + self.assertEqual( + csrf.check_csrf_failure_view(None), + [ + Error( + "The CSRF failure view '' could not be imported.", + id='security.E025', + ) + ], + ) + + @override_settings( + CSRF_FAILURE_VIEW=f'{__name__}.failure_view_with_invalid_signature', + ) + def test_failure_view_invalid_signature(self): + msg = ( + "The CSRF failure view " + "'check_framework.test_security.failure_view_with_invalid_signature' " + "does not take the correct number of arguments." + ) + self.assertEqual( + csrf.check_csrf_failure_view(None), + [Error(msg, id='security.E024')], + ) -- cgit v1.3