From 4338b6526d3604b371ac37134371946baa1ed0ce Mon Sep 17 00:00:00 2001 From: Dominique Bischof Date: Fri, 3 Mar 2023 08:03:27 +0100 Subject: [PATCH] Refs #31747 -- Added more tests for preserving query strings when redirect with APPEND_SLASH in admin. --- tests/admin_views/tests.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 5f7aafe430..f1d098eb40 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -8515,6 +8515,23 @@ class AdminSiteFinalCatchAllPatternTests(TestCase): "/test_admin/admin/login/?next=/test_admin/admin/admin_views/article", ) + @override_settings(APPEND_SLASH=True) + def test_missing_slash_append_slash_true_non_staff_user_query_string(self): + user = User.objects.create_user( + username="user", + password="secret", + email="user@example.com", + is_staff=False, + ) + self.client.force_login(user) + known_url = reverse("admin:admin_views_article_changelist") + response = self.client.get("%s?id=1" % known_url[:-1]) + self.assertRedirects( + response, + "/test_admin/admin/login/?next=/test_admin/admin/admin_views/article" + "%3Fid%3D1", + ) + @override_settings(APPEND_SLASH=False) def test_missing_slash_append_slash_false(self): superuser = User.objects.create_user( @@ -8629,6 +8646,24 @@ class AdminSiteFinalCatchAllPatternTests(TestCase): response, known_url, status_code=301, target_status_code=403 ) + @override_settings(APPEND_SLASH=True) + def test_missing_slash_append_slash_true_query_without_final_catch_all_view(self): + superuser = User.objects.create_user( + username="staff", + password="secret", + email="staff@example.com", + is_staff=True, + ) + self.client.force_login(superuser) + known_url = reverse("admin10:admin_views_article_changelist") + response = self.client.get("%s?id=1" % known_url[:-1]) + self.assertRedirects( + response, + f"{known_url}?id=1", + status_code=301, + fetch_redirect_response=False, + ) + @override_settings(APPEND_SLASH=False) def test_missing_slash_append_slash_false_without_final_catch_all_view(self): superuser = User.objects.create_user(