summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http/webrick.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-02 12:58:35 -0500
committerLuke Kanies <luke@madstop.com>2008-05-02 12:58:35 -0500
commit31b79fa7760f95059a4e2afb35e734de283cf4a0 (patch)
tree5e8cf6732758e3548103d2523fccecb056c39c1d /spec/unit/network/http/webrick.rb
parent7a876ed6a06bc5decb257126eb57368aeb178a81 (diff)
downloadpuppet-31b79fa7760f95059a4e2afb35e734de283cf4a0.tar.gz
puppet-31b79fa7760f95059a4e2afb35e734de283cf4a0.tar.xz
puppet-31b79fa7760f95059a4e2afb35e734de283cf4a0.zip
Adding xmlrpc support to webrick.
This provides the backward compatibility for webrick, and only Mongrel is left.
Diffstat (limited to 'spec/unit/network/http/webrick.rb')
-rw-r--r--spec/unit/network/http/webrick.rb130
1 files changed, 92 insertions, 38 deletions
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 48b995c28..0a26a58bd 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -19,18 +19,20 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
[:setup_logger, :setup_ssl].each {|meth| @server.stubs(meth).returns({})} # the empty hash is required because of how we're merging
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :catalog ], :protocols => [ :rest ] }
+ @listen_params = { :address => "127.0.0.1", :port => 31337,
+ :handlers => [ :node, :catalog ], :xmlrpc_handlers => [], :protocols => [ :rest ]
+ }
end
-
+
it "should fail if already listening" do
@server.listen(@listen_params)
Proc.new { @server.listen(@listen_params) }.should raise_error(RuntimeError)
end
-
+
it "should require at least one handler" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
-
+
it "should require at least one protocol" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
end
@@ -38,7 +40,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
it "should require a listening address to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
end
-
+
it "should require a listening port to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :port == k})}.should raise_error(ArgumentError)
end
@@ -47,7 +49,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@mock_webrick.expects(:start)
@server.listen(@listen_params)
end
-
+
it "should tell webrick to listen on the specified address and port" do
WEBrick::HTTPServer.expects(:new).with {|args|
args[:Port] == 31337 and args[:BindAddress] == "127.0.0.1"
@@ -74,28 +76,80 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@server.listen(@listen_params)
end
-
+
it "should be listening" do
@server.listen(@listen_params)
@server.should be_listening
end
-
- it "should instantiate a handler for each protocol+handler pair to configure web server routing" do
- @listen_params[:protocols].each do |protocol|
- mock_handler = mock("handler instance for [#{protocol}]")
- mock_handler_class = mock("handler class for [#{protocol}]")
- @listen_params[:handlers].each do |handler|
- @mock_webrick.expects(:mount)
+
+ describe "when the REST protocol is requested" do
+ it "should use a WEBrick + REST class to configure WEBrick" do
+ Puppet::Network::HTTP::WEBrick.expects(:class_for_protocol).with(:rest).at_least_once
+ @server.listen(@listen_params.merge(:protocols => [:rest]))
+ end
+
+ it "should instantiate a handler for each protocol+handler pair to configure web server routing" do
+ @listen_params[:protocols].each do |protocol|
+ @listen_params[:handlers].each do |handler|
+ @mock_webrick.expects(:mount)
+ end
end
+ @server.listen(@listen_params)
end
- @server.listen(@listen_params)
end
- it "should use a WEBrick + REST class to configure WEBrick when REST services are requested" do
- Puppet::Network::HTTP::WEBrick.expects(:class_for_protocol).with(:rest).at_least_once
- @server.listen(@listen_params.merge(:protocols => [:rest]))
+ describe "when the XMLRPC protocol is requested" do
+ before do
+ @servlet = mock 'servlet'
+
+ Puppet::Network::XMLRPC::WEBrickServlet.stubs(:new).returns @servlet
+
+ @master_handler = mock('master_handler')
+ @file_handler = mock('file_handler')
+
+ @master = mock 'master'
+ @file = mock 'file'
+ @master_handler.stubs(:new).returns @master
+ @file_handler.stubs(:new).returns @file
+
+ Puppet::Network::Handler.stubs(:handler).with(:master).returns @master_handler
+ Puppet::Network::Handler.stubs(:handler).with(:fileserver).returns @file_handler
+ end
+
+ it "should do nothing if no xmlrpc handlers have been specified" do
+ Puppet::Network::Handler.expects(:handler).never
+
+ @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => []))
+ end
+
+ it "should look the handler classes up via their base class" do
+ Puppet::Network::Handler.expects(:handler).with(:master).returns @master_handler
+ Puppet::Network::Handler.expects(:handler).with(:fileserver).returns @file_handler
+
+ @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
+ end
+
+ it "should create an instance for each requested xmlrpc handler" do
+ @master_handler.expects(:new).returns @master
+ @file_handler.expects(:new).returns @file
+
+ @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
+ end
+
+ it "should create a webrick servlet with the xmlrpc handler instances" do
+ Puppet::Network::XMLRPC::WEBrickServlet.expects(:new).with([@master, @file]).returns @servlet
+
+ @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
+ end
+
+ it "should mount the webrick servlet at /RPC2" do
+ @mock_webrick.stubs(:mount)
+ @mock_webrick.expects(:mount).with("/RPC2", @servlet)
+
+ @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
+ end
end
-
+
it "should fail if services from an unknown protocol are requested" do
Proc.new { @server.listen(@listen_params.merge(:protocols => [ :foo ]))}.should raise_error
end
@@ -103,21 +157,21 @@ end
describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a protocol" do
- it "should require a protocol" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError)
- end
-
- it "should accept a protocol" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError)
- end
-
- it "should use a WEBrick + REST class when a REST protocol is specified" do
- Puppet::Network::HTTP::WEBrick.class_for_protocol("rest").should == Puppet::Network::HTTP::WEBrickREST
- end
-
- it "should fail when an unknown protocol is specified" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("abcdefg") }.should raise_error
- end
+ it "should require a protocol" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a protocol" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError)
+ end
+
+ it "should use a WEBrick + REST class when a REST protocol is specified" do
+ Puppet::Network::HTTP::WEBrick.class_for_protocol("rest").should == Puppet::Network::HTTP::WEBrickREST
+ end
+
+ it "should fail when an unknown protocol is specified" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("abcdefg") }.should raise_error
+ end
end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
@@ -129,17 +183,17 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
[:setup_logger, :setup_ssl].each {|meth| @server.stubs(meth).returns({})} # the empty hash is required because of how we're merging
@listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :catalog ], :protocols => [ :rest ] }
end
-
+
it "should fail unless listening" do
Proc.new { @server.unlisten }.should raise_error(RuntimeError)
end
-
+
it "should order webrick server to stop" do
@mock_webrick.expects(:shutdown)
@server.listen(@listen_params)
@server.unlisten
end
-
+
it "should no longer be listening" do
@server.listen(@listen_params)
@server.unlisten
@@ -154,7 +208,7 @@ describe Puppet::Network::HTTP::WEBrick do
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
end
-
+
describe "when configuring an x509 store" do
before do
@store = stub 'store'