Skip to content
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

Fix incorrect return statement in auth (#2086) #2092

Merged
merged 1 commit into from
Apr 27, 2022
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 CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ def auth(self, password, username=None, **kwargs):
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.
Expand Down
14 changes: 14 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,23 @@ def test_case_insensitive_command_names(self, r):
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)
Expand Down