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

Restore Redis 4.3.0 accidental AUTH fallback behavior with a deprecation warning #1041

Merged
merged 1 commit into from Oct 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

* Restore the accidential auth behavior of redis-rb 4.3.0 with a warning. If provided with the `default` user password, but a wrong username,
redis-rb will first try to connect as the provided user, but then will fallback to connect as the `default` user with the provided password.
This behavior is deprecated and will be removed in Redis 4.6.0. Fix #1038.

# 4.5.0

* Handle parts of the command using incompatible encodings. See #1037.
Expand Down
10 changes: 10 additions & 0 deletions lib/redis/client.rb
Expand Up @@ -122,6 +122,16 @@ def connect
rescue CommandError => err # Likely on Redis < 6
if err.message.match?(/ERR wrong number of arguments for \'auth\' command/)
call [:auth, password]
elsif err.message.match?(/WRONGPASS invalid username-password pair/)
begin
call [:auth, password]
rescue CommandError
raise err
end
::Kernel.warn(
"[redis-rb] The Redis connection was configured with username #{username.inspect}, but" \
" the provided password was for the default user. This will start failing in redis-rb 4.6."
)
else
raise
end
Expand Down
28 changes: 28 additions & 0 deletions test/connection_test.rb
Expand Up @@ -9,6 +9,34 @@ def test_provides_a_meaningful_inspect
assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
end

def test_connection_with_user_and_password
target_version "6.0" do
with_acl do |username, password|
redis = Redis.new(OPTIONS.merge(username: username, password: password))
assert_equal "PONG", redis.ping
end
end
end

def test_connection_with_default_user_and_password
target_version "6.0" do
with_default_user_password do |_username, password|
redis = Redis.new(OPTIONS.merge(password: password))
assert_equal "PONG", redis.ping
end
end
end

def test_connection_with_wrong_user_and_password
target_version "6.0" do
with_default_user_password do |_username, password|
Kernel.expects(:warn).once
redis = Redis.new(OPTIONS.merge(username: "does-not-exist", password: password))
assert_equal "PONG", redis.ping
end
end
end

def test_connection_information
assert_equal "127.0.0.1", r.connection.fetch(:host)
assert_equal 6381, r.connection.fetch(:port)
Expand Down
10 changes: 10 additions & 0 deletions test/helper.rb
Expand Up @@ -172,9 +172,19 @@ def with_acl
'+ping', '+select', '+command', '+cluster|slots', '+cluster|nodes',
'>mysecret')
yield('johndoe', 'mysecret')
ensure
admin.acl('DELUSER', 'johndoe')
admin.close
end

def with_default_user_password
admin = _new_client
admin.acl('SETUSER', 'default', '>mysecret')
yield('default', 'mysecret')
ensure
admin.acl('SETUSER', 'default', 'nopass')
admin.close
end
end

module Client
Expand Down