mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #36560 -- Prevented UpdateCacheMiddleware from caching responses with Cache-Control 'no-cache' or 'no-store'.
This commit is contained in:
25
tests/cache/tests.py
vendored
25
tests/cache/tests.py
vendored
@@ -2731,16 +2731,21 @@ class CacheMiddlewareTest(SimpleTestCase):
|
||||
)
|
||||
cache.clear()
|
||||
|
||||
def test_cached_control_private_not_cached(self):
|
||||
"""Responses with 'Cache-Control: private' are not cached."""
|
||||
view_with_private_cache = cache_page(3)(
|
||||
cache_control(private=True)(hello_world_view)
|
||||
)
|
||||
request = self.factory.get("/view/")
|
||||
response = view_with_private_cache(request, "1")
|
||||
self.assertEqual(response.content, b"Hello World 1")
|
||||
response = view_with_private_cache(request, "2")
|
||||
self.assertEqual(response.content, b"Hello World 2")
|
||||
def test_cache_control_not_cached(self):
|
||||
"""
|
||||
Responses with 'Cache-Control: private/no-cache/no-store' are
|
||||
not cached.
|
||||
"""
|
||||
for cc in ("private", "no-cache", "no-store"):
|
||||
with self.subTest(cache_control=cc):
|
||||
view_with_cache = cache_page(3)(
|
||||
cache_control(**{cc: True})(hello_world_view)
|
||||
)
|
||||
request = self.factory.get("/view/")
|
||||
response = view_with_cache(request, "1")
|
||||
self.assertEqual(response.content, b"Hello World 1")
|
||||
response = view_with_cache(request, "2")
|
||||
self.assertEqual(response.content, b"Hello World 2")
|
||||
|
||||
def test_sensitive_cookie_not_cached(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user