diff options
author | Nathan L Smith <smith@chef.io> | 2015-12-11 15:23:06 -0600 |
---|---|---|
committer | Nathan L Smith <smith@chef.io> | 2015-12-11 15:23:06 -0600 |
commit | 5188bfb251daf307e3b1cead6d1c3f5a449302d5 (patch) | |
tree | 17e72d2715e69387ffdc97216224a1ff1ee4566b | |
parent | a8c2fb3e7e30fae882693253fd699f2b1bab185c (diff) | |
download | chef-nls/ftp-proxy.tar.gz |
Honor ftp_proxy environment variables in remote_filenls/ftp-proxy
Fixes #4216.
-rw-r--r-- | lib/chef/provider/remote_file/ftp.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/remote_file/ftp_spec.rb | 48 |
2 files changed, 48 insertions, 2 deletions
diff --git a/lib/chef/provider/remote_file/ftp.rb b/lib/chef/provider/remote_file/ftp.rb index 3f78286aa3..c5fa9d6e29 100644 --- a/lib/chef/provider/remote_file/ftp.rb +++ b/lib/chef/provider/remote_file/ftp.rb @@ -148,7 +148,7 @@ class Chef #adapted from buildr/lib/buildr/core/transports.rb via chef/rest/rest_client.rb def proxy_uri(uri) - proxy = Chef::Config["ftp_proxy"] + proxy = Chef::Config["ftp_proxy"] || ENV["ftp_proxy"] || ENV["FTP_PROXY"] proxy = URI.parse(proxy) if String === proxy if Chef::Config["ftp_proxy_user"] proxy.user = Chef::Config["ftp_proxy_user"] diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index dbbddd8e84..609dfbb7d8 100644 --- a/spec/unit/provider/remote_file/ftp_spec.rb +++ b/spec/unit/provider/remote_file/ftp_spec.rb @@ -198,7 +198,7 @@ describe Chef::Provider::RemoteFile::FTP do end - context "and proxying is enabled" do + context "when proxying is enabled via Chef::Config" do before do Chef::Config[:ftp_proxy] = "socks5://socks.example.com:5000" Chef::Config[:ftp_proxy_user] = "bill" @@ -215,5 +215,51 @@ describe Chef::Provider::RemoteFile::FTP do end + context "when proxying is enabled via environment variables" do + before :each do + allow(ENV).to receive(:[]).with("SOCKS_SERVER") + allow(ENV).to receive(:[]).with("TMPDIR") + allow(ENV).to receive(:[]).with("TMP") + allow(ENV).to receive(:[]).with("TEMP") + allow(ENV).to receive(:[]).with("ftp_proxy").and_return( + "socks5://bill:ted@socks.example.com:5000" + ) + allow(ENV).to receive(:[]).with("FTP_PROXY") + end + + context "when lowercase" do + before :each do + allow(ENV).to receive(:[]).with("ftp_proxy").and_return( + "socks5://bill:ted@socks.example.com:5000" + ) + allow(ENV).to receive(:[]).with("FTP_PROXY") + end + + it "fetches the file via the proxy" do + current_socks_server = ENV["SOCKS_SERVER"] + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", "socks5://bill:ted@socks.example.com:5000").ordered + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", current_socks_server).ordered + result = fetcher.fetch + expect(result).to equal(tempfile) + end + end + + context "when uppercase" do + before :each do + allow(ENV).to receive(:[]).with("ftp_proxy") + allow(ENV).to receive(:[]).with("FTP_PROXY").and_return( + "socks5://bill:ted@socks.example.com:5000" + ) + end + + it "fetches the file via the proxy" do + current_socks_server = ENV["SOCKS_SERVER"] + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", "socks5://bill:ted@socks.example.com:5000").ordered + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", current_socks_server).ordered + result = fetcher.fetch + expect(result).to equal(tempfile) + end + end + end end end |