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

Handle a blank value for the http_proxy host #18073

Merged
merged 1 commit into from
Oct 10, 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/vmdb/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Util
def self.http_proxy_uri(proxy_config = :default)
proxy = ::Settings.http_proxy[proxy_config].to_hash
proxy = ::Settings.http_proxy.to_hash unless proxy[:host]
return nil unless proxy[:host]
return nil if proxy[:host].blank?

user = proxy.delete(:user)
user &&= CGI.escape(user)
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/vmdb/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
expect(described_class.http_proxy_uri).to be_nil
end

it "with a blank host" do
# We couldn't save nil http_proxy host, so some host values will be ''
stub_settings_merge(:http_proxy => {:default => {:host => ''}})
expect(described_class.http_proxy_uri).to be_nil
end

it "with host" do
stub_settings_merge(:http_proxy => {:default => {:host => "1.2.3.4", :port => nil, :user => nil, :password => nil}})
expect(described_class.http_proxy_uri).to eq(URI::Generic.build(:scheme => "http", :host => "1.2.3.4"))
Expand Down