From 0075172f43d7503392a31340eb603f3fd93ad5b9 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 28 Jun 2014 00:08:42 +0200
Subject: [PATCH] enable/disable rate limiting and blacklisting from config

---
 authserv/ratelimit.py          | 7 +++++--
 authserv/test/test_app_main.py | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/authserv/ratelimit.py b/authserv/ratelimit.py
index 70ee03f..9b0bb02 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 298af68..c03d4a9 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()
 
-- 
GitLab