Skip to content

Commit

Permalink
When empty config values are provided for http_proxy, https_proxy or …
Browse files Browse the repository at this point in the history
…ftp_proxy do not export environment values for those keys.

Provides a mechanism to prevent local proxy environment settings from being pushed to the test node

Fixes #934
  • Loading branch information
tacchino committed Feb 7, 2016
1 parent 2394371 commit 2b65e37
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/kitchen/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,19 @@ def validate_config!
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def wrap_shell_code(code)
env = []
if config[:http_proxy]
if config[:http_proxy] && !config[:http_proxy].empty?
env << shell_env_var("http_proxy", config[:http_proxy])
env << shell_env_var("HTTP_PROXY", config[:http_proxy])
else
export_proxy(env, "http")
end
if config[:https_proxy]
if config[:https_proxy] && !config[:https_proxy].empty?
env << shell_env_var("https_proxy", config[:https_proxy])
env << shell_env_var("HTTPS_PROXY", config[:https_proxy])
else
export_proxy(env, "https")
end
if config[:ftp_proxy]
if config[:ftp_proxy] && !config[:ftp_proxy].empty?
env << shell_env_var("ftp_proxy", config[:ftp_proxy])
env << shell_env_var("FTP_PROXY", config[:ftp_proxy])
else
Expand Down
33 changes: 33 additions & 0 deletions spec/kitchen/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,28 @@ class SubclassDefaults < StaticDefaults
CODE
end

it "does not export http_proxy or HTTP_PROXY when :http_proxy is empty" do
config[:http_proxy] = ''

cmd.must_equal(outdent!(<<-CODE.chomp))
sh -c '
mkdir foo
'
CODE
end

it "does not export https_proxy or HTTPS_PROXY when :https_proxy is empty" do
config[:https_proxy] = ''

cmd.must_equal(outdent!(<<-CODE.chomp))
sh -c '
mkdir foo
'
CODE
end

it "exports ftp_proxy & FTP_PROXY from workstation when :ftp_proxy isn't set" do
ENV["ftp_proxy"] = "ftp://proxy"
ENV["FTP_PROXY"] = "ftp://proxy"
Expand All @@ -846,6 +868,17 @@ class SubclassDefaults < StaticDefaults
CODE
end

it "does not export ftp_proxy or FTP_PROXY when :ftp_proxy is empty" do
config[:ftp_proxy] = ''

cmd.must_equal(outdent!(<<-CODE.chomp))
sh -c '
mkdir foo
'
CODE
end

it "exports no_proxy & NO_PROXY from workstation when http_proxy is set from workstation" do
ENV["http_proxy"] = "http://proxy"
ENV["HTTP_PROXY"] = "http://proxy"
Expand Down

0 comments on commit 2b65e37

Please sign in to comment.