mirror of
https://github.com/jazzband/django-defender.git
synced 2026-03-16 22:10:32 +00:00
Merge pull request #47 from nephridium/decode_redis_data
Make key_list read from redis Python 3 compatible
This commit is contained in:
commit
94b7bcfffd
2 changed files with 24 additions and 2 deletions
|
|
@ -75,6 +75,26 @@ class AccessAttemptTest(DefenderTestCase):
|
|||
password=VALID_PASSWORD,
|
||||
)
|
||||
|
||||
def test_data_integrity_of_get_blocked_ips(self):
|
||||
""" Test whether data retrieved from redis via
|
||||
get_blocked_ips() is the same as the data saved
|
||||
"""
|
||||
data_in = ['127.0.0.1', '4.2.2.1']
|
||||
for ip in data_in:
|
||||
utils.block_ip(ip)
|
||||
data_out = utils.get_blocked_ips()
|
||||
self.assertEqual(sorted(data_in), sorted(data_out))
|
||||
|
||||
def test_data_integrity_of_get_blocked_usernames(self):
|
||||
""" Test whether data retrieved from redis via
|
||||
get_blocked_usernames() is the same as the data saved
|
||||
"""
|
||||
data_in = ['foo', 'bar']
|
||||
for username in data_in:
|
||||
utils.block_username(username)
|
||||
data_out = utils.get_blocked_usernames()
|
||||
self.assertEqual(sorted(data_in), sorted(data_out))
|
||||
|
||||
def test_login_get(self):
|
||||
""" visit the login page """
|
||||
response = self.client.get(ADMIN_LOGIN_URL)
|
||||
|
|
|
|||
|
|
@ -88,14 +88,16 @@ def strip_keys(key_list):
|
|||
def get_blocked_ips():
|
||||
""" get a list of blocked ips from redis """
|
||||
key = get_ip_blocked_cache_key("*")
|
||||
key_list = REDIS_SERVER.keys(key)
|
||||
key_list = [redis_key.decode('utf-8')
|
||||
for redis_key in REDIS_SERVER.keys(key)]
|
||||
return strip_keys(key_list)
|
||||
|
||||
|
||||
def get_blocked_usernames():
|
||||
""" get a list of blocked usernames from redis """
|
||||
key = get_username_blocked_cache_key("*")
|
||||
key_list = REDIS_SERVER.keys(key)
|
||||
key_list = [redis_key.decode('utf-8')
|
||||
for redis_key in REDIS_SERVER.keys(key)]
|
||||
return strip_keys(key_list)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue