summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-10 17:05:38 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-12 16:29:06 -0800
commitc514c641d0c0090be29252dcc773385248d3fe93 (patch)
treeb73294a3764f4dc0743971aee1fcc574d5d85f02 /spec/unit/network
parent2b9b7a5f7fe4b673f0d1fba9fb523cc0e2e34fa5 (diff)
downloadpuppet-c514c641d0c0090be29252dcc773385248d3fe93.tar.gz
puppet-c514c641d0c0090be29252dcc773385248d3fe93.tar.xz
puppet-c514c641d0c0090be29252dcc773385248d3fe93.zip
(#5838) Added support for HEAD requests to the indirector.
Added the ability for the indirector to handle REST HEAD requests. These are done using a new indirector method, head(), which should return true if find() would return a result and false if find() would return nil. Access control for the head method is the union of that for the find and save methods. That is, if either find or save is allowed, then head is allowed. This is necessary so that users will not have to change their authconfig to take advantage of the new feature. Paired-with: Jesse Wolfe <jesse@puppetlabs.com>
Diffstat (limited to 'spec/unit/network')
-rw-r--r--spec/unit/network/http/api/v1_spec.rb4
-rwxr-xr-xspec/unit/network/http/handler_spec.rb33
-rwxr-xr-xspec/unit/network/rest_authconfig_spec.rb2
-rwxr-xr-xspec/unit/network/rights_spec.rb20
4 files changed, 58 insertions, 1 deletions
diff --git a/spec/unit/network/http/api/v1_spec.rb b/spec/unit/network/http/api/v1_spec.rb
index c593242c0..23a291cf3 100644
--- a/spec/unit/network/http/api/v1_spec.rb
+++ b/spec/unit/network/http/api/v1_spec.rb
@@ -68,6 +68,10 @@ describe Puppet::Network::HTTP::API::V1 do
@tester.uri2indirection("GET", "/env/foo/bar", {}).method.should == :find
end
+ it "should choose 'head' as the indirection method if the http method is a HEAD and the indirection name is singular" do
+ @tester.uri2indirection("HEAD", "/env/foo/bar", {}).method.should == :head
+ end
+
it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is plural" do
@tester.uri2indirection("GET", "/env/foos/bar", {}).method.should == :search
end
diff --git a/spec/unit/network/http/handler_spec.rb b/spec/unit/network/http/handler_spec.rb
index cdbce41f7..8464ae68e 100755
--- a/spec/unit/network/http/handler_spec.rb
+++ b/spec/unit/network/http/handler_spec.rb
@@ -256,6 +256,39 @@ describe Puppet::Network::HTTP::Handler do
end
end
+ describe "when performing head operation" do
+ before do
+ @irequest = stub 'indirection_request', :method => :head, :indirection_name => "my_handler", :to_hash => {}, :key => "my_result", :model => @model_class
+
+ @model_class.stubs(:head).returns true
+ end
+
+ it "should use the indirection request to find the model class" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_head(@irequest, @request, @response)
+ end
+
+ it "should use the escaped request key" do
+ @model_class.expects(:head).with do |key, args|
+ key == "my_result"
+ end.returns true
+ @handler.do_head(@irequest, @request, @response)
+ end
+
+ it "should not generate a response when a model head call succeeds" do
+ @handler.expects(:set_response).never
+ @handler.do_head(@irequest, @request, @response)
+ end
+
+ it "should return a 404 when the model head call returns false" do
+ @model_class.stubs(:name).returns "my name"
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
+ @model_class.stubs(:head).returns(false)
+ @handler.do_head(@irequest, @request, @response)
+ end
+ end
+
describe "when searching for model instances" do
before do
@irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
diff --git a/spec/unit/network/rest_authconfig_spec.rb b/spec/unit/network/rest_authconfig_spec.rb
index 9892c2b25..d629f8670 100755
--- a/spec/unit/network/rest_authconfig_spec.rb
+++ b/spec/unit/network/rest_authconfig_spec.rb
@@ -47,7 +47,7 @@ describe Puppet::Network::RestAuthConfig do
end
it "should ask for authorization to the ACL subsystem" do
- @acl.expects(:is_forbidden_and_why?).with("/path/to/resource", :node => "me", :ip => "127.0.0.1", :method => :save, :environment => :env, :authenticated => true).returns(nil)
+ @acl.expects(:is_request_forbidden_and_why?).with(@request).returns(nil)
@authconfig.allowed?(@request)
end
diff --git a/spec/unit/network/rights_spec.rb b/spec/unit/network/rights_spec.rb
index ca3f22464..3b9e48374 100755
--- a/spec/unit/network/rights_spec.rb
+++ b/spec/unit/network/rights_spec.rb
@@ -9,6 +9,26 @@ describe Puppet::Network::Rights do
@right = Puppet::Network::Rights.new
end
+ describe "when validating a :head request" do
+ [:find, :save].each do |allowed_method|
+ it "should allow the request if only #{allowed_method} is allowed" do
+ rights = Puppet::Network::Rights.new
+ rights.newright("/")
+ rights.allow("/", "*")
+ rights.restrict_method("/", allowed_method)
+ rights.restrict_authenticated("/", :any)
+ request = Puppet::Indirector::Request.new(:indirection_name, :head, "key")
+ rights.is_request_forbidden_and_why?(request).should == nil
+ end
+ end
+
+ it "should disallow the request if neither :find nor :save is allowed" do
+ rights = Puppet::Network::Rights.new
+ request = Puppet::Indirector::Request.new(:indirection_name, :head, "key")
+ rights.is_request_forbidden_and_why?(request).should be_instance_of(Puppet::Network::AuthorizationError)
+ end
+ end
+
[:allow, :deny, :restrict_method, :restrict_environment, :restrict_authenticated].each do |m|
it "should have a #{m} method" do
@right.should respond_to(m)