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

chore: add api key #619

Merged
merged 1 commit into from
Jun 19, 2024
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
6 changes: 5 additions & 1 deletion api/account/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

from .deduplication import Rules

from trusta_labs.api import CgrantsApiKey

secret_key = CgrantsApiKey()

log = logging.getLogger(__name__)

api = NinjaExtraAPI(urls_namespace="account")
Expand Down Expand Up @@ -646,7 +650,7 @@ def get_account_customization(request, dashboard_path: str):
raise APIException("Customization not found", status.HTTP_404_NOT_FOUND)


@api.get("/allow-list/{str:list}/{str:address}", auth=None)
@api.get("/allow-list/{str:list}/{str:address}", auth=secret_key)
def check_on_allow_list(request, list: str, address: str):
"""
Check if an address is on the allow list for a specific round
Expand Down
11 changes: 9 additions & 2 deletions api/account/test/test_allow_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
import pytest
from django.test import Client
from account.models import AddressListMember, AddressList
Expand All @@ -19,13 +20,19 @@ def test_successful_get_allow_list(self):
)

client = Client()
response = client.get(f"/account/allow-list/{list_name}/{user_address}")
response = client.get(
f"/account/allow-list/{list_name}/{user_address}",
HTTP_AUTHORIZATION=settings.CGRANTS_API_TOKEN,
)
assert response.status_code == 200
assert response.json()["is_member"]

def test_unsuccessful_get_allow_list(self):
list_name = "test"
client = Client()
response = client.get(f"/account/allow-list/{list_name}/0x123")
response = client.get(
f"/account/allow-list/{list_name}/0x123",
HTTP_AUTHORIZATION=settings.CGRANTS_API_TOKEN,
)
assert response.status_code == 200
assert not response.json()["is_member"]
Loading