Comments (3)
Ratelimits are calculated on staggered, fixed windows, i.e., for a given set of group/path/methods/key-value/period, ratelimit will calculate some value that will be the same every time it's calculated for period
seconds (it uses the value to stagger them so, e.g. not all hour ratelimits expire at the top of the hour).
So, imagine the limit is 1/min
, the second attempt (&
) will be ratelimited, but the 3rd won't be, even though it's within 1 minute of the first:
period: | |
attempts: ^ & ^
The reason for this is that if you reset the period every time (what ratelimit used to do) then you can end up blocking even good actors basically forever (e.g. they try every 59 seconds, continually pushing the limit out and never being allowed).
So what's probably happening is that every once in a while, you cross the boundary during that loop. The odds are bad—and your flakiness rate is low—but it's entirely possible.
You could probably simplify this by mocking ratelimit.utils.is_ratelimited
to always return True
during this test, instead of trying to actually trip the limit. Alternatively, set the number of attempts to twice the limit, to make sure you hit it even if you cross the boundary (but you'll have to drop some of the assertions within the loop).
from django-ratelimit.
Thanks a lot, makes complete sense, this had occurred to me but I assumed the limit was reset every time.
Thanks for your help.
from django-ratelimit.
For anyone else having trouble with ratelimt and CI, my solution is:
wrong_credentials = {'username': '[email protected]', 'password': 'wrong'}
found_captcha = False
for _ in range(7):
response = self.client.post(self.login_url, wrong_credentials)
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['login_form'].is_valid())
if 'captcha' in response.content:
found_captcha = True
break
self.assertTrue(found_captcha, 'captcha not found on login page after 7 failed login attempts')
from django-ratelimit.
Related Issues (20)
- Update package config to pyproject.toml
- `mixins.py` removed from `4.0` HOT 1
- Wrong project link on pypi HOT 4
- Unable to rate-limit on arg/kwarg value HOT 2
- Support for Django's built in `RedisCache` cache backend
- get_usage on class based view
- Expire time of Multiple ratelimit on same view not seem correct.
- Incorrect homepage link on PyPI HOT 2
- Feature request: Attach information about rate-limit violations to request object for use in custom middleware
- Blacken Codes HOT 1
- Add async support? HOT 18
- Add a configurable cache key timeout
- Add informational headers for rate-limit HOT 4
- Wrong Status Code HOT 1
- Alias function for is_ratelimited HOT 2
- Documentation for custom get_usage / is_rate_limited needed. HOT 1
- RATELIMIT_VIEW Not Functioning as Expected with Class-Based Views HOT 14
- Is there a way to clear the ratelimit for a user ? HOT 2
- Is sliding time window rate limiting supported? HOT 3
- @ratelimit(key='post:username', rate='5/m') not working. It does not base limit from post data.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-ratelimit.