summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2016-02-29 15:30:01 -0800
committerNoah Kantrowitz <noah@coderanger.net>2016-02-29 15:30:01 -0800
commitc824aa564fa1a193d76b47fa430742c0a756eaa2 (patch)
treea89549efd83665bc1c95fd83059696249f8d1149
parent5533dbb2917860dca16765d49079ed01a421fad8 (diff)
downloadchef-c824aa564fa1a193d76b47fa430742c0a756eaa2.tar.gz
Handle negative content length headers too.
This is equivalent to not passing one, we can't check for bad downloads.
-rw-r--r--lib/chef/http/validate_content_length.rb2
-rw-r--r--spec/unit/http/validate_content_length_spec.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/chef/http/validate_content_length.rb b/lib/chef/http/validate_content_length.rb
index 33b6d5a549..17219a7c89 100644
--- a/lib/chef/http/validate_content_length.rb
+++ b/lib/chef/http/validate_content_length.rb
@@ -86,7 +86,7 @@ class Chef
transfer_encoding = http_response["transfer-encoding"]
content_encoding = http_response["content-encoding"]
- if content_length.nil?
+ if content_length.nil? || content_length < 0
Chef::Log.debug "HTTP server did not include a Content-Length header in response, cannot identify truncated downloads."
return true
end
diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb
index 37bf6c2180..7fedb66b11 100644
--- a/spec/unit/http/validate_content_length_spec.rb
+++ b/spec/unit/http/validate_content_length_spec.rb
@@ -119,6 +119,21 @@ describe Chef::HTTP::ValidateContentLength do
end
end
+ describe "with negative Content-Length header" do
+ let(:content_length_value) { '-1' }
+
+ %w{direct streaming}.each do |req_type|
+ describe "when running #{req_type} request" do
+ let(:request_type) { req_type.to_sym }
+
+ it "should skip validation and log for debug" do
+ run_content_length_validation
+ expect(debug_output).to include("HTTP server did not include a Content-Length header in response")
+ end
+ end
+ end
+ end
+
describe "with correct Content-Length header" do
%w{direct streaming}.each do |req_type|
describe "when running #{req_type} request" do