API Token improvements - Token Rate Limits #27
+164
−110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is in the PR?
Add implementation to secure coverage and crashmanager API endpoints with rate-limiting.
This uses Throttling from Django rest framework and Redis cache db to store user request rate data.
Rate Limit Testing Script
A simple bash script to test API rate limiting. The script sends consecutive requests to an endpoint until it receives a rate limit response (HTTP 429) or reaches the maximum request count.
Setup
1. Create the script file:
2. Copy the script content into
test_rate_limit.sh
3. Make the script executable:
chmod +x test_rate_limit.sh
Usage
Basic Run (110 requests)
./test_rate_limit.sh
Auth setup:
You can update HARDCODED_TOKEN variable inside the script, or pass it as an argument when running the script.
To run it as part of the script command.
./test_rate_limit.sh 110 <token>
Custom Request Count
./test_rate_limit.sh 150 # Will send up to 150 requests
What to expect:
1. It will show the endpoint and maximum requests
2. For each request, you'll see the status code
3. If rate limit is hit (HTTP 429):
Shows which request triggered the limit
Displays the server's error response
4. If no rate limit is hit, shows completion message
SPEC DOC LINK:
https://docs.google.com/document/d/1l9r-t6mcwirwnxkjxdZ2HF3QWPEzanZ46Azi7F0B2nQ/edit?tab=t.0
DEMO VIDEO:
https://www.loom.com/share/d8cc5c2c5c5a4dc58df78de843cd07d5?sid=aa540f7c-9c38-4523-9085-301bdec5871e