diff --git a/files/gitlab-cookbooks/gitlab/libraries/redis_helper.rb b/files/gitlab-cookbooks/gitlab/libraries/redis_helper.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3JlZGlzX2hlbHBlci5yYg==..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3JlZGlzX2hlbHBlci5yYg== 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/redis_helper.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/redis_helper.rb @@ -96,7 +96,7 @@ uri.port = port uri.path = path # In case the password has non-alphanumeric passwords, be sure to encode it - uri.password = CGI.escape(password) if password + uri.password = encode_redis_password(password) if password uri end diff --git a/files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper.rb b/files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL25ld19yZWRpc19oZWxwZXIucmI=..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL25ld19yZWRpc19oZWxwZXIucmI= 100644 --- a/files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper.rb +++ b/files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper.rb @@ -10,7 +10,7 @@ uri.port = port if port uri.path = path if path # In case the password has non-alphanumeric passwords, be sure to encode it - uri.password = CGI.escape(password) if password + uri.password = encode_redis_password(password) if password uri end diff --git a/spec/chef/cookbooks/gitlab/libraries/redis_uri_spec.rb b/spec/chef/cookbooks/gitlab/libraries/redis_uri_spec.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3JlZGlzX3VyaV9zcGVjLnJi..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3JlZGlzX3VyaV9zcGVjLnJi 100644 --- a/spec/chef/cookbooks/gitlab/libraries/redis_uri_spec.rb +++ b/spec/chef/cookbooks/gitlab/libraries/redis_uri_spec.rb @@ -2,6 +2,7 @@ # are the ones we expect require 'spec_helper' +require_relative '../../../../../files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper' RSpec.describe URI::Redis do subject { URI('redis://localhost') } @@ -48,8 +49,8 @@ end context 'with non-alphanumeric password' do - let(:password) { "&onBsidv6#XeKFd}=BDDyRrv" } - let(:escaped) { CGI.escape(password) } + let(:password) { "&onBsidv6# XeKFd}=BDDyRrv" } + let(:escaped) { NewRedisHelper.encode_redis_password(password) } it 'rejects unencoded passwords' do expect { subject.password = password }.to raise_error(URI::InvalidComponentError) diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg==..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb @@ -267,7 +267,7 @@ redis_host: 'redis.example.com', redis_port: 8888, redis_database: 2, - redis_password: 'mypass', + redis_password: 'my pass', redis_enable_client: false } ) @@ -276,10 +276,10 @@ it 'creates the config file with custom host, port, password and database' do expect(chef_run).to create_templatesymlink('Create a resque.yml and create a symlink to Rails root').with_variables( hash_including( - redis_url: URI('redis://:mypass@redis.example.com:8888/2'), + redis_url: URI('redis://:my%20pass@redis.example.com:8888/2'), redis_sentinels: [], redis_enable_client: false ) ) expect(chef_run).to render_file(config_file).with_content { |content| @@ -280,10 +280,10 @@ redis_sentinels: [], redis_enable_client: false ) ) expect(chef_run).to render_file(config_file).with_content { |content| - expect(content).to match(%r(url: redis://:mypass@redis.example.com:8888/2)) + expect(content).to match(%r(url: redis://:my%20pass@redis.example.com:8888/2)) expect(content).to match(/id:$/) } end @@ -291,10 +291,10 @@ it 'creates cable.yml with custom host, port, password and database' do expect(chef_run).to create_templatesymlink('Create a cable.yml and create a symlink to Rails root').with_variables( hash_including( - redis_url: URI('redis://:mypass@redis.example.com:8888/2'), + redis_url: URI('redis://:my%20pass@redis.example.com:8888/2'), redis_sentinels: [], redis_enable_client: false ) ) expect(chef_run).to render_file(config_file).with_content { |content| @@ -295,10 +295,10 @@ redis_sentinels: [], redis_enable_client: false ) ) expect(chef_run).to render_file(config_file).with_content { |content| - expect(content).to match(%r(url: redis://:mypass@redis.example.com:8888/2)) + expect(content).to match(%r(url: redis://:my%20pass@redis.example.com:8888/2)) expect(content).to match(/id:$/) } end diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-workhorse_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-workhorse_spec.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItd29ya2hvcnNlX3NwZWMucmI=..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItd29ya2hvcnNlX3NwZWMucmI= 100644 --- a/spec/chef/cookbooks/gitlab/recipes/gitlab-workhorse_spec.rb +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-workhorse_spec.rb @@ -620,7 +620,7 @@ end it 'should generate config file with the specified values' do - content = 'Sentinel = ["redis://:some+pass@127.0.0.1:26379","redis://:some+pass@127.0.8.1:12345"]' + content = 'Sentinel = ["redis://:some%20pass@127.0.0.1:26379","redis://:some%20pass@127.0.8.1:12345"]' content_sentinel_master = 'SentinelMaster = "examplemaster"' content_password = 'Password = "examplepassword"' content_sentinel_password = 'SentinelPassword = "some pass"' @@ -686,7 +686,7 @@ end it 'should generate config file with the specified values' do - content = 'Sentinel = ["redis://:some+workhorse+pass@127.0.0.2:26379","redis://:some+workhorse+pass@127.0.8.2:12345"]' + content = 'Sentinel = ["redis://:some%20workhorse%20pass@127.0.0.2:26379","redis://:some%20workhorse%20pass@127.0.8.2:12345"]' content_sentinel_master = 'SentinelMaster = "worhorse.master"' content_sentinel_password = 'Password = "some workhorse pass"' content_url = 'URL =' diff --git a/spec/chef/cookbooks/package/libraries/new_redis_helper/gitlab_workhorse_spec.rb b/spec/chef/cookbooks/package/libraries/new_redis_helper/gitlab_workhorse_spec.rb index 0a1e6d56ce706a23803d8d061ba3c7042eaecbd4_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9uZXdfcmVkaXNfaGVscGVyL2dpdGxhYl93b3JraG9yc2Vfc3BlYy5yYg==..191ff5a0879a5f4c29dc1a3cdf47a95f8c164ea8_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9uZXdfcmVkaXNfaGVscGVyL2dpdGxhYl93b3JraG9yc2Vfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/package/libraries/new_redis_helper/gitlab_workhorse_spec.rb +++ b/spec/chef/cookbooks/package/libraries/new_redis_helper/gitlab_workhorse_spec.rb @@ -46,6 +46,26 @@ end end + context 'when password set with a space' do + before do + stub_gitlab_rb( + gitlab_rails: { + redis_password: 'redis password' + } + ) + end + + it 'ensures the password is encoded with %20' do + expect(subject.redis_params).to eq( + url: 'unix://:redis%20password@/var/opt/gitlab/redis/redis.socket', + password: 'redis password', + sentinels: [], + sentinelMaster: 'gitlab-redis', + sentinelPassword: nil + ) + end + end + context 'when settings specified via gitlab_rails' do before do stub_gitlab_rb(