Fix admin login 500 when clients omit the trailing slash.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Shayan Azadi
2026-08-17 18:49:15 +03:30
parent 26b83dabac
commit e8423facaa
5 changed files with 66 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ from datetime import timedelta
from django.contrib.auth import get_user_model
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import override_settings
from django.utils import timezone
from PIL import Image
from rest_framework import status
@@ -343,6 +344,26 @@ class AdminLoginAPITests(APITestCase):
self.assertIn('token', response.data)
self.assertEqual(response.data['user']['username'], self.admin_username)
def test_admin_login_without_trailing_slash(self):
"""Axios/fetch omit the slash; this used to 500 with APPEND_SLASH + DEBUG."""
response = self.client.post(
'/api/admin/login',
{'username': self.admin_username, 'password': self.admin_password},
format='json',
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('token', response.data)
def test_admin_login_without_trailing_slash_debug(self):
with override_settings(DEBUG=True):
response = self.client.post(
'/api/admin/login',
{'username': self.admin_username, 'password': self.admin_password},
format='json',
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('token', response.data)
def test_admin_login_wrong_password(self):
response = self.client.post(
'/api/admin/login/',