From 2808cdc8fb15ad27f83af3e62db69f5ea7ced29e Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Mon, 7 Sep 2020 13:33:47 +0200 Subject: Fixed #31962 -- Made SessionMiddleware raise SessionInterrupted when session destroyed while request is processing. --- tests/sessions_tests/tests.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/sessions_tests') diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index 29b58073e1..11adef9d75 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -19,7 +19,9 @@ from django.contrib.sessions.backends.file import SessionStore as FileSession from django.contrib.sessions.backends.signed_cookies import ( SessionStore as CookieSession, ) -from django.contrib.sessions.exceptions import InvalidSessionKey +from django.contrib.sessions.exceptions import ( + InvalidSessionKey, SessionInterrupted, +) from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.models import Session from django.contrib.sessions.serializers import ( @@ -28,7 +30,7 @@ from django.contrib.sessions.serializers import ( from django.core import management from django.core.cache import caches from django.core.cache.backends.base import InvalidCacheBackendError -from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation +from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse from django.test import ( RequestFactory, SimpleTestCase, TestCase, ignore_warnings, @@ -746,10 +748,10 @@ class SessionMiddlewareTests(TestCase): "The request's session was deleted before the request completed. " "The user may have logged out in a concurrent request, for example." ) - with self.assertRaisesMessage(SuspiciousOperation, msg): + with self.assertRaisesMessage(SessionInterrupted, msg): # Handle the response through the middleware. It will try to save # the deleted session which will cause an UpdateError that's caught - # and raised as a SuspiciousOperation. + # and raised as a SessionInterrupted. middleware(request) def test_session_delete_on_end(self): -- cgit v1.3