From a51abb18dc0403186cb84bf84924a8bf06e469c9 Mon Sep 17 00:00:00 2001 From: Sylvia McLaughlin <85905333+sylviamclaughlin@users.noreply.github.com> Date: Wed, 12 Jun 2024 19:36:00 +0000 Subject: [PATCH 1/2] Removing the rate limiting for the geolocate function --- app/server/server.py | 1 - app/tests/server/test_server.py | 25 ------------------------- 2 files changed, 26 deletions(-) diff --git a/app/server/server.py b/app/server/server.py index ddad0a56..0275e37d 100644 --- a/app/server/server.py +++ b/app/server/server.py @@ -198,7 +198,6 @@ async def user(request: Request): # Geolocate route. Returns the country, city, latitude, and longitude of the IP address. # If we have a custom header of 'X-Sentinel-Source', then we skip rate limiting so that Sentinel is not rate limited @handler.get("/geolocate/{ip}") -@limiter.limit("20/minute", key_func=sentinel_key_func) def geolocate(ip, request: Request): reader = maxmind.geolocate(ip) if isinstance(reader, str): diff --git a/app/tests/server/test_server.py b/app/tests/server/test_server.py index b9c75c44..fe93e3bc 100644 --- a/app/tests/server/test_server.py +++ b/app/tests/server/test_server.py @@ -582,31 +582,6 @@ async def test_user_rate_limiting(): assert response.json() == {"message": "Rate limit exceeded"} -@pytest.mark.asyncio -async def test_geolocate_rate_limiting(): - async with AsyncClient(app=app, base_url="http://test") as client: - # Mock the maxmind.geolocate function - with patch( - "server.server.maxmind.geolocate", - return_value=("Country", "City", 12.34, 56.78), - ): - # Make 10 requests to the geolocate endpoint - for _ in range(20): - response = await client.get("/geolocate/8.8.8.8") - assert response.status_code == 200 - assert response.json() == { - "country": "Country", - "city": "City", - "latitude": 12.34, - "longitude": 56.78, - } - - # The 21th request should be rate limited - response = await client.get("/geolocate/8.8.8.8") - assert response.status_code == 429 - assert response.json() == {"message": "Rate limit exceeded"} - - @pytest.mark.asyncio async def test_webhooks_rate_limiting(): async with AsyncClient(app=app, base_url="http://test") as client: From f5481b464204b903a8754322bdd45ebde0766d2e Mon Sep 17 00:00:00 2001 From: Sylvia McLaughlin <85905333+sylviamclaughlin@users.noreply.github.com> Date: Wed, 12 Jun 2024 19:42:17 +0000 Subject: [PATCH 2/2] Removing the request --- app/server/server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/server/server.py b/app/server/server.py index 0275e37d..188f3e4e 100644 --- a/app/server/server.py +++ b/app/server/server.py @@ -196,9 +196,8 @@ async def user(request: Request): # Geolocate route. Returns the country, city, latitude, and longitude of the IP address. -# If we have a custom header of 'X-Sentinel-Source', then we skip rate limiting so that Sentinel is not rate limited @handler.get("/geolocate/{ip}") -def geolocate(ip, request: Request): +def geolocate(ip): reader = maxmind.geolocate(ip) if isinstance(reader, str): raise HTTPException(status_code=404, detail=reader)