From 44f505db760d4af22f50830863c934e00b78cc18 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 10 Oct 2018 10:05:50 -0400 Subject: [PATCH] Merge pull request #18073 from jrafanie/handle_blank_http_proxy_host Handle a blank value for the http_proxy host (cherry picked from commit a17d07e26daeeb1c06e5dd888ee535ae823cbbe9) https://bugzilla.redhat.com/show_bug.cgi?id=1639353 --- lib/vmdb/util.rb | 2 +- spec/lib/vmdb/util_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vmdb/util.rb b/lib/vmdb/util.rb index e0123ca5365..c262c961240 100644 --- a/lib/vmdb/util.rb +++ b/lib/vmdb/util.rb @@ -4,7 +4,7 @@ def self.http_proxy_uri(proxy_config = :default) # TODO: (julian) This looks really messy. Need to make it look nicer. proxy = (::Settings.http_proxy[proxy_config] || ::Settings.http_proxy).to_h - return nil unless proxy[:host] + return nil if proxy[:host].blank? user = proxy.delete(:user) user &&= CGI.escape(user) diff --git a/spec/lib/vmdb/util_spec.rb b/spec/lib/vmdb/util_spec.rb index 2cbde1b5af7..3a7c64e6132 100644 --- a/spec/lib/vmdb/util_spec.rb +++ b/spec/lib/vmdb/util_spec.rb @@ -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(: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"))