summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjamesc <james@opscode.com>2013-11-20 14:48:08 -0800
committerjamesc <james@opscode.com>2013-11-20 14:48:08 -0800
commitdb7e67ab8c13a32413bc53c4d985c6f7685fa0b6 (patch)
treea70b306ea0335644386b956ddc9512f7b3d873bd
parent25b383f580fa2086c639369b8ee40d3db1fff337 (diff)
downloadchef-db7e67ab8c13a32413bc53c4d985c6f7685fa0b6.tar.gz
Add tests for raw_http_request to check that the authenticator gets
called and that the correct headers are passed to send_http_request
-rw-r--r--spec/unit/rest_spec.rb45
1 files changed, 38 insertions, 7 deletions
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index 4cf58767de..0281bd22ec 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -65,13 +65,6 @@ describe Chef::REST do
Chef::REST::CookieJar.instance.clear
end
- describe "legacy API" do
- it 'responds to raw_http_request as a public method' do
- @rest.public_methods.map(&:to_s).should include("raw_http_request")
- end
-
- end
-
describe "calling an HTTP verb on a path or absolute URL" do
it "adds a relative URL to the base url it was initialized with" do
@@ -127,6 +120,44 @@ describe Chef::REST do
end
end
+ describe "legacy API" do
+ before(:each) do
+ Chef::Config[:node_name] = "webmonkey.example.com"
+ Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
+ @rest = Chef::REST.new(@base_url)
+ end
+
+ it 'responds to raw_http_request as a public method' do
+ @rest.public_methods.map(&:to_s).should include("raw_http_request")
+ end
+
+ it 'calls the authn middleware' do
+ data = "\"secure data\""
+
+ auth_headers = STANDARD_WRITE_HEADERS.merge({"auth_done"=>"yep"})
+
+ @rest.authenticator.should_receive(:handle_request).
+ with(:POST, @monkey_uri, STANDARD_WRITE_HEADERS, data).
+ and_return([:POST, @monkey_uri, auth_headers, data])
+ @rest.should_receive(:send_http_request).
+ with(:POST, @monkey_uri, auth_headers, data).
+ and_return([1,2,3])
+ @rest.should_receive('success_response?'.to_sym).with(1).and_return(true)
+ @rest.raw_http_request(:POST, @monkey_uri, STANDARD_WRITE_HEADERS, data)
+ end
+
+ it 'sets correct authn headers' do
+ data = "\"secure data\""
+ method, uri, auth_headers, d = @rest.authenticator.handle_request(:POST, @monkey_uri, STANDARD_WRITE_HEADERS, data)
+
+ @rest.should_receive(:send_http_request).
+ with(:POST, @monkey_uri, auth_headers, data).
+ and_return([1,2,3])
+ @rest.should_receive('success_response?'.to_sym).with(1).and_return(true)
+ @rest.raw_http_request(:POST, @monkey_uri, STANDARD_WRITE_HEADERS, data)
+ end
+ end
+
describe "when configured to authenticate to the Chef server" do
before do