summaryrefslogtreecommitdiff
path: root/spec/unit/server_api_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/server_api_spec.rb')
-rw-r--r--spec/unit/server_api_spec.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/spec/unit/server_api_spec.rb b/spec/unit/server_api_spec.rb
index 1b5d729383..5d78c4bd9b 100644
--- a/spec/unit/server_api_spec.rb
+++ b/spec/unit/server_api_spec.rb
@@ -116,17 +116,36 @@ describe Chef::ServerAPI do
it "500 on a get retries and gets correctly " do
WebMock.disable_net_connect!
- get_body = { bar: "baz" }
headers = { "Accept" => "application/json", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Host" => "chef.example.com:4000", "X-Chef-Version" => Chef::VERSION, "X-Ops-Sign" => "algorithm=sha1;version=1.1;", "X-Ops-Userid" => "silent-bob" }
stub_request(:get, "http://chef.example.com:4000/foo").with(headers: headers).to_return(status: [500, "Internal Server Error"])
stub_request(:get, "http://chef.example.com:4000/foo").with(headers: headers).to_return(status: 200, body: "", headers: {})
client.get("foo")
end
- end
- it "does not retry a 406 Not Acceptable" do
- WebMock.disable_net_connect!
- stub_request(:get, "http://chef.example.com:4000/foo").to_return(status: [406, "Not Acceptable"])
- expect { client.get("foo") }.to raise_error(Net::HTTPServerException)
+ it "406 on a post does protocol negotiation" do
+ WebMock.disable_net_connect!
+ post_body = { bar: "baz" }
+ body_406 = '{"error":"invalid-x-ops-server-api-version","message":"Specified version 2 not supported","min_version":0,"max_version":1}'
+ stub_request(:post, "http://chef.example.com:4000/foo").with(body: post_body.to_json, headers: { "X-Ops-Server-Api-Version" => "2" }).to_return(status: [406, "Not Acceptable"], body: body_406 )
+ stub_request(:post, "http://chef.example.com:4000/foo").with(body: post_body.to_json, headers: { "X-Ops-Server-Api-Version" => "0" }).to_return(status: 200, body: "", headers: {})
+ client.post("foo", post_body)
+ end
+
+ it "406 on a put does protocol negotiation" do
+ WebMock.disable_net_connect!
+ put_body = { bar: "baz" }
+ body_406 = '{"error":"invalid-x-ops-server-api-version","message":"Specified version 2 not supported","min_version":0,"max_version":1}'
+ stub_request(:put, "http://chef.example.com:4000/foo").with(body: put_body.to_json, headers: { "X-Ops-Server-Api-Version" => "2" }).to_return(status: [406, "Not Acceptable"], body: body_406 )
+ stub_request(:put, "http://chef.example.com:4000/foo").with(body: put_body.to_json, headers: { "X-Ops-Server-Api-Version" => "0" }).to_return(status: 200, body: "", headers: {})
+ client.put("foo", put_body)
+ end
+
+ it "406 on a get does protocol negotiation" do
+ WebMock.disable_net_connect!
+ body_406 = '{"error":"invalid-x-ops-server-api-version","message":"Specified version 2 not supported","min_version":0,"max_version":1}'
+ stub_request(:get, "http://chef.example.com:4000/foo").with(headers: { "X-Ops-Server-Api-Version" => "2" }).to_return(status: [406, "Not Acceptable"], body: body_406 )
+ stub_request(:get, "http://chef.example.com:4000/foo").with(headers: { "X-Ops-Server-Api-Version" => "0" }).to_return(status: 200, body: "", headers: {})
+ client.get("foo")
+ end
end
end