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

Allow nil password and www_form_encoded_password to work together. #297

Merged
merged 1 commit into from
May 8, 2018
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
2 changes: 1 addition & 1 deletion lib/train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def self.target_config(config = nil) # rubocop:disable Metrics/AbcSize
conf[:user] ||= uri.user
conf[:path] ||= uri.path
conf[:password] ||=
if conf[:www_form_encoded_password]
if conf[:www_form_encoded_password] && !uri.password.nil?
URI.decode_www_form_component(uri.password)
else
uri.password
Expand Down
12 changes: 12 additions & 0 deletions test/unit/train_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@
res[:target].must_equal org[:target]
end

it 'ignores www-form-encoded password value when there is no password' do
org = { target: "mock://username@1.2.3.4:100",
www_form_encoded_password: true}
res = Train.target_config(org)
res[:backend].must_equal 'mock'
res[:host].must_equal '1.2.3.4'
res[:user].must_equal 'username'
res[:password].must_be_nil
res[:port].must_equal 100
res[:target].must_equal org[:target]
end

it 'it raises UserError on invalid URIs' do
org = { target: 'mock world' }
proc { Train.target_config(org) }.must_raise Train::UserError
Expand Down