Current master does now respect ratelimiting, since parsing of the
api-paste.ini was faulty. api-paste.ini limited user limiting by
setting a line as follows:
user:<user-id>:(GET, *, ".*", 4, minute) which was passed to the
Limiter as kwargs with "user" as a key. Thus multiple user limiting
was not possible as well as extracting the id of the user was bound
to fail, since we checked on the key with startswith("user:")
An example config in the api-paste.ini has to look as follows:
limits = (POST, "*", .*, 10, MINUTE)
limits.<user-id1>:(GET, "*", .*, 4, minute)
limits.<user-id2>:(GET, "*", .*, 2, minute)
Fixes bug:
1206976
Change-Id: I4adbe3dbe3a0bd607d6e675f230b0442b08ec791
# Pick up any per-user limit information
for key, value in kwargs.items():
- if key.startswith('user:'):
- username = key[5:]
+ if key.startswith('limits.'):
+ username = key[7:]
self.levels[username] = self.parse_limits(value)
def get_limits(self, username=None):
# Pick up any per-user limit information
for key, value in kwargs.items():
- if key.startswith('user:'):
- username = key[5:]
+ if key.startswith('limits.'):
+ username = key[7:]
self.levels[username] = self.parse_limits(value)
def get_limits(self, username=None):
def setUp(self):
"""Run before each test."""
super(LimiterTest, self).setUp()
- userlimits = {'user:user3': ''}
+ userlimits = {'limits.user3': ''}
self.limiter = limits.Limiter(TEST_LIMITS, **userlimits)
def _check(self, num, verb, url, username=None):
def setUp(self):
"""Run before each test."""
super(LimiterTest, self).setUp()
- userlimits = {'user:user3': ''}
+ userlimits = {'limits.user3': ''}
self.limiter = limits.Limiter(TEST_LIMITS, **userlimits)
def _check(self, num, verb, url, username=None):