summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordogukanteber <47397379+dogukanteber@users.noreply.github.com>2022-03-02 13:27:12 +0300
committerGitHub <noreply@github.com>2022-03-02 12:27:12 +0200
commitc5d19b8571d2b15a29637f56a51b0da560072945 (patch)
treecd61e1a20bf0779c3aadbee77c8b2b1ab0c79d94
parenta77df17cf3c36444540f6bce793720e1ee06f1c7 (diff)
downloadredis-py-c5d19b8571d2b15a29637f56a51b0da560072945.tar.gz
Add support for AUTH (#1929)
* Add support for AUTH * Fix linter error * test fix * fix test in cluster Co-authored-by: Chayim <chayim@users.noreply.github.com> Co-authored-by: Chayim I. Kirshen <c@kirshen.com> Co-authored-by: dvora-h <dvora.heller@redis.com>
-rw-r--r--redis/cluster.py1
-rw-r--r--redis/commands/core.py14
-rw-r--r--tests/test_commands.py24
3 files changed, 29 insertions, 10 deletions
diff --git a/redis/cluster.py b/redis/cluster.py
index 3b30a6e..4491e29 100644
--- a/redis/cluster.py
+++ b/redis/cluster.py
@@ -228,6 +228,7 @@ class RedisCluster(RedisClusterCommands):
"ACL SETUSER",
"ACL USERS",
"ACL WHOAMI",
+ "AUTH",
"CLIENT LIST",
"CLIENT SETNAME",
"CLIENT GETNAME",
diff --git a/redis/commands/core.py b/redis/commands/core.py
index 44650f2..2937780 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -369,14 +369,16 @@ class ManagementCommands(CommandsProtocol):
Redis management commands
"""
- def auth(self):
+ def auth(self, password, username=None, **kwargs):
"""
- This function throws a NotImplementedError since it is intentionally
- not supported.
+ Authenticates the user. If you do not pass username, Redis will try to
+ authenticate for the "default" user. If you do pass username, it will
+ authenticate for the given user.
+ For more information check https://redis.io/commands/auth
"""
- raise NotImplementedError(
- "AUTH is intentionally not implemented in the client."
- )
+ if username:
+ return self.execute_command("AUTH", username, password, **kwargs)
+ return self.execute_command
def bgrewriteaof(self, **kwargs):
"""Tell the Redis server to rewrite the AOF file from data in memory.
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 5c32d5f..dc10cde 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -65,16 +65,32 @@ class TestResponseCallbacks:
class TestRedisCommands:
+ def test_auth(self, r, request):
+ username = "redis-py-auth"
+
+ def teardown():
+ r.acl_deluser(username)
+
+ request.addfinalizer(teardown)
+
+ assert r.acl_setuser(
+ username,
+ enabled=True,
+ passwords=["+strong_password"],
+ commands=["+acl"],
+ )
+
+ assert r.auth(username=username, password="strong_password") is True
+
+ with pytest.raises(exceptions.ResponseError):
+ r.auth(username=username, password="wrong_password")
+
def test_command_on_invalid_key_type(self, r):
r.lpush("a", "1")
with pytest.raises(redis.ResponseError):
r["a"]
# SERVER INFORMATION
- def test_auth_not_implemented(self, r):
- with pytest.raises(NotImplementedError):
- r.auth()
-
@skip_if_server_version_lt("6.0.0")
def test_acl_cat_no_category(self, r):
categories = r.acl_cat()