Skip to content

Commit 9a1b00f

Browse files
authored
Add support for ACL DRYRUN (#1992)
* Add support for ACL DRYRUN * Fix linter error * Revert "Fix linter error" This reverts commit aa1cf04. * Fix linter error
1 parent c56a758 commit 9a1b00f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

redis/commands/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def acl_cat(self, category=None, **kwargs):
2828
pieces = [category] if category else []
2929
return self.execute_command("ACL CAT", *pieces, **kwargs)
3030

31+
def acl_dryrun(self, username, *args, **kwargs):
32+
"""
33+
Simulate the execution of a given command by a given ``username``.
34+
35+
For more information check https://redis.io/commands/acl-dryrun
36+
"""
37+
return self.execute_command("ACL DRYRUN", username, *args, **kwargs)
38+
3139
def acl_deluser(self, *username, **kwargs):
3240
"""
3341
Delete the ACL for the specified ``username``s

tests/test_commands.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ def test_acl_cat_with_category(self, r):
8787
assert isinstance(commands, list)
8888
assert "get" in commands
8989

90+
@skip_if_server_version_lt("7.0.0")
91+
def test_acl_dryrun(self, r):
92+
username = "redis-py-user"
93+
r.acl_setuser(
94+
username,
95+
keys=["*"],
96+
commands=["+set"],
97+
)
98+
assert r.acl_dryrun(username, "set", "key", "value") == b"OK"
99+
assert r.acl_dryrun(username, "get", "key").startswith(
100+
b"This user has no permissions to run the"
101+
)
102+
90103
@skip_if_server_version_lt("6.0.0")
91104
@skip_if_redis_enterprise()
92105
def test_acl_deluser(self, r, request):

0 commit comments

Comments
 (0)