From 82a57f33bb551d8ad2637810ecdc99aca140069f Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Wed, 1 Sep 2021 14:46:58 +0300 Subject: [PATCH] Adding DELUSER list of users support Adding support for ACL help Part of #1546 --- redis/client.py | 1 + redis/commands.py | 10 ++++++++-- tests/test_commands.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/redis/client.py b/redis/client.py index a4d7f6b43a..ff15157f4d 100755 --- a/redis/client.py +++ b/redis/client.py @@ -654,6 +654,7 @@ class Redis(Commands, object): 'ACL DELUSER': int, 'ACL GENPASS': str_if_bytes, 'ACL GETUSER': parse_acl_getuser, + 'ACL HELP': lambda r: list(map(str_if_bytes, r)), 'ACL LIST': lambda r: list(map(str_if_bytes, r)), 'ACL LOAD': bool_ok, 'ACL LOG': parse_acl_log, diff --git a/redis/commands.py b/redis/commands.py index 42307799de..79f80a7f41 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -48,9 +48,9 @@ def acl_cat(self, category=None): pieces = [category] if category else [] return self.execute_command('ACL CAT', *pieces) - def acl_deluser(self, username): + def acl_deluser(self, *username): "Delete the ACL for the specified ``username``" - return self.execute_command('ACL DELUSER', username) + return self.execute_command('ACL DELUSER', *username) def acl_genpass(self): "Generate a random password value" @@ -64,6 +64,12 @@ def acl_getuser(self, username): """ return self.execute_command('ACL GETUSER', username) + def acl_help(self): + """The ACL HELP command returns helpful text describing + the different subcommands. + """ + return self.execute_command('ACL HELP') + def acl_list(self): "Return a list of all ACLs on the server" return self.execute_command('ACL LIST') diff --git a/tests/test_commands.py b/tests/test_commands.py index d77a01c29a..e1bcc63b99 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -93,6 +93,17 @@ def teardown(): assert r.acl_setuser(username, enabled=False, reset=True) assert r.acl_deluser(username) == 1 + # now, a group of users + users = ['bogususer_%d' % r for r in range(0, 5)] + for u in users: + r.acl_setuser(u, enabled=False, reset=True) + assert r.acl_deluser(*users) > 1 + assert r.acl_getuser(users[0]) is None + assert r.acl_getuser(users[1]) is None + assert r.acl_getuser(users[2]) is None + assert r.acl_getuser(users[3]) is None + assert r.acl_getuser(users[4]) is None + @skip_if_server_version_lt(REDIS_6_VERSION) def test_acl_genpass(self, r): password = r.acl_genpass() @@ -185,6 +196,12 @@ def teardown(): hashed_passwords=['-' + hashed_password]) assert len(r.acl_getuser(username)['passwords']) == 1 + @skip_if_server_version_lt(REDIS_6_VERSION) + def test_acl_help(self, r): + res = r.acl_help() + assert isinstance(res, list) + assert len(res) != 0 + @skip_if_server_version_lt(REDIS_6_VERSION) def test_acl_list(self, r, request): username = 'redis-py-user'