summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-12-15 13:17:04 -0600
committerJay Mundrawala <jdmundrawala@gmail.com>2016-01-25 09:51:06 -0800
commitd999373538ad9861ad8176d2ecd1ead02d487814 (patch)
tree5b22de7e3eecddf1bfba2402e6d0cf1b62189f98
parent395324bab4a687f8e65789c77c1222beba89a586 (diff)
downloadchef-d999373538ad9861ad8176d2ecd1ead02d487814.tar.gz
Pass headers to mixlib-authentication
-rw-r--r--lib/chef/http/authenticator.rb13
-rw-r--r--spec/unit/http/authenticator_spec.rb4
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb
index 02074171f8..ab4804c964 100644
--- a/lib/chef/http/authenticator.rb
+++ b/lib/chef/http/authenticator.rb
@@ -47,8 +47,8 @@ class Chef
end
def handle_request(method, url, headers={}, data=false)
- headers.merge!(authentication_headers(method, url, data)) if sign_requests?
headers.merge!({"X-Ops-Server-API-Version" => @api_version})
+ headers.merge!(authentication_headers(method, url, data, headers)) if sign_requests?
[method, url, headers, data]
end
@@ -90,12 +90,17 @@ class Chef
raise Chef::Exceptions::InvalidPrivateKey, msg
end
- def authentication_headers(method, url, json_body=nil)
- request_params = {:http_method => method, :path => url.path, :body => json_body, :host => "#{url.host}:#{url.port}"}
+ def authentication_headers(method, url, json_body=nil, headers=nil)
+ request_params = {
+ :http_method => method,
+ :path => url.path,
+ :body => json_body,
+ :host => "#{url.host}:#{url.port}",
+ :headers => headers,
+ }
request_params[:body] ||= ""
auth_credentials.signature_headers(request_params)
end
-
end
end
end
diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb
index 1289ebb61e..031a483fe9 100644
--- a/spec/unit/http/authenticator_spec.rb
+++ b/spec/unit/http/authenticator_spec.rb
@@ -70,7 +70,9 @@ describe Chef::HTTP::Authenticator do
it_behaves_like "merging the server API version into the headers"
it "calls authentication_headers with the proper input" do
- expect(class_instance).to receive(:authentication_headers).with(method, url, data).and_return({})
+ expect(class_instance).to receive(:authentication_headers).with(
+ method, url, data,
+ {"X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}).and_return({})
class_instance.handle_request(method, url, headers, data)
end
end