diff options
-rw-r--r-- | lib/chef/http/authenticator.rb | 3 | ||||
-rw-r--r-- | spec/unit/knife_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/rest_spec.rb | 30 |
3 files changed, 15 insertions, 21 deletions
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb index 4255f18cbd..4ec35add34 100644 --- a/lib/chef/http/authenticator.rb +++ b/lib/chef/http/authenticator.rb @@ -24,6 +24,8 @@ class Chef class HTTP class Authenticator + SERVER_API_VERSION = "0" + attr_reader :signing_key_filename attr_reader :raw_key attr_reader :attr_names @@ -41,6 +43,7 @@ class Chef 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' => SERVER_API_VERSION}) [method, url, headers, data] end diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index b748232081..cb7d5e0b9e 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -130,7 +130,8 @@ describe Chef::Knife do "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", 'X-Chef-Version' => Chef::VERSION, "Host"=>"api.opscode.piab", - "X-REMOTE-REQUEST-ID"=>request_id}} + "X-REMOTE-REQUEST-ID"=>request_id, + 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}} let(:request_id) {"1234"} diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb index 85c9e3df8f..b4f8f336a9 100644 --- a/spec/unit/rest_spec.rb +++ b/spec/unit/rest_spec.rb @@ -69,8 +69,8 @@ describe Chef::REST do rest end - let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id}} - let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id}} + let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}} + let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}} before(:each) do Chef::Log.init(log_stringio) @@ -277,19 +277,6 @@ describe Chef::REST do rest end - let(:base_headers) do - { - 'Accept' => 'application/json', - 'X-Chef-Version' => Chef::VERSION, - 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE, - 'X-REMOTE-REQUEST-ID' => request_id - } - end - - let (:req_with_body_headers) do - base_headers.merge("Content-Type" => "application/json", "Content-Length" => '13') - end - before(:each) do Chef::Config[:ssl_client_cert] = nil Chef::Config[:ssl_client_key] = nil @@ -304,7 +291,8 @@ describe Chef::REST do 'X-Chef-Version' => Chef::VERSION, 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE, 'Host' => host_header, - 'X-REMOTE-REQUEST-ID' => request_id + 'X-REMOTE-REQUEST-ID' => request_id, + 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION } end @@ -548,7 +536,7 @@ describe Chef::REST do end end end - end + end # as JSON API requests context "when streaming downloads to a tempfile" do let!(:tempfile) { Tempfile.open("chef-rspec-rest_spec-line-@{__LINE__}--") } @@ -586,7 +574,8 @@ describe Chef::REST do 'X-Chef-Version' => Chef::VERSION, 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE, 'Host' => host_header, - 'X-REMOTE-REQUEST-ID'=> request_id + 'X-REMOTE-REQUEST-ID'=> request_id, + 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION } expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock) rest.streaming_request(url, {}) @@ -597,7 +586,8 @@ describe Chef::REST do 'X-Chef-Version' => Chef::VERSION, 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE, 'Host' => host_header, - 'X-REMOTE-REQUEST-ID'=> request_id + 'X-REMOTE-REQUEST-ID'=> request_id, + 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION } expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock) rest.streaming_request(url, {}) @@ -695,7 +685,7 @@ describe Chef::REST do expect(block_called).to be_truthy end end - end + end # when making REST requests context "when following redirects" do let(:rest) do |