summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-06-02 14:43:06 +0100
committerGitHub <noreply@github.com>2017-06-02 14:43:06 +0100
commit2a50e82132d317b3ab6c8d964d972f56d1dbdac6 (patch)
treee643c1afe4cf2d9c11f203b0020546c7c9e1c9a1
parent5eea7985094df4f5f3cbbd4201851907c099b353 (diff)
parent6c9e6b43743e95104dbb888b9fc87112aabb98a6 (diff)
downloadchef-2a50e82132d317b3ab6c8d964d972f56d1dbdac6.tar.gz
Merge pull request #6142 from MsysTechnologiesllc/nim/error_handling_for_proxy_issue
[MSYS-563] Modified error message to explain connectivity issue due to Proxy
-rw-r--r--lib/chef/knife.rb6
-rw-r--r--spec/unit/knife_spec.rb22
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index 9c8b984054..aa30f2e2ed 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -486,7 +486,11 @@ class Chef
ui.error "Failed to authenticate to #{server_url} as #{username} with key #{api_key}"
ui.info "Response: #{format_rest_error(response)}"
when Net::HTTPForbidden
- ui.error "You authenticated successfully to #{server_url} as #{username} but you are not authorized for this action"
+ ui.error "You authenticated successfully to #{server_url} as #{username} but you are not authorized for this action."
+ proxy_env_vars = ENV.to_hash.keys.map(&:downcase) & %w{http_proxy https_proxy ftp_proxy socks_proxy no_proxy}
+ unless proxy_env_vars.empty?
+ ui.error "There are proxy servers configured, your Chef server may need to be added to NO_PROXY."
+ end
ui.info "Response: #{format_rest_error(response)}"
when Net::HTTPBadRequest
ui.error "The data in your request was invalid"
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 00c629b680..2b22dbc4f7 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -439,6 +439,28 @@ describe Chef::Knife do
expect(stderr.string).to match(%r{Response: y u no administrator})
end
+ context "when proxy servers are set" do
+ before do
+ ENV["http_proxy"] = "xyz"
+ end
+
+ after do
+ ENV.delete("http_proxy")
+ end
+
+ it "formats proxy errors nicely" do
+ response = Net::HTTPForbidden.new("1.1", "403", "Forbidden")
+ response.instance_variable_set(:@read, true)
+ allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no administrator"))
+ allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response))
+ allow(knife).to receive(:username).and_return("sadpanda")
+ knife.run_with_pretty_exceptions
+ expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action})
+ expect(stderr.string).to match(%r{ERROR: There are proxy servers configured, your Chef server may need to be added to NO_PROXY.})
+ expect(stderr.string).to match(%r{Response: y u no administrator})
+ end
+ end
+
it "formats 400s nicely" do
response = Net::HTTPBadRequest.new("1.1", "400", "Bad Request")
response.instance_variable_set(:@read, true) # I hate you, net/http.