Skip to content

Adding DELUSER list of users support #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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')
Expand Down
17 changes: 17 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'
Expand Down