Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix MRO to return 405 for unsupported methods (#3175)

Dhruv Bhanushaliac08b3b5039b
diff --git a/api/api/views/oauth2_views.py b/api/api/views/oauth2_views.py
index e4dc73565..30864bf04 100644
--- a/api/api/views/oauth2_views.py
+++ b/api/api/views/oauth2_views.py
@@ -1,3 +1,4 @@
+import json
import logging as log
import secrets
import smtplib
@@ -136,9 +137,9 @@ class VerifyEmail(APIView):
@extend_schema(tags=["auth"])
-class TokenView(BaseTokenView, APIView):
+class TokenView(APIView, BaseTokenView):
@token
- def post(self, *args, **kwargs):
+ def post(self, request):
"""
Get an access token using client credentials.
@@ -154,7 +155,9 @@ class TokenView(BaseTokenView, APIView):
endpoint.
"""
- return super().post(*args, **kwargs)
+ res = super().post(request._request)
+ data = json.loads(res.content)
+ return Response(data, status=res.status_code)
@extend_schema(tags=["auth"])
diff --git a/api/test/test_auth.py b/api/test/test_auth.py
index 3aec9174a..c2dc6688a 100644
--- a/api/test/test_auth.py
+++ b/api/test/test_auth.py
@@ -52,6 +52,16 @@ def test_auth_token_exchange(client, test_auth_tokens_registration):
return res_data
+def test_auth_token_exchange_unsupported_method(client):
+ res = client.get(
+ "/v1/auth_tokens/token/",
+ verify=False,
+ )
+ assert res.status_code == 405
+ assert res.json()["detail"] == 'Method "GET" not allowed.'
+
+
@pytest.mark.django_db
@pytest.mark.parametrize(
"rate_limit_model",