Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3294 bug embed cant handle unlimited api keys #784

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/embed/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def handle_embed_add_stamps(


class AccountAPIKeySchema(Schema):
rate_limit: str
rate_limit: str | None


@api_router.get(
Expand Down
20 changes: 19 additions & 1 deletion api/embed/test/test_api_validate_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.auth.models import UserManager
from django.test import Client, TestCase

from account.models import Account, AccountAPIKey
from account.models import Account, AccountAPIKey, RateLimits

# Avoids type issues in standard django models
user_manager = cast(UserManager, get_user_model().objects)
Expand Down Expand Up @@ -49,3 +49,21 @@ def test_rate_limit_success(self):
assert rate_limit_response.status_code == 200
data = rate_limit_response.json()
assert data == {"rate_limit": api_key_obj.rate_limit}

def test_rate_limit_success_for_unlimited_rate(self):
"""Test that the rate limit API when the rate limit is set to UNLIMITED"""

(api_key_obj, api_key) = AccountAPIKey.objects.create_key(
account=self.account,
name="Token for user 1",
rate_limit=RateLimits.UNLIMITED.value,
)

rate_limit_response = self.client.get(
"/embed/validate-api-key",
**{"HTTP_X-API-KEY": api_key},
)

assert rate_limit_response.status_code == 200
data = rate_limit_response.json()
assert data == {"rate_limit": api_key_obj.rate_limit}