chore: Ability to Remove password info from sentinel config (#4550)
Introduce the REDIS_SENTINEL_PASSWORD environment variable to customize the behaviour of sentinel passwords. Co-authored-by: EXT02D22861 <nusret.ozates@consultant.turkcell.com.tr> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -7,11 +7,9 @@ describe ::Redis::Config do
|
||||
|
||||
before do
|
||||
described_class.instance_variable_set(:@config, nil)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_URL', 'redis://127.0.0.1:6379').and_return(redis_url)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_PASSWORD', nil).and_return(redis_pasword)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_SENTINELS', nil).and_return('')
|
||||
allow(ENV).to receive(:fetch).with('REDIS_SENTINEL_MASTER_NAME', 'mymaster').and_return('')
|
||||
described_class.config
|
||||
with_modified_env REDIS_URL: redis_url, REDIS_PASSWORD: redis_pasword, REDIS_SENTINELS: '', REDIS_SENTINEL_MASTER_NAME: '' do
|
||||
described_class.config
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks for app redis config' do
|
||||
@@ -38,11 +36,10 @@ describe ::Redis::Config do
|
||||
|
||||
before do
|
||||
described_class.instance_variable_set(:@config, nil)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_URL', 'redis://127.0.0.1:6379').and_return(redis_url)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_PASSWORD', nil).and_return(redis_pasword)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_SENTINELS', nil).and_return(redis_sentinels)
|
||||
allow(ENV).to receive(:fetch).with('REDIS_SENTINEL_MASTER_NAME', 'mymaster').and_return(redis_master_name)
|
||||
described_class.config
|
||||
with_modified_env REDIS_URL: redis_url, REDIS_PASSWORD: redis_pasword, REDIS_SENTINELS: redis_sentinels,
|
||||
REDIS_SENTINEL_MASTER_NAME: redis_master_name do
|
||||
described_class.config
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks for app redis config' do
|
||||
@@ -50,5 +47,41 @@ describe ::Redis::Config do
|
||||
expect(described_class.app[:url]).to eq("redis://#{redis_master_name}")
|
||||
expect(described_class.app[:sentinels]).to match_array(expected_sentinels)
|
||||
end
|
||||
|
||||
context 'when redis sentinel is used with REDIS_SENTINEL_PASSWORD empty string' do
|
||||
let(:redis_sentinel_password) { '' }
|
||||
|
||||
before do
|
||||
described_class.instance_variable_set(:@config, nil)
|
||||
with_modified_env REDIS_URL: redis_url, REDIS_PASSWORD: redis_pasword, REDIS_SENTINELS: redis_sentinels,
|
||||
REDIS_SENTINEL_MASTER_NAME: redis_master_name, REDIS_SENTINEL_PASSWORD: redis_sentinel_password do
|
||||
described_class.config
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks for app redis config and sentinel passwords will be empty' do
|
||||
expect(described_class.app.keys).to match_array([:url, :password, :sentinels, :network_timeout, :reconnect_attempts, :ssl_params])
|
||||
expect(described_class.app[:url]).to eq("redis://#{redis_master_name}")
|
||||
expect(described_class.app[:sentinels]).to match_array(expected_sentinels.map { |s| s.except(:password) })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when redis sentinel is used with REDIS_SENTINEL_PASSWORD' do
|
||||
let(:redis_sentinel_password) { 'sentinel_password' }
|
||||
|
||||
before do
|
||||
described_class.instance_variable_set(:@config, nil)
|
||||
with_modified_env REDIS_URL: redis_url, REDIS_PASSWORD: redis_pasword, REDIS_SENTINELS: redis_sentinels,
|
||||
REDIS_SENTINEL_MASTER_NAME: redis_master_name, REDIS_SENTINEL_PASSWORD: redis_sentinel_password do
|
||||
described_class.config
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks for app redis config and redis password is replaced in sentinel config' do
|
||||
expect(described_class.app.keys).to match_array([:url, :password, :sentinels, :network_timeout, :reconnect_attempts, :ssl_params])
|
||||
expect(described_class.app[:url]).to eq("redis://#{redis_master_name}")
|
||||
expect(described_class.app[:sentinels]).to match_array(expected_sentinels.map { |s| s.merge(password: redis_sentinel_password) })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user