summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-24 20:53:25 -0500
committerLuke Kanies <luke@madstop.com>2008-08-26 22:40:41 -0700
commit40e76fb83ef466425fec736abbf1913a6426bf01 (patch)
tree59b4239f340260d58e026470b6c060334632a0d5
parent8ea25efd90b4d2281db12076cbaab3f766cac8b4 (diff)
downloadpuppet-40e76fb83ef466425fec736abbf1913a6426bf01.tar.gz
puppet-40e76fb83ef466425fec736abbf1913a6426bf01.tar.xz
puppet-40e76fb83ef466425fec736abbf1913a6426bf01.zip
Fixing the rest backends for webrick and mongrel so the get the whole request key.
Also adding the Content work necessary to demonstrate that this is actually required. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/file_serving/content.rb16
-rw-r--r--lib/puppet/network/http/mongrel/rest.rb2
-rw-r--r--lib/puppet/network/http/webrick/rest.rb2
-rwxr-xr-xspec/unit/file_serving/content.rb12
-rwxr-xr-xspec/unit/network/http/mongrel/rest.rb6
-rwxr-xr-xspec/unit/network/http/webrick/rest.rb6
6 files changed, 34 insertions, 10 deletions
diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb
index f13fcaa72..b30070dd6 100644
--- a/lib/puppet/file_serving/content.rb
+++ b/lib/puppet/file_serving/content.rb
@@ -14,9 +14,19 @@ class Puppet::FileServing::Content < Puppet::FileServing::Base
extend Puppet::Indirector
indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks
- attr_reader :path
+ def self.supported_formats
+ [:raw]
+ end
+
+ def self.from_raw(content)
+ instance = new("eh")
+ instance.content = content
+ instance
+ end
+ # Collect our data.
def collect
+ content
end
# Read the content of our file in.
@@ -29,4 +39,8 @@ class Puppet::FileServing::Content < Puppet::FileServing::Base
end
@content
end
+
+ def to_raw
+ content
+ end
end
diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb
index d265dde86..45d21ea62 100644
--- a/lib/puppet/network/http/mongrel/rest.rb
+++ b/lib/puppet/network/http/mongrel/rest.rb
@@ -35,7 +35,7 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler
# return the key included in the request path
def request_key(request)
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
- x = request.params[Mongrel::Const::REQUEST_PATH].split('/')[2]
+ x = request.params[Mongrel::Const::REQUEST_PATH].split('/', 3)[2]
end
# return the request body
diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb
index 13f795fb2..f06914365 100644
--- a/lib/puppet/network/http/webrick/rest.rb
+++ b/lib/puppet/network/http/webrick/rest.rb
@@ -36,7 +36,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet
def request_key(request)
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
- x = request.path.split('/')[2]
+ x = request.path.split('/', 3)[2]
end
def body(request)
diff --git a/spec/unit/file_serving/content.rb b/spec/unit/file_serving/content.rb
index a63f7efab..5441dff53 100755
--- a/spec/unit/file_serving/content.rb
+++ b/spec/unit/file_serving/content.rb
@@ -28,7 +28,8 @@ describe Puppet::FileServing::Content do
File.stubs(:lstat).returns(stub("stat", :ftype => "file"))
File.expects(:read).with("/path").returns result
content.collect
- content.content.should equal(result)
+
+ content.instance_variable_get("@content").should_not be_nil
end
end
@@ -58,4 +59,13 @@ describe Puppet::FileServing::Content, "when returning the contents" do
File.expects(:read).with(@path).returns(:mycontent)
@content.content.should == :mycontent
end
+
+ it "should cache the returned contents" do
+ File.expects(:stat).with(@path).returns stub("stat", :ftype => "file")
+ File.expects(:read).with(@path).returns(:mycontent)
+ @content.content
+
+ # The second run would throw a failure if the content weren't being cached.
+ @content.content
+ end
end
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index 3b248dcfe..9dbc1c9ab 100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -53,9 +53,9 @@ describe "Puppet::Network::HTTP::MongrelREST" do
@handler.path(@request).should == "/foo"
end
- it "should use the second part of the request path as the request key" do
- @params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo/bar"
- @handler.request_key(@request).should == "bar"
+ it "should use the remainder of the request path as the request key" do
+ @params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo/bar/baz"
+ @handler.request_key(@request).should == "bar/baz"
end
it "should return nil as the request key if no second field is present" do
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index 620201472..1f4ccbe29 100755
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -47,9 +47,9 @@ describe Puppet::Network::HTTP::WEBrickREST do
@handler.path(@request).should == "/foo"
end
- it "should return the second field in the path as the request key" do
- @request.expects(:path).returns "/foo/bar"
- @handler.request_key(@request).should == "bar"
+ it "should return the remainder of the path as the request key" do
+ @request.expects(:path).returns "/foo/bar/baz"
+ @handler.request_key(@request).should == "bar/baz"
end
it "should return nil as the request key if there is no second field" do