summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-03-19 23:58:19 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-03-20 18:27:08 +1100
commit0179e945a7d402c90a333c8207243882af362e06 (patch)
treee977d49f50c7907a67799bd8d445f833f9c823ee /spec/unit
parenta497263d97229489dcc4341cc98ca3c75f116374 (diff)
downloadpuppet-0179e945a7d402c90a333c8207243882af362e06.tar.gz
puppet-0179e945a7d402c90a333c8207243882af362e06.tar.xz
puppet-0179e945a7d402c90a333c8207243882af362e06.zip
Fixing #1557 - Environments are now in REST URIs
This commit includes multiple, related changes, all in one commit because the whole thing was necessary to reach a functional tree again: * The URI starts with the environment, so: /production/certificate/foo /development/file_content/path/to/your/file * All REST handling is done by a single instance mounted at / for webrick and Mongrel, rather than having individual instances mounted at, say, /certificate. * All REST URI translation is done by an API module. Currently only the 'v1' module exists with no support for additional modules, but it's well-separated and will be easy to expand as we need it. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/application/puppetd.rb6
-rw-r--r--spec/unit/application/puppetmasterd.rb7
-rwxr-xr-xspec/unit/network/http/handler.rb66
-rwxr-xr-xspec/unit/network/http/mongrel.rb23
-rwxr-xr-xspec/unit/network/http/mongrel/rest.rb14
-rwxr-xr-xspec/unit/network/http/webrick.rb27
-rwxr-xr-xspec/unit/network/http/webrick/rest.rb14
-rwxr-xr-xspec/unit/ssl/certificate.rb4
-rwxr-xr-xspec/unit/ssl/certificate_revocation_list.rb4
9 files changed, 50 insertions, 115 deletions
diff --git a/spec/unit/application/puppetd.rb b/spec/unit/application/puppetd.rb
index 592b499ca..d93a52761 100755
--- a/spec/unit/application/puppetd.rb
+++ b/spec/unit/application/puppetd.rb
@@ -398,12 +398,6 @@ describe "puppetd" do
@puppetd.setup_listen
end
- it "should create a server with facts REST handler" do
- Puppet::Network::Server.expects(:new).with { |args| args[:handlers] == [:facts] }
-
- @puppetd.setup_listen
- end
-
it "should use puppet default port" do
Puppet.stubs(:[]).with(:puppetport).returns(:port)
diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/puppetmasterd.rb
index da1b1dd1c..5b193ebbf 100644
--- a/spec/unit/application/puppetmasterd.rb
+++ b/spec/unit/application/puppetmasterd.rb
@@ -289,13 +289,6 @@ describe "PuppetMaster" do
@puppetmasterd.main
end
- it "should create the server with the right REST handlers" do
- Puppet::Indirector::Indirection.stubs(:instances).returns("handlers")
- Puppet::Network::Server.expects(:new).with { |args| args[:handlers] == "handlers"}
-
- @puppetmasterd.main
- end
-
it "should generate a SSL cert for localhost" do
Puppet::SSL::Host.expects(:localhost)
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 85149b642..84b87025f 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -21,28 +21,13 @@ describe Puppet::Network::HTTP::Handler do
end
describe "when initializing" do
- before do
- Puppet::Indirector::Indirection.stubs(:model).returns "eh"
- end
-
it "should fail when no server type has been provided" do
- lambda { @handler.initialize_for_puppet :handler => "foo" }.should raise_error(ArgumentError)
+ lambda { @handler.initialize_for_puppet }.should raise_error(ArgumentError)
end
- it "should fail when no handler has been provided" do
- lambda { @handler.initialize_for_puppet :server => "foo" }.should raise_error(ArgumentError)
- end
-
- it "should set the handler and server type" do
- @handler.initialize_for_puppet :server => "foo", :handler => "bar"
+ it "should set server type" do
+ @handler.initialize_for_puppet("foo")
@handler.server.should == "foo"
- @handler.handler.should == "bar"
- end
-
- it "should use the indirector to find the appropriate model" do
- Puppet::Indirector::Indirection.expects(:model).with("bar").returns "mymodel"
- @handler.initialize_for_puppet :server => "foo", :handler => "bar"
- @handler.model.should == "mymodel"
end
end
@@ -59,9 +44,6 @@ describe Puppet::Network::HTTP::Handler do
@result = stub 'result', :render => "mytext"
- @handler.stubs(:model).returns @model_class
- @handler.stubs(:handler).returns :my_handler
-
stub_server_interface
end
@@ -82,7 +64,7 @@ describe Puppet::Network::HTTP::Handler do
@handler.expects(:http_method).with(@request).returns "mymethod"
@handler.expects(:params).with(@request).returns "myparams"
- @handler.expects(:uri2indirection).with("mypath", "myparams", "mymethod").returns stub("request", :method => :find)
+ @handler.expects(:uri2indirection).with("mymethod", "mypath", "myparams").returns stub("request", :method => :find)
@handler.stubs(:do_find)
@@ -115,7 +97,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when finding a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :options => {}, :key => "my_result"
+ @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "my_result", :model => @model_class
@model_class.stubs(:find).returns @result
@@ -123,6 +105,12 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model class" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_find(@irequest, @request, @response)
+ end
+
it "should use the escaped request key" do
@model_class.expects(:find).with do |key, args|
key == "my_result"
@@ -131,7 +119,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:find).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end.returns @result
@@ -206,7 +194,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when searching for model instances" do
before do
- @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@result1 = mock 'result1'
@result2 = mock 'results'
@@ -219,8 +207,14 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_search(@irequest, @request, @response)
+ end
+
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:search).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end.returns @result
@@ -267,12 +261,18 @@ describe Puppet::Network::HTTP::Handler do
describe "when destroying a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :destroy, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :destroy, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@result = stub 'result', :render => "the result"
@model_class.stubs(:destroy).returns @result
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_destroy(@irequest, @request, @response)
+ end
+
it "should use the escaped request key to destroy the instance in the model" do
@irequest.expects(:key).returns "foo bar"
@model_class.expects(:destroy).with do |key, args|
@@ -282,7 +282,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:destroy).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end
@@ -306,7 +306,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when saving a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :save, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :save, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@handler.stubs(:body).returns('my stuff')
@result = stub 'result', :render => "the result"
@@ -318,6 +318,12 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_save(@irequest, @request, @response)
+ end
+
it "should use the 'body' hook to retrieve the body of the request" do
@handler.expects(:body).returns "my body"
@model_class.expects(:convert_from).with { |format, body| body == "my body" }.returns @model_instance
@@ -332,7 +338,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_instance.expects(:save).with do |args|
args[:foo] == :baz and args[:bar] == :xyzzy
end
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 9c708067a..59f893251 100755
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -31,10 +31,7 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
@mock_puppet_mongrel = mock('puppet_mongrel')
Puppet::Network::HTTPServer::Mongrel.stubs(:new).returns(@mock_puppet_mongrel)
- @listen_params = { :address => "127.0.0.1", :port => 31337,
- :handlers => [ :node, :catalog ], :protocols => [ :rest, :xmlrpc ],
- :xmlrpc_handlers => [ :status, :fileserver ]
- }
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :protocols => [ :rest, :xmlrpc ], :xmlrpc_handlers => [ :status, :fileserver ] }
end
it "should fail if already listening" do
@@ -42,10 +39,6 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
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
@@ -75,12 +68,10 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
end
describe "when providing REST services" do
- 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_mongrel.expects(:register)
- end
- end
+ it "should instantiate a handler at / for handling REST calls" do
+ Puppet::Network::HTTP::MongrelREST.expects(:new).returns "myhandler"
+ @mock_mongrel.expects(:register).with("/", "myhandler")
+
@server.listen(@listen_params)
end
@@ -107,10 +98,6 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
@server.listen(@listen_params.merge(:xmlrpc_handlers => [:status, :master]))
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(ArgumentError)
- end
end
describe "Puppet::Network::HTTP::Mongrel", "when turning off listening" do
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index c03698dbd..84a7e7f64 100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -48,19 +48,9 @@ describe "Puppet::Network::HTTP::MongrelREST" do
@handler.http_method(@request).should == "mymethod"
end
- it "should use the first part of the request path as the path" do
+ it "should return the request path as the path" do
@params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo/bar"
- @handler.path(@request).should == "/foo"
- end
-
- 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
- @params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo"
- @handler.request_key(@request).should be_nil
+ @handler.path(@request).should == "/foo/bar"
end
it "should return the request body as the body" do
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index e02d5c213..a6fbfc83f 100755
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -20,9 +20,7 @@ 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 ], :xmlrpc_handlers => [], :protocols => [ :rest ]
- }
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :xmlrpc_handlers => [], :protocols => [ :rest ] }
end
it "should fail if already listening" do
@@ -30,10 +28,6 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
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
@@ -84,18 +78,11 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
end
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 register the REST handler at /" do
+ # We don't care about the options here.
+ @mock_webrick.expects(:mount).with { |path, klass, options| path == "/" and klass == Puppet::Network::HTTP::WEBrickREST }
- 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)
+ @server.listen(@listen_params.merge(:protocols => [:rest]))
end
end
@@ -150,10 +137,6 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@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
end
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index b32cf49c5..bb0918131 100755
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -42,19 +42,9 @@ describe Puppet::Network::HTTP::WEBrickREST do
@handler.http_method(@request).should == "FOO"
end
- it "should return the first argument of the request path as the path" do
+ it "should return the request path as the path" do
@request.expects(:path).returns "/foo/bar"
- @handler.path(@request).should == "/foo"
- end
-
- 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
- @request.expects(:path).returns "/foo"
- @handler.request_key(@request).should be_nil
+ @handler.path(@request).should == "/foo/bar"
end
it "should return the request body as the body" do
diff --git a/spec/unit/ssl/certificate.rb b/spec/unit/ssl/certificate.rb
index a092c6abe..0d48991ad 100755
--- a/spec/unit/ssl/certificate.rb
+++ b/spec/unit/ssl/certificate.rb
@@ -21,10 +21,6 @@ describe Puppet::SSL::Certificate do
@class.indirection.name.should == :certificate
end
- it "should default to the :file terminus" do
- @class.indirection.terminus_class.should == :file
- end
-
it "should only support the text format" do
@class.supported_formats.should == [:s]
end
diff --git a/spec/unit/ssl/certificate_revocation_list.rb b/spec/unit/ssl/certificate_revocation_list.rb
index 3963b407f..eb25268e6 100755
--- a/spec/unit/ssl/certificate_revocation_list.rb
+++ b/spec/unit/ssl/certificate_revocation_list.rb
@@ -12,10 +12,6 @@ describe Puppet::SSL::CertificateRevocationList do
@class = Puppet::SSL::CertificateRevocationList
end
- it "should default to the :file terminus" do
- @class.indirection.terminus_class.should == :file
- end
-
it "should only support the text format" do
@class.supported_formats.should == [:s]
end