Skip to content

Commit

Permalink
Ensure no empty sentinels list is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed May 16, 2024
1 parent 461a712 commit 9f85a48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/3scale/backend/storage_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def cfg_sentinels_handler(options)
role = options.delete :role
sentinels = options.delete :sentinels
# The Redis client can't accept empty string or array of :sentinels
return options if sentinels.nil? || sentinels.empty?
return options if sentinels.to_s.strip.empty? || sentinels.empty?

sentinels = Splitter.split(sentinels) if sentinels.is_a? String

options[:sentinels] = sentinels.map do |sentinel|
sentinels = sentinels.map do |sentinel|
if sentinel.is_a? Hash
next if sentinel.empty?
sentinel.fetch(:host) do
Expand All @@ -233,6 +233,10 @@ def cfg_sentinels_handler(options)
end
end.compact

return options if sentinels.empty?

options[:sentinels] = sentinels

# For the sentinels that do not have the :port key or
# the port key is nil we configure them with the default
# sentinel port
Expand Down
2 changes: 1 addition & 1 deletion test/unit/storage_async_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_role_empty_when_sentinels_does_not_exist
end

def test_sentinels_empty
['', []].each do |sentinels_val|
[nil, '', ' ', [], [nil], [''], [' '], [{}]].each do |sentinels_val|
config_obj = {
url: 'redis://master-group-name',
sentinels: sentinels_val
Expand Down
2 changes: 1 addition & 1 deletion test/unit/storage_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_role_empty_when_sentinels_does_not_exist
end

def test_sentinels_empty
['', []].each do |sentinels_val|
[nil, '', ' ', [], [nil], [''], [' '], [{}]].each do |sentinels_val|
config_obj = {
url: 'redis://master-group-name',
sentinels: sentinels_val
Expand Down

0 comments on commit 9f85a48

Please sign in to comment.