summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-04-22 11:33:37 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-04-22 11:33:37 -0700
commit5b8788c64898a0cb101d30c97e3529ebc878d384 (patch)
tree4122f769deb7d84399be2df6e7da5699ace0f80d
parent480aeb8b5cda4292411d0bc66e1f05614000acfe (diff)
downloadchef-5b8788c64898a0cb101d30c97e3529ebc878d384.tar.gz
CHEF-5100: moar func tests
This tests the reuse of the content length validation object and the situation where the content length of a previous download is retained while a 403 or other HTTP error fails to re-init the content length to zero. The result is the 403 is turned into an inaccurate content length exception, masking the real error.
-rw-r--r--spec/functional/http/simple_spec.rb24
-rw-r--r--spec/functional/rest_spec.rb15
-rw-r--r--spec/support/shared/functional/http.rb23
3 files changed, 62 insertions, 0 deletions
diff --git a/spec/functional/http/simple_spec.rb b/spec/functional/http/simple_spec.rb
index 2df40b6272..9afd57e93f 100644
--- a/spec/functional/http/simple_spec.rb
+++ b/spec/functional/http/simple_spec.rb
@@ -54,6 +54,30 @@ describe Chef::HTTP::Simple do
end
end
+ shared_examples_for "an endpoint that 403s" do
+ it "fails with a Net::HTTPServerException for a streaming request" do
+ expect { http_client.streaming_request(source) }.to raise_error(Net::HTTPServerException)
+ end
+
+ it "fails with a Net::HTTPServerException for a GET request" do
+ expect { http_client.get(source) }.to raise_error(Net::HTTPServerException)
+ end
+ end
+
+ shared_examples_for "a 403 after a successful request when reusing the request object" do
+ it "fails with a Net::HTTPServerException for a streaming request" do
+ tempfile = http_client.streaming_request(source)
+ tempfile.close
+ Digest::MD5.hexdigest(binread(tempfile.path)).should == Digest::MD5.hexdigest(expected_content)
+ expect { http_client.streaming_request(source2) }.to raise_error(Net::HTTPServerException)
+ end
+
+ it "fails with a Net::HTTPServerException for a GET request" do
+ Digest::MD5.hexdigest(http_client.get(source)).should == Digest::MD5.hexdigest(expected_content)
+ expect { http_client.get(source2) }.to raise_error(Net::HTTPServerException)
+ end
+ end
+
it_behaves_like "downloading all the things"
end
diff --git a/spec/functional/rest_spec.rb b/spec/functional/rest_spec.rb
index 7b87705d77..195a00d957 100644
--- a/spec/functional/rest_spec.rb
+++ b/spec/functional/rest_spec.rb
@@ -40,6 +40,21 @@ describe Chef::REST do
end
end
+ shared_examples_for "an endpoint that 403s" do
+ it "fails with a Net::HTTPServerException" do
+ expect { http_client.streaming_request(source, {}) }.to raise_error(Net::HTTPServerException)
+ end
+ end
+
+ shared_examples_for "a 403 after a successful request when reusing the request object" do
+ it "fails with a Net::HTTPServerException" do
+ tempfile = http_client.streaming_request(source, {})
+ tempfile.close
+ Digest::MD5.hexdigest(binread(tempfile.path)).should == Digest::MD5.hexdigest(expected_content)
+ expect { http_client.streaming_request(source2, {}) }.to raise_error(Net::HTTPServerException)
+ end
+ end
+
before do
Chef::Config[:node_name] = "webmonkey.example.com"
Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb
index 86fe467d92..c362ecaa18 100644
--- a/spec/support/shared/functional/http.rb
+++ b/spec/support/shared/functional/http.rb
@@ -146,6 +146,15 @@ module ChefHTTPShared
end
}
+ #
+ # 403 with a Content-Length
+ #
+ @api.get('/forbidden', 403, 'Forbidden',
+ {
+ 'Content-Length' => 'Forbidden'.bytesize.to_s
+ }
+ )
+
end
def stop_tiny_server
@@ -215,5 +224,19 @@ shared_examples_for "downloading all the things" do
it_behaves_like "downloads requests correctly"
end
+
+ describe "when downloading an endpoint that 403s" do
+ let(:source) { 'http://localhost:9000/forbidden' }
+
+ it_behaves_like "an endpoint that 403s"
+ end
+
+ describe "when downloading an endpoint that 403s" do
+ let(:source) { 'http://localhost:9000/nyan_cat_content_length_compressed.png' }
+ let(:expected_content) { binread(nyan_uncompressed_filename) }
+ let(:source2) { 'http://localhost:9000/forbidden' }
+
+ it_behaves_like "a 403 after a successful request when reusing the request object"
+ end
end