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/webrick | |
| 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/webrick')
| -rwxr-xr-x | spec/unit/network/http/webrick/rest.rb | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb index 1f4ccbe29..b32cf49c5 100755 --- a/spec/unit/network/http/webrick/rest.rb +++ b/spec/unit/network/http/webrick/rest.rb @@ -83,11 +83,37 @@ describe Puppet::Network::HTTP::WEBrickREST do end describe "and determining the request parameters" do - it "should include the HTTP request parameters" do - @request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy) + it "should include the HTTP request parameters, with the keys as symbols" do + @request.stubs(:query).returns("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(:query).returns('foo' => encoding) + result = @handler.params(@request) + result[:foo].should == "foo bar" + end + + it "should convert the string 'true' to the boolean" do + @request.expects(:query).returns('foo' => "true") + result = @handler.params(@request) + result[:foo].should be_true + end + + it "should convert the string 'false' to the boolean" do + @request.expects(:query).returns('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(:query).returns('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 |
