summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-07-15 12:50:31 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-07-23 14:11:27 -0600
commit4aff39dc90bb490379ef38075bf67da9cb780246 (patch)
treef4f0efc59f6a0814145fcd805436a7ab16fb4232 /spec
parentd767320ff0819e355f093f548db9b7d578587c57 (diff)
downloadchef-zero-4aff39dc90bb490379ef38075bf67da9cb780246.tar.gz
Do a better job parsing accepts so browsers can get data
Diffstat (limited to 'spec')
-rw-r--r--spec/server_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/server_spec.rb b/spec/server_spec.rb
index 575c2e2..d5da281 100644
--- a/spec/server_spec.rb
+++ b/spec/server_spec.rb
@@ -1,4 +1,5 @@
require 'chef_zero/server'
+require 'uri'
describe ChefZero::Server do
context 'with a server bound to port 8889' do
@@ -24,5 +25,58 @@ describe ChefZero::Server do
it 'a server bound to range 8889-8889 throws an exception' do
expect { ChefZero::Server.new(:port => 8889.upto(8889)).start_background }.to raise_error Errno::EADDRINUSE
end
+
+ context 'accept headers' do
+ def get_nodes(accepts)
+ uri = URI(@server.url)
+ httpcall = Net::HTTP.new(uri.host, uri.port)
+ httpcall.get('/nodes', 'Accept' => accepts)
+ end
+
+ it 'accepts requests with no accept header' do
+ request = Net::HTTP::Get.new('/nodes')
+ request.delete('Accept')
+ uri = URI(@server.url)
+ response = Net::HTTP.new(uri.host, uri.port).request(request)
+ expect(response.code).to eq '200'
+ end
+
+ it 'accepts requests with accept: application/json' do
+ expect(get_nodes('application/json').code).to eq '200'
+ end
+
+ it 'accepts requests with accept: application/*' do
+ expect(get_nodes('application/*').code).to eq '200'
+ end
+
+ it 'accepts requests with accept: application/*' do
+ expect(get_nodes('*/*').code).to eq '200'
+ end
+
+ it 'denies requests with accept: application/blah' do
+ expect(get_nodes('application/blah').code).to eq '406'
+ end
+
+ it 'denies requests with accept: blah/json' do
+ expect(get_nodes('blah/json').code).to eq '406'
+ end
+
+ it 'denies requests with accept: blah/*' do
+ expect(get_nodes('blah/*').code).to eq '406'
+ end
+
+ it 'denies requests with accept: blah/*' do
+ expect(get_nodes('blah/*').code).to eq '406'
+ end
+
+ it 'denies requests with accept: <empty string>' do
+ expect(get_nodes('').code).to eq '406'
+ end
+
+ it 'accepts requests with accept: a/b;a=b;c=d, application/json;a=b, application/xml;a=b' do
+ expect(get_nodes('a/b;a=b;c=d, application/json;a=b, application/xml;a=b').code).to eq '200'
+ end
+
+ end
end
end