Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove the /api/v2/token endpoint
Roland Geider3fb51282436c
diff --git a/wger/core/tests/test_apikey.py b/wger/core/tests/test_apikey.pyindex 9a179a586..b93cd1c33 100644--- a/wger/core/tests/test_apikey.py+++ b/wger/core/tests/test_apikey.py@@ -24,6 +24,7 @@ from django.urls import reverse# Third Partyfrom rest_framework.authtoken.models import Tokenfrom rest_framework.test import APIClient+from rest_framework_simplejwt.tokens import RefreshTokenfrom rest_framework_simplejwt.token_blacklist.models import (BlacklistedToken,OutstandingToken,@@ -140,13 +141,8 @@ class ApiKeyTestCase(WgerTestCase):and a previously-issued refresh must stop minting access tokens."""api = APIClient()- obtain = api.post(- '/api/v2/token',- {'username': 'test', 'password': 'testtest'},- format='json',- )- self.assertEqual(obtain.status_code, 200)- old_refresh = obtain.data['refresh']+ user = User.objects.get(username='test')+ old_refresh = str(RefreshToken.for_user(user))# Sanity baseline before the revokerefresh_before = api.post(@@ -183,13 +179,8 @@ class ApiKeyTestCase(WgerTestCase):leakage here would be a one-call DoS."""api_admin = APIClient()- admin_obtain = api_admin.post(- '/api/v2/token',- {'username': 'admin', 'password': 'adminadmin'},- format='json',- )- self.assertEqual(admin_obtain.status_code, 200)- admin_refresh = admin_obtain.data['refresh']+ admin = User.objects.get(username='admin')+ admin_refresh = str(RefreshToken.for_user(admin))self.user_login('test')response = self.client.post(@@ -213,12 +204,8 @@ class ApiKeyTestCase(WgerTestCase):kills the victim's mobile sessions."""api = APIClient()- obtain = api.post(- '/api/v2/token',- {'username': 'test', 'password': 'testtest'},- format='json',- )- old_refresh = obtain.data['refresh']+ user = User.objects.get(username='test')+ old_refresh = str(RefreshToken.for_user(user))self.user_login('test')response = self.client.get(@@ -378,9 +365,7 @@ class LongLivedRefreshTokenTestCase(WgerTestCase):# And the marker really is what gates inclusion.browser_sessions = [- s- for s in Session.objects.all()- if s.get_decoded().get('_auth_user_id') == str(user.pk)+ s for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == str(user.pk)]self.assertTrue(browser_sessions)for s in browser_sessions:diff --git a/wger/core/tests/test_change_password.py b/wger/core/tests/test_change_password.pyindex ebf7ab2f8..8ecd7f041 100644--- a/wger/core/tests/test_change_password.py+++ b/wger/core/tests/test_change_password.py@@ -24,6 +24,7 @@ from django.urls import reverse# Third Partyfrom rest_framework.authtoken.models import Tokenfrom rest_framework.test import APIClient+from rest_framework_simplejwt.tokens import RefreshToken# wgerfrom wger.core.tests.base_testcase import WgerTestCase@@ -129,13 +130,7 @@ class ChangePasswordTestCase(WgerTestCase):drf_token_key = Token.objects.get(user=user).keyapi = APIClient()- obtain = api.post(- '/api/v2/token',- {'username': 'test', 'password': 'testtest'},- format='json',- )- self.assertEqual(obtain.status_code, 200)- old_refresh = obtain.data['refresh']+ old_refresh = str(RefreshToken.for_user(user))self.user_login('test')response = self.client.post(diff --git a/wger/core/tests/test_user_login.py b/wger/core/tests/test_user_login.pyindex c09db35f9..6e00d4577 100644--- a/wger/core/tests/test_user_login.py+++ b/wger/core/tests/test_user_login.py@@ -5,15 +5,8 @@ from unittest import mockfrom django.contrib.auth.models import Userfrom django.urls import reverse-# Third Party-from rest_framework import status-# wger-from wger.core.tests.api_base_test import ApiBaseTestCase-from wger.core.tests.base_testcase import (- BaseTestCase,- WgerTestCase,-)+from wger.core.tests.base_testcase import WgerTestCasefrom wger.core.views.user import trainer_login@@ -84,40 +77,6 @@ class TrainerLoginTestCase(WgerTestCase):self.assertEqual(404, resp.status_code)-class JwtTokenEmailLoginTestCase(BaseTestCase, ApiBaseTestCase):- """- The SimpleJWT token endpoint forwards its credential as ``username``.- allauth's authentication backend must resolve that value as an email- address too, so a user can obtain a JWT with either identifier.- """-- url = '/api/v2/token'-- def test_obtain_token_with_email(self):- response = self.client.post(- self.url,- {'username': '[email protected]', 'password': 'adminadmin'},- )- self.assertEqual(response.status_code, status.HTTP_200_OK)- self.assertIn('access', response.data)- self.assertIn('refresh', response.data)-- def test_obtain_token_with_username(self):- response = self.client.post(- self.url,- {'username': 'admin', 'password': 'adminadmin'},- )- self.assertEqual(response.status_code, status.HTTP_200_OK)- self.assertIn('access', response.data)-- def test_obtain_token_with_email_wrong_password(self):- response = self.client.post(- self.url,- {'username': '[email protected]', 'password': 'wrong-password'},- )- self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)--class WebLoginViewTestCase(WgerTestCase):"""The web login view (core:user:login) is allauth's LoginView, with one wgerdiff --git a/wger/urls.py b/wger/urls.pyindex a526dbf79..ca38336a9 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -34,7 +34,6 @@ from drf_spectacular.views import ()from rest_framework import routersfrom rest_framework_simplejwt.views import (- TokenObtainPairView,TokenRefreshView,TokenVerifyView,)@@ -315,7 +314,6 @@ urlpatterns += [core_api_views.UserAPIRegistrationViewSet.as_view({'post': 'post'}),name='api_register',),- path('api/v2/token', TokenObtainPairView.as_view(), name='token_obtain_pair'),path('api/v2/token/refresh', TokenRefreshView.as_view(), name='token_refresh'),path('api/v2/token/verify', TokenVerifyView.as_view(), name='token_verify'),# Others