diff options
| author | Luke Kanies <luke@madstop.com> | 2009-02-14 17:35:34 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-18 22:38:43 -0600 |
| commit | 7bc41cefa0115067a2e9aab3dbd1924667c46dfe (patch) | |
| tree | fb2ae6dad4610ae6d6d633c1aedde514e5568afb /spec/unit/network/http/mongrel | |
| parent | 992231a58daf8f0b489022f0af8ddcfb615bb0e1 (diff) | |
| download | puppet-7bc41cefa0115067a2e9aab3dbd1924667c46dfe.tar.gz puppet-7bc41cefa0115067a2e9aab3dbd1924667c46dfe.tar.xz puppet-7bc41cefa0115067a2e9aab3dbd1924667c46dfe.zip | |
Adding clarity to query string handling in REST calls
We previously only handled simple strings as values,
but we know handle true and false as booleans, we URI-escape
all strings, and we can yaml-encode and then escape arrays of
strings.
This could get abused a bit, in that we're just yaml-dumping anything
that's an array, but it should be pretty safe. Mmmm, should.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/network/http/mongrel')
| -rwxr-xr-x | spec/unit/network/http/mongrel/rest.rb | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb index 9dbc1c9ab..e72d4f540 100755 --- a/spec/unit/network/http/mongrel/rest.rb +++ b/spec/unit/network/http/mongrel/rest.rb @@ -97,16 +97,42 @@ describe "Puppet::Network::HTTP::MongrelREST" do end end - describe "and determining the request parameters", :shared => true do + describe "and determining the request parameters" do before do @request.stubs(:params).returns({}) end - it "should include the HTTP request parameters" do + it "should include the HTTP request parameters, with the keys as symbols" do @request.expects(:params).returns('QUERY_STRING' => 'foo=baz&bar=xyzzy') result = @handler.params(@request) - result["foo"].should == "baz" - result["bar"].should == "xyzzy" + result[:foo].should == "baz" + result[:bar].should == "xyzzy" + end + + it "should URI-decode the HTTP parameters" do + encoding = URI.escape("foo bar") + @request.expects(:params).returns('QUERY_STRING' => "foo=#{encoding}") + result = @handler.params(@request) + result[:foo].should == "foo bar" + end + + it "should convert the string 'true' to the boolean" do + @request.expects(:params).returns('QUERY_STRING' => 'foo=true') + result = @handler.params(@request) + result[:foo].should be_true + end + + it "should convert the string 'false' to the boolean" do + @request.expects(:params).returns('QUERY_STRING' => 'foo=false') + result = @handler.params(@request) + result[:foo].should be_false + end + + it "should YAML-load and URI-decode values that are YAML-encoded" do + escaping = URI.escape(YAML.dump(%w{one two})) + @request.expects(:params).returns('QUERY_STRING' => "foo=#{escaping}") + result = @handler.params(@request) + result[:foo].should == %w{one two} end it "should pass the client's ip address to model find" do |
