Skip to content
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
7 changes: 6 additions & 1 deletion lib/redis_client/sentinel_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def initialize(
raise ArgumentError, "Expected role to be either :master or :replica, got: #{role.inspect}"
end

# Track whether SSL was explicitly provided by user
ssl_explicitly_set = client_config.key?(:ssl)

if url
url_config = URLConfig.new(url)
client_config = {
Expand Down Expand Up @@ -68,7 +71,9 @@ def initialize(
client_config[:reconnect_attempts] ||= DEFAULT_RECONNECT_ATTEMPTS
@client_config = client_config || {}
@sentinel_client_config = @client_config.dup
@sentinel_client_config.delete(:ssl)
# Only remove SSL from sentinel config if it was derived from URL,
# not if explicitly set by user.
@sentinel_client_config.delete(:ssl) unless ssl_explicitly_set
super(**client_config)
@sentinel_configs = sentinels_to_configs(sentinels)
end
Expand Down
18 changes: 18 additions & 0 deletions test/sentinel/sentinel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ def test_config_ssl_from_rediss_url
end
end

def test_explicit_ssl_option_overrides_url
sentinel_client_mock = SentinelClientMock.new([
[["SENTINEL", "get-master-addr-by-name", "cache"], [Servers::REDIS.host, Servers::REDIS.port.to_s]],
sentinel_refresh_command_mock,
])

# Passing ssl: true should enable SSL for both Redis and Sentinel configs
config = new_config(ssl: true)

stub(config, :sentinel_client, ->(_config) { sentinel_client_mock }) do
assert_predicate config, :ssl?, "Expected Redis config to use SSL when explicitly passed"

config.sentinels.each do |sentinel|
assert_predicate sentinel, :ssl?, "Expected Sentinel config to use SSL when explicitly passed"
end
end
end

def test_sentinel_shared_username_password
config = new_config(sentinel_username: "alice", sentinel_password: "superpassword")

Expand Down