1
0
mirror of https://github.com/django/django.git synced 2025-01-06 08:25:50 +00:00
django/tests/deprecation/test_csrf_cookie_masked.py
Chris Jerdonek 5d80843ebc Fixed #32800 -- Changed CsrfViewMiddleware not to mask the CSRF secret.
This also adds CSRF_COOKIE_MASKED transitional setting helpful in
migrating multiple instance of the same project to Django 4.1+.

Thanks Florian Apolloner and Shai Berger for reviews.

Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-11-29 10:47:39 +01:00

31 lines
1.1 KiB
Python

import sys
from types import ModuleType
from django.conf import CSRF_COOKIE_MASKED_DEPRECATED_MSG, Settings, settings
from django.test import SimpleTestCase
from django.utils.deprecation import RemovedInDjango50Warning
class CsrfCookieMaskedDeprecationTests(SimpleTestCase):
msg = CSRF_COOKIE_MASKED_DEPRECATED_MSG
def test_override_settings_warning(self):
with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg):
with self.settings(CSRF_COOKIE_MASKED=True):
pass
def test_settings_init_warning(self):
settings_module = ModuleType('fake_settings_module')
settings_module.USE_TZ = False
settings_module.CSRF_COOKIE_MASKED = True
sys.modules['fake_settings_module'] = settings_module
try:
with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg):
Settings('fake_settings_module')
finally:
del sys.modules['fake_settings_module']
def test_access(self):
# Warning is not raised on access.
self.assertEqual(settings.CSRF_COOKIE_MASKED, False)