summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/mongrel.rb1
-rw-r--r--lib/puppet/network/http/webrick.rb22
-rwxr-xr-x[-rw-r--r--]spec/integration/network/server/mongrel.rb0
-rwxr-xr-x[-rw-r--r--]spec/integration/network/server/webrick.rb4
-rw-r--r--spec/unit/network/http/webrick.rb130
5 files changed, 115 insertions, 42 deletions
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index 9a4531c7a..5e93b88ba 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -38,6 +38,7 @@ class Puppet::Network::HTTP::Mongrel
def setup_handlers
@protocols.each do |protocol|
+ next if protocol == :xmlrpc
klass = class_for_protocol(protocol)
@handlers.each do |handler|
@server.register('/' + handler.to_s, klass.new(:server => @server, :handler => handler))
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index 2b3eace48..36fb0776b 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -25,6 +25,7 @@ class Puppet::Network::HTTP::WEBrick
@protocols = args[:protocols]
@handlers = args[:handlers]
+ @xmlrpc_handlers = args[:xmlrpc_handlers]
arguments = {:BindAddress => args[:address], :Port => args[:port]}
arguments.merge!(setup_logger)
@@ -105,9 +106,6 @@ class Puppet::Network::HTTP::WEBrick
results[:SSLCACertificateFile] = Puppet[:localcacert]
results[:SSLVerifyClient] = OpenSSL::SSL::VERIFY_PEER
- # LAK:NOTE I'm not sure why this is this way, actually.
- results[:SSLCertName] = nil
-
results[:SSLCertificateStore] = setup_ssl_store if Puppet[:hostcrl] != 'false'
results
@@ -130,12 +128,30 @@ class Puppet::Network::HTTP::WEBrick
private
def setup_handlers
+ # Set up the new-style protocols.
@protocols.each do |protocol|
+ next if protocol == :xmlrpc
klass = self.class.class_for_protocol(protocol)
@handlers.each do |handler|
@server.mount('/' + handler.to_s, klass, handler)
@server.mount('/' + handler.to_s + 's', klass, handler)
end
end
+
+ # And then set up xmlrpc, if configured.
+ if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
+ @server.mount("/RPC2", xmlrpc_servlet)
+ end
+ end
+
+ # Create our xmlrpc servlet, which provides backward compatibility.
+ def xmlrpc_servlet
+ handlers = @xmlrpc_handlers.collect { |handler|
+ unless hclass = Puppet::Network::Handler.handler(handler)
+ raise "Invalid xmlrpc handler %s" % handler
+ end
+ hclass.new({})
+ }
+ Puppet::Network::XMLRPC::WEBrickServlet.new handlers
end
end
diff --git a/spec/integration/network/server/mongrel.rb b/spec/integration/network/server/mongrel.rb
index a4089585e..a4089585e 100644..100755
--- a/spec/integration/network/server/mongrel.rb
+++ b/spec/integration/network/server/mongrel.rb
diff --git a/spec/integration/network/server/webrick.rb b/spec/integration/network/server/webrick.rb
index ee307bca3..120f2946c 100644..100755
--- a/spec/integration/network/server/webrick.rb
+++ b/spec/integration/network/server/webrick.rb
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/network/server'
require 'puppet/ssl/certificate_authority'
@@ -8,7 +10,7 @@ describe Puppet::Network::Server do
before :each do
Puppet[:servertype] = 'webrick'
Puppet[:hostcrl] = 'false'
- @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :node ] }
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :node ], :xmlrpc_handlers => [ :status ] }
# Get a safe temporary file
@tmpfile = Tempfile.new("webrick_integration_testing")
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'