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

Removing the rate limiting for the geolocate function #540

Merged
merged 2 commits into from
Jun 12, 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
4 changes: 1 addition & 3 deletions app/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +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}")
@limiter.limit("20/minute", key_func=sentinel_key_func)
def geolocate(ip, request: Request):
def geolocate(ip):
reader = maxmind.geolocate(ip)
if isinstance(reader, str):
raise HTTPException(status_code=404, detail=reader)
Expand Down
25 changes: 0 additions & 25 deletions app/tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading