Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix missing rate limit model from rate_limit info endpoint (#815)
sarayourfriend0f21592f1061
diff --git a/api/catalog/api/views/oauth2_views.py b/api/catalog/api/views/oauth2_views.pyindex 580dfb7f1..bdf12d68e 100644--- a/api/catalog/api/views/oauth2_views.py+++ b/api/catalog/api/views/oauth2_views.py@@ -277,6 +277,10 @@ curl \\burst_throttle_key = throttle_key.format(scope="enhanced_oauth2_client_credentials_burst", client_id=client_id)+ elif throttle_type == "exempt":+ burst_throttle_key = sustained_throttle_key = throttle_key.format(+ scope="exempt_oauth2_client_credentials_burst", client_id=client_id+ )else:return Response(status=500, data="Unknown API key rate limit type")diff --git a/api/test/auth_test.py b/api/test/auth_test.pyindex e6e308eed..f457f9994 100644--- a/api/test/auth_test.py+++ b/api/test/auth_test.py@@ -6,8 +6,9 @@ from django.urls import reversefrom django.utils.http import urlencodeimport pytest+from oauth2_provider.models import AccessToken-from catalog.api.models import OAuth2Verification+from catalog.api.models import OAuth2Verification, ThrottledApplication@pytest.mark.django_db@@ -52,7 +53,11 @@ def test_auth_token_exchange(client, test_auth_tokens_registration):@pytest.mark.django_db-def test_auth_email_verification(client, test_auth_token_exchange):+ "rate_limit_model",+ [x[0] for x in ThrottledApplication.RATE_LIMIT_MODELS],+)+def test_auth_email_verification(client, rate_limit_model, test_auth_token_exchange):# This test needs to cheat by looking in the database, so it will be# skipped in non-local environments.if API_URL == "http://localhost:8000":@@ -61,22 +66,33 @@ def test_auth_email_verification(client, test_auth_token_exchange):path = reverse("verify-email", args=[code])res = client.get(path)assert res.status_code == 200- test_auth_rate_limit_reporting(client, test_auth_token_exchange, verified=True)+ test_auth_rate_limit_reporting(+ client, rate_limit_model, test_auth_token_exchange, verified=True+ )@pytest.mark.django_db-def test_auth_rate_limit_reporting(client, test_auth_token_exchange, verified=False):+ "rate_limit_model",+ [x[0] for x in ThrottledApplication.RATE_LIMIT_MODELS],+)+def test_auth_rate_limit_reporting(+ client, rate_limit_model, test_auth_token_exchange, verified=False+):# We're anonymous still, so we need to wait a second before exchanging# the token.time.sleep(1)token = test_auth_token_exchange["access_token"]+ application = AccessToken.objects.get(token=token).application+ application.rate_limit_model = rate_limit_model+ application.save()res = client.get("/v1/rate_limit/", HTTP_AUTHORIZATION=f"Bearer {token}")res_data = res.json()if verified:- assert res_data["rate_limit_model"] == "standard"+ assert res_data["rate_limit_model"] == rate_limit_modelassert res_data["verified"] is Trueelse:- assert res_data["rate_limit_model"] == "standard"+ assert res_data["rate_limit_model"] == rate_limit_modelassert res_data["verified"] is False