summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2015-12-08 17:02:23 -0700
committertyler-ball <tyleraball@gmail.com>2015-12-09 14:23:54 -0700
commit85d0407a16fa4dfc479d550a96355a6d11f4f551 (patch)
tree5be428017e0883fdcaa19c74308bb73783270071 /spec/unit
parent200c3e5b71ec269efffbfb97e94f1a7aada951af (diff)
downloadchef-85d0407a16fa4dfc479d550a96355a6d11f4f551.tar.gz
Moving the proxy export to environment varibles into Chef::Config
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/application_spec.rb182
-rw-r--r--spec/unit/mixin/proxified_socket_spec.rb4
2 files changed, 5 insertions, 181 deletions
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index f5a2c72aa0..20b7e3a506 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -39,7 +39,6 @@ describe Chef::Application do
@app = Chef::Application.new
allow(@app).to receive(:configure_chef).and_return(true)
allow(@app).to receive(:configure_logging).and_return(true)
- allow(@app).to receive(:configure_proxy_environment_variables).and_return(true)
end
it "should configure chef" do
@@ -52,11 +51,6 @@ describe Chef::Application do
@app.reconfigure
end
- it "should configure environment variables" do
- expect(@app).to receive(:configure_proxy_environment_variables).and_return(true)
- @app.reconfigure
- end
-
it 'should not receive set_specific_recipes' do
expect(@app).to_not receive(:set_specific_recipes)
@app.reconfigure
@@ -101,6 +95,7 @@ describe Chef::Application do
@app = Chef::Application.new
#Chef::Config.stub(:merge!).and_return(true)
allow(@app).to receive(:parse_options).and_return(true)
+ expect(Chef::Config).to receive(:export_proxies).and_return(true)
end
it "should parse the commandline options" do
@@ -245,181 +240,6 @@ describe Chef::Application do
end
end
- describe "when configuring environment variables" do
- def configure_proxy_environment_variables_stubs
- allow(@app).to receive(:configure_http_proxy).and_return(true)
- allow(@app).to receive(:configure_https_proxy).and_return(true)
- allow(@app).to receive(:configure_ftp_proxy).and_return(true)
- allow(@app).to receive(:configure_no_proxy).and_return(true)
- end
-
- shared_examples_for "setting ENV['http_proxy']" do
- before do
- Chef::Config[:http_proxy] = http_proxy
- end
-
- it "should set ENV['http_proxy']" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://#{address}:#{port}")
- end
-
- it "should set ENV['HTTP_PROXY']" do
- @app.configure_proxy_environment_variables
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://#{address}:#{port}")
- end
-
- describe "when Chef::Config[:http_proxy_user] is set" do
- before do
- Chef::Config[:http_proxy_user] = "username"
- end
-
- it "should set ENV['http_proxy'] with the username" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://username@#{address}:#{port}")
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username@#{address}:#{port}")
- end
-
- context "when :http_proxy_user contains '@' and/or ':'" do
- before do
- Chef::Config[:http_proxy_user] = "my:usern@me"
- end
-
- it "should set ENV['http_proxy'] with the escaped username" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://my%3Ausern%40me@#{address}:#{port}")
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://my%3Ausern%40me@#{address}:#{port}")
- end
- end
-
- describe "when Chef::Config[:http_proxy_pass] is set" do
- before do
- Chef::Config[:http_proxy_pass] = "password"
- end
-
- it "should set ENV['http_proxy'] with the password" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://username:password@#{address}:#{port}")
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username:password@#{address}:#{port}")
- end
-
- context "when :http_proxy_pass contains '@' and/or ':'" do
- before do
- Chef::Config[:http_proxy_pass] = ":P@ssword101"
- end
-
- it "should set ENV['http_proxy'] with the escaped password" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://username:%3AP%40ssword101@#{address}:#{port}")
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username:%3AP%40ssword101@#{address}:#{port}")
- end
- end
- end
- end
-
- describe "when Chef::Config[:http_proxy_pass] is set (but not Chef::Config[:http_proxy_user])" do
- before do
- Chef::Config[:http_proxy_user] = nil
- Chef::Config[:http_proxy_pass] = "password"
- end
-
- it "should set ENV['http_proxy']" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq("#{scheme}://#{address}:#{port}")
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://#{address}:#{port}")
- end
- end
- end
-
- describe "when configuring ENV['http_proxy']" do
- before do
- @env = {}
- allow(@app).to receive(:env).and_return(@env)
-
- allow(@app).to receive(:configure_https_proxy).and_return(true)
- allow(@app).to receive(:configure_ftp_proxy).and_return(true)
- allow(@app).to receive(:configure_no_proxy).and_return(true)
- end
-
- describe "when Chef::Config[:http_proxy] is not set" do
- before do
- Chef::Config[:http_proxy] = nil
- end
-
- it "should not set ENV['http_proxy']" do
- @app.configure_proxy_environment_variables
- expect(@env).to eq({})
- end
- end
-
- describe "when Chef::Config[:http_proxy] is set" do
- context "when given an FQDN" do
- let(:scheme) { "http" }
- let(:address) { "proxy.example.org" }
- let(:port) { 8080 }
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
-
- it_should_behave_like "setting ENV['http_proxy']"
- end
-
- context "when given an HTTPS URL" do
- let(:scheme) { "https" }
- let(:address) { "proxy.example.org" }
- let(:port) { 8080 }
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
-
- it_should_behave_like "setting ENV['http_proxy']"
- end
-
- context "when given an IP" do
- let(:scheme) { "http" }
- let(:address) { "127.0.0.1" }
- let(:port) { 22 }
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
-
- it_should_behave_like "setting ENV['http_proxy']"
- end
-
- context "when given an IPv6" do
- let(:scheme) { "http" }
- let(:address) { "[2001:db8::1]" }
- let(:port) { 80 }
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
-
- it_should_behave_like "setting ENV['http_proxy']"
- end
-
- context "when given without including http://" do
- let(:scheme) { "http" }
- let(:address) { "proxy.example.org" }
- let(:port) { 8181 }
- let(:http_proxy) { "#{address}:#{port}" }
-
- it_should_behave_like "setting ENV['http_proxy']"
- end
-
- context "when given the full proxy in :http_proxy only" do
- before do
- Chef::Config[:http_proxy] = "http://username:password@proxy.example.org:2222"
- Chef::Config[:http_proxy_user] = nil
- Chef::Config[:http_proxy_pass] = nil
- end
-
- it "should set ENV['http_proxy']" do
- @app.configure_proxy_environment_variables
- expect(@env['http_proxy']).to eq(Chef::Config[:http_proxy])
- end
- end
-
- context "when the config options aren't URI compliant" do
- it "raises Chef::Exceptions::BadProxyURI" do
- Chef::Config[:http_proxy] = "http://proxy.bad_example.org/:8080"
- expect { @app.configure_proxy_environment_variables }.to raise_error(Chef::Exceptions::BadProxyURI)
- end
- end
- end
- end
- end
-
describe "class method: fatal!" do
before do
allow(STDERR).to receive(:puts).with("FATAL: blah").and_return(true)
diff --git a/spec/unit/mixin/proxified_socket_spec.rb b/spec/unit/mixin/proxified_socket_spec.rb
index d999d09235..88f71ae48b 100644
--- a/spec/unit/mixin/proxified_socket_spec.rb
+++ b/spec/unit/mixin/proxified_socket_spec.rb
@@ -61,6 +61,8 @@ describe Chef::Mixin::ProxifiedSocket do
context "when https_proxy is set" do
before do
+ # I'm purposefully setting both of these because we prefer the https
+ # variable
ENV['https_proxy'] = https_uri
ENV['http_proxy'] = http_uri
end
@@ -69,6 +71,8 @@ describe Chef::Mixin::ProxifiedSocket do
include_examples "proxified socket"
context "when no_proxy is set" do
+ # This is testing that no_proxy is also provided to Proxified
+ # when it is set
before do
ENV['no_proxy'] = no_proxy_spec
end