summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-05-20 17:12:25 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-05-23 10:24:09 +0200
commit9db932ab4c4e0e85697719443247d229bf14db9a (patch)
tree477f1a1ced8b10ab8d154ad3f0a943fc68cb20a3 /tests/auth_tests
parentcdd374939a3df497ff050e16663a73acb6cca899 (diff)
[5.2.x] Fixed #36390 -- Deprecated RemoteUserMiddleware subclasses missing aprocess_request().
Regression in 50f89ae850f6b4e35819fe725a08c7e579bfd099. Thank you to shamoon for the report and Natalia Bidart for the review. Backport of 1704c49a9b149b66b6a0e67abc8c95293bc35649 from main.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_remote_user.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py
index 85de931c1a..e84c1b2e4c 100644
--- a/tests/auth_tests/test_remote_user.py
+++ b/tests/auth_tests/test_remote_user.py
@@ -13,6 +13,7 @@ from django.test import (
modify_settings,
override_settings,
)
+from django.utils.deprecation import RemovedInDjango61Warning
@override_settings(ROOT_URLCONF="auth_tests.urls")
@@ -487,3 +488,51 @@ class PersistentRemoteUserTest(RemoteUserTest):
response = await self.async_client.get("/remote_user/")
self.assertFalse(response.context["user"].is_anonymous)
self.assertEqual(response.context["user"].username, "knownuser")
+
+
+# RemovedInDjango61Warning.
+class CustomProcessRequestMiddlewareSyncOnly(RemoteUserMiddleware):
+ def process_request(self, request):
+ raise NotImplementedError("process_request has not been implemented.")
+
+
+# RemovedInDjango61Warning.
+class CustomProcessRequestMiddleware(RemoteUserMiddleware):
+ def process_request(self, request):
+ raise NotImplementedError("process_request has not been implemented.")
+
+ async def aprocess_request(self, request):
+ raise NotImplementedError("aprocess_request has not been implemented.")
+
+
+# RemovedInDjango61Warning.
+@override_settings(ROOT_URLCONF="auth_tests.urls")
+class CustomProcessRequestMiddlewareTest(TestCase):
+ @modify_settings(
+ MIDDLEWARE={
+ "append": "auth_tests.test_remote_user."
+ "CustomProcessRequestMiddlewareSyncOnly"
+ }
+ )
+ async def test_async_warns_sync_only_middleware(self):
+ deprecation_msg = (
+ "Support for subclasses of RemoteUserMiddleware that override "
+ "process_request() without overriding aprocess_request() is "
+ "deprecated."
+ )
+ error_msg = "process_request has not been implemented."
+ with (
+ self.assertWarnsMessage(RemovedInDjango61Warning, deprecation_msg),
+ self.assertRaisesMessage(NotImplementedError, error_msg),
+ ):
+ await self.async_client.get("/remote_user/")
+
+ @modify_settings(
+ MIDDLEWARE={
+ "append": "auth_tests.test_remote_user.CustomProcessRequestMiddleware"
+ }
+ )
+ async def test_async_no_warning_sync_and_async_middleware(self):
+ error_msg = "aprocess_request has not been implemented."
+ with self.assertRaisesMessage(NotImplementedError, error_msg):
+ await self.async_client.get("/remote_user/")