diff options
author | nimisha <nimisha.sharad@msystechnologies.com> | 2017-06-02 15:02:20 +0530 |
---|---|---|
committer | nimisha <nimisha.sharad@msystechnologies.com> | 2017-06-02 16:51:50 +0530 |
commit | 6c9e6b43743e95104dbb888b9fc87112aabb98a6 (patch) | |
tree | e4c20049a453e6d25a76d26bc6181eeafbc21889 /spec/unit/knife_spec.rb | |
parent | d383d9078b99fd3442f0d53f6b65407b9305b641 (diff) | |
download | chef-6c9e6b43743e95104dbb888b9fc87112aabb98a6.tar.gz |
Checking for proxy error separately
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
Diffstat (limited to 'spec/unit/knife_spec.rb')
-rw-r--r-- | spec/unit/knife_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
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. |