diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-04-12 17:08:36 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-04-12 17:08:36 -0700 |
| commit | 46721411066926aff3a7d5bb6470d3b8aec1b47d (patch) | |
| tree | 5f844a68b7fe541b3699762b635cf1d8c40312f5 /spec/unit/network/http/api | |
| parent | 8778307ca33a637fe10b601ee737628f2e5f9fbf (diff) | |
| download | puppet-46721411066926aff3a7d5bb6470d3b8aec1b47d.tar.gz puppet-46721411066926aff3a7d5bb6470d3b8aec1b47d.tar.xz puppet-46721411066926aff3a7d5bb6470d3b8aec1b47d.zip | |
(#6117) Add POST support to indirector requests
POST with a singular indirection is turned into a find in the indirector.
When making a large find request from a REST terminus, POST is used, and for
small requests, GET is used for backward compatibility.
Paired-With: Jesse Wolfe
Diffstat (limited to 'spec/unit/network/http/api')
| -rwxr-xr-x | spec/unit/network/http/api/v1_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/unit/network/http/api/v1_spec.rb b/spec/unit/network/http/api/v1_spec.rb index 3da8cbfae..d16ff122a 100755 --- 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", {})[1].should == :find end + it "should choose 'find' as the indirection method if the http method is a POST and the indirection name is singular" do + @tester.uri2indirection("POST", "/env/foo/bar", {})[1].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", {})[1].should == :head end @@ -164,4 +168,26 @@ describe Puppet::Network::HTTP::API::V1 do end end + describe "when converting a request into a URI with body" do + before :each do + @request = Puppet::Indirector::Request.new(:foo, :find, "with spaces", :foo => :bar, :environment => "myenv") + end + + it "should use the environment as the first field of the URI" do + @tester.request_to_uri_and_body(@request).first.split("/")[1].should == "myenv" + end + + it "should use the indirection as the second field of the URI" do + @tester.request_to_uri_and_body(@request).first.split("/")[2].should == "foo" + end + + it "should use the escaped key as the remainder of the URI" do + escaped = URI.escape("with spaces") + @tester.request_to_uri_and_body(@request).first.split("/")[3].sub(/\?.+/, '').should == escaped + end + + it "should return the URI and body separately" do + @tester.request_to_uri_and_body(@request).should == ["/myenv/foo/with%20spaces", "foo=bar"] + end + end end |
