summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Morrow <jon@morrowmail.com>2015-05-12 13:57:47 -0700
committerJon Morrow <jon@morrowmail.com>2015-05-12 13:57:47 -0700
commita5b0ff07093dd52c1c57b84463ed0e4739285fe8 (patch)
treec5cbb0e4e34dfd6a472ef44c9019a58b546e8b8b
parent82ecd970d184734df63580290964f4b8f9672b21 (diff)
parent7bb5560abbd579820a26ff43d0bfec336f4b9a2f (diff)
downloadchef-a5b0ff07093dd52c1c57b84463ed0e4739285fe8.tar.gz
Merge pull request #3342 from chef/fix-empty-proxy
Check if proxy env_var is empty
-rw-r--r--lib/chef/http/basic_client.rb16
-rw-r--r--spec/unit/http/basic_client_spec.rb16
2 files changed, 26 insertions, 6 deletions
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index 076d152d16..de5e7c03a8 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -101,12 +101,16 @@ class Chef
env["#{url.scheme.upcase}_PROXY"] || env["#{url.scheme}_proxy"]
# Check if the proxy string contains a scheme. If not, add the url's scheme to the
- # proxy before parsing. The regex /^.*:\/\// matches, for example, http://.
- proxy = if proxy.match(/^.*:\/\//)
- URI.parse(proxy)
- else
- URI.parse("#{url.scheme}://#{proxy}")
- end if String === proxy
+ # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy
+ # here since we are really just trying to get the string built correctly.
+ if String === proxy && !proxy.strip.empty?
+ if proxy.match(/^.*:\/\//)
+ proxy = URI.parse(proxy.strip)
+ else
+ proxy = URI.parse("#{url.scheme}://#{proxy.strip}")
+ end
+ end
+
no_proxy = Chef::Config[:no_proxy] || env['NO_PROXY'] || env['no_proxy']
excludes = no_proxy.to_s.split(/\s*,\s*/).compact
excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
diff --git a/spec/unit/http/basic_client_spec.rb b/spec/unit/http/basic_client_spec.rb
index 32b32a5f4c..b7552f54aa 100644
--- a/spec/unit/http/basic_client_spec.rb
+++ b/spec/unit/http/basic_client_spec.rb
@@ -109,5 +109,21 @@ describe "HTTP Connection" do
end
end
+
+ context "when an empty proxy is set by the environment" do
+ let(:env) do
+ {
+ "https_proxy" => ""
+ }
+ end
+
+ before do
+ allow(subject).to receive(:env).and_return(env)
+ end
+
+ it "to not fail with URI parse exception" do
+ expect { subject.proxy_uri }.to_not raise_error
+ end
+ end
end
end