diff options
author | Kamyab Taghizadeh <kamyab.zad@gmail.com> | 2022-04-28 04:06:05 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 02:36:05 +0300 |
commit | cfebc0fa9c4f7e4ef141729959cd149861cfd706 (patch) | |
tree | 535b63b5538df5b221b86c4b2aac93a8ac91eff4 | |
parent | 1f046ac23502521dad280a49ff31263b2e92f4b3 (diff) | |
download | redis-py-cfebc0fa9c4f7e4ef141729959cd149861cfd706.tar.gz |
Fix incorrect return statement in auth (#2086) (#2092)
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | redis/commands/core.py | 8 | ||||
-rw-r--r-- | tests/test_commands.py | 14 |
3 files changed, 20 insertions, 3 deletions
@@ -7,6 +7,7 @@ * Fix scan_iter for RedisCluster * Remove verbose logging when initializing ClusterPubSub, ClusterPipeline or RedisCluster * Fix broken connection writer lock-up for asyncio (#2065) + * Fix auth bug when provided with no username (#2086) * 4.1.3 (Feb 8, 2022) * Fix flushdb and flushall (#1926) diff --git a/redis/commands/core.py b/redis/commands/core.py index fd6ad46..30102eb 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -376,9 +376,11 @@ class ManagementCommands(CommandsProtocol): authenticate for the given user. For more information see https://redis.io/commands/auth """ - if username: - return self.execute_command("AUTH", username, password, **kwargs) - return self.execute_command + pieces = [] + if username is not None: + pieces.append(username) + pieces.append(password) + return self.execute_command("AUTH", *pieces, **kwargs) 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 64fd87c..c8edd57 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -67,9 +67,23 @@ class TestResponseCallbacks: class TestRedisCommands: @skip_if_redis_enterprise() def test_auth(self, r, request): + # first, test for default user (`username` is supposed to be optional) + default_username = "default" + temp_pass = "temp_pass" + r.config_set("requirepass", temp_pass) + + assert r.auth(temp_pass, default_username) is True + assert r.auth(temp_pass) is True + + # test for other users username = "redis-py-auth" def teardown(): + try: + r.auth(temp_pass) + except exceptions.ResponseError: + r.auth("default", "") + r.config_set("requirepass", "") r.acl_deluser(username) request.addfinalizer(teardown) |