diff --git a/authserv/ratelimit.py b/authserv/ratelimit.py index 70ee03fd97b2ba502027781f18e3198d82a77f25..9b0bb0292d9169851c34343ee1697052bc928a84 100644 --- a/authserv/ratelimit.py +++ b/authserv/ratelimit.py @@ -114,6 +114,8 @@ def ratelimit_http_request(key_fn, count=0, period=0): def decoratorfn(fn): @functools.wraps(fn) def _ratelimit(*args, **kwargs): + if not current_app.config.get('ENABLE_RATELIMIT'): + return fn(*args, **kwargs) key = _tostr(key_fn(fn.__name__, args)) if key and not rl.check(current_app.memcache, key): current_app.logger.debug('ratelimited: %s', key) @@ -161,13 +163,15 @@ def blacklist_on_auth_failure(key_fn, count=0, period=0, ttl=0, check_wl=False, def decoratorfn(fn): @functools.wraps(fn) def _blacklist(*args, **kwargs): + if not current_app.config.get('ENABLE_BLACKLIST'): + return fn(*args, **kwargs) key = _tostr(key_fn(fn.__name__, args)) if not key: return fn(*args, **kwargs) if ((not check_wl or not whitelisted(key)) and not bl.check(current_app.memcache, key)): - current_app.logger.debug('blacklisted %s', key) + current_app.logger.info('blacklisted %s', key) return bl_return_value result = fn(*args, **kwargs) if result != protocol.OK: @@ -175,4 +179,3 @@ def blacklist_on_auth_failure(key_fn, count=0, period=0, ttl=0, check_wl=False, return result return _blacklist return decoratorfn - diff --git a/authserv/test/test_app_main.py b/authserv/test/test_app_main.py index 298af680cfe5bb6bcef03b2d816117a3836697a4..c03d4a928ad4451e5e8ed46f48d2e3fd7bbe23f6 100644 --- a/authserv/test/test_app_main.py +++ b/authserv/test/test_app_main.py @@ -22,6 +22,7 @@ class ServerTest(unittest.TestCase): app.config.update({ 'TESTING': True, 'DEBUG': True, + 'ENABLE_BLACKLIST': True, }) self.app = app.test_client()