Skip to content

Commit cfebc0f

Browse files
authored
Fix incorrect return statement in auth (#2086) (#2092)
1 parent 1f046ac commit cfebc0f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix scan_iter for RedisCluster
88
* Remove verbose logging when initializing ClusterPubSub, ClusterPipeline or RedisCluster
99
* Fix broken connection writer lock-up for asyncio (#2065)
10+
* Fix auth bug when provided with no username (#2086)
1011

1112
* 4.1.3 (Feb 8, 2022)
1213
* Fix flushdb and flushall (#1926)

redis/commands/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,11 @@ def auth(self, password, username=None, **kwargs):
376376
authenticate for the given user.
377377
For more information see https://redis.io/commands/auth
378378
"""
379-
if username:
380-
return self.execute_command("AUTH", username, password, **kwargs)
381-
return self.execute_command
379+
pieces = []
380+
if username is not None:
381+
pieces.append(username)
382+
pieces.append(password)
383+
return self.execute_command("AUTH", *pieces, **kwargs)
382384

383385
def bgrewriteaof(self, **kwargs):
384386
"""Tell the Redis server to rewrite the AOF file from data in memory.

tests/test_commands.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,23 @@ def test_case_insensitive_command_names(self, r):
6767
class TestRedisCommands:
6868
@skip_if_redis_enterprise()
6969
def test_auth(self, r, request):
70+
# first, test for default user (`username` is supposed to be optional)
71+
default_username = "default"
72+
temp_pass = "temp_pass"
73+
r.config_set("requirepass", temp_pass)
74+
75+
assert r.auth(temp_pass, default_username) is True
76+
assert r.auth(temp_pass) is True
77+
78+
# test for other users
7079
username = "redis-py-auth"
7180

7281
def teardown():
82+
try:
83+
r.auth(temp_pass)
84+
except exceptions.ResponseError:
85+
r.auth("default", "")
86+
r.config_set("requirepass", "")
7387
r.acl_deluser(username)
7488

7589
request.addfinalizer(teardown)

0 commit comments

Comments
 (0)