diff options
author | Claire McQuin <claire@getchef.com> | 2014-01-23 16:57:47 -0800 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-01-23 16:57:47 -0800 |
commit | 963c3d55ce11f5d00a59b216e026d1bf87e7217a (patch) | |
tree | bfa44790eaa368f1390582b20332b7618ee6928a | |
parent | 50b163117b6a2ca7b3325e207a16c03fd7449dad (diff) | |
download | chef-963c3d55ce11f5d00a59b216e026d1bf87e7217a.tar.gz |
add real error for bad download size
-rw-r--r-- | lib/chef/exceptions.rb | 4 | ||||
-rw-r--r-- | lib/chef/http/validate_response.rb | 2 | ||||
-rw-r--r-- | spec/unit/rest_spec.rb | 8 |
3 files changed, 9 insertions, 5 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 1c952318f1..bc4a6e3b47 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -297,5 +297,9 @@ class Chef # non-GET and non-HEAD request will thus raise an InvalidRedirect. class InvalidRedirect < StandardError; end + # Raised when the content length of a download does not match the content + # length declared in the http response. + class ContentLengthMismatch < RuntimeError; end + end end diff --git a/lib/chef/http/validate_response.rb b/lib/chef/http/validate_response.rb index 436334ab7a..1eaef3fa91 100644 --- a/lib/chef/http/validate_response.rb +++ b/lib/chef/http/validate_response.rb @@ -82,7 +82,7 @@ class Chef Chef::Log.debug "Content-Length header = #{content_length}" Chef::Log.debug "Response body length = #{response_length}" if response_length != content_length - raise "Response body length #{response_length} does not match HTTP Content-Length header #{content_length}" #FIXME: real exception + raise Chef::Exceptions::ContentLengthMismatch, "Response body length #{response_length} does not match HTTP Content-Length header #{content_length}." end true end diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb index b8c3155d53..86e447a66f 100644 --- a/spec/unit/rest_spec.rb +++ b/spec/unit/rest_spec.rb @@ -389,7 +389,7 @@ describe Chef::REST do it "should fail if the response is truncated" do http_response["Content-Length"] = (body.bytesize + 99).to_s - expect { rest.request(:GET, url) }.to raise_error(RuntimeError) + expect { rest.request(:GET, url) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) end context "when JSON is returned" do @@ -402,7 +402,7 @@ describe Chef::REST do it "should fail if the response is truncated" do http_response.add_field('content-type', "application/json") http_response["Content-Length"] = (body.bytesize + 99).to_s - expect { rest.request(:GET, url, {}) }.to raise_error(RuntimeError) + expect { rest.request(:GET, url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) end end @@ -488,7 +488,7 @@ describe Chef::REST do end it "fails when the compressed body is truncated" do http_response["Content-Length"] = (body.bytesize + 99).to_s - expect {rest.request(:GET, url)}.to raise_error(RuntimeError) + expect {rest.request(:GET, url)}.to raise_error(Chef::Exceptions::ContentLengthMismatch) end end @@ -590,7 +590,7 @@ describe Chef::REST do it "it raises an exception when the download is truncated" do http_response["Content-Length"] = (body.bytesize + 99).to_s http_response.stub(:read_body).and_yield("ninja") - expect { rest.streaming_request(url, {}) }.to raise_error(RuntimeError) + expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) end it "fetches a file and yields the tempfile it is streamed to" do |