Skip to content

Commit

Permalink
chore: add api key (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz authored Jun 19, 2024
1 parent 4fe178d commit f734f0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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"]

1 comment on commit f734f0c

@teguhsy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice good

Please sign in to comment.