summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-06-14 13:53:56 -0500
committerLuke Kanies <luke@madstop.com>2008-06-14 13:53:56 -0500
commit6a61198f9293674a4bf0aa75bfbca10e20f64d20 (patch)
tree0b1b6c4ffe6e69c3c9d3e9650620e3afbd486f18 /spec/unit/network/http
parenteaa6eabc680cb6264594e30fd6a56e3e36765269 (diff)
parent7b2c310e18b214424ae082e6ed2354a07b708c6f (diff)
Merge branch '0.24.x'
Also added the fixes to make the certhandler tests pass even when certs exist; I'll deal with the conflict later. Conflicts: CHANGELOG bin/puppetd lib/puppet/network/http/handler.rb lib/puppet/network/http/mongrel/rest.rb spec/integration/indirector/rest.rb spec/integration/network/server/mongrel.rb spec/integration/network/server/webrick.rb spec/unit/network/http/webrick.rb
Diffstat (limited to 'spec/unit/network/http')
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/mongrel.rb0
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/mongrel/rest.rb166
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/mongrel/xmlrpc.rb0
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/webrick.rb2
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/webrick/rest.rb167
-rwxr-xr-x[-rw-r--r--]spec/unit/network/http/webrick/xmlrpc.rb0
6 files changed, 241 insertions, 94 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 1f87fd943..1f87fd943 100644..100755
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index b483bbd46..3df925133 100644..100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -1,9 +1,11 @@
+#!/usr/bin/env ruby
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
require 'puppet/network/http'
describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
confine "Mongrel is not available" => Puppet.features.mongrel?
-
+
before do
@mock_mongrel = mock('Mongrel server')
@mock_mongrel.stubs(:register)
@@ -11,20 +13,20 @@ describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model)
@params = { :server => @mock_mongrel, :handler => :foo }
end
-
+
it "should require access to a Mongrel server" do
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError)
end
-
+
it "should require an indirection name" do
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :handler == k })}.should raise_error(ArgumentError)
end
-
+
it "should look up the indirection model from the indirection name" do
Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(@mock_model)
Puppet::Network::HTTP::MongrelREST.new(@params)
end
-
+
it "should fail if the indirection is not known" do
Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil)
Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params) }.should raise_error(ArgumentError)
@@ -33,7 +35,7 @@ end
describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
confine "Mongrel is not available" => Puppet.features.mongrel?
-
+
before do
@mock_request = stub('mongrel http request')
@mock_head = stub('response head')
@@ -45,28 +47,28 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model_class)
@handler = Puppet::Network::HTTP::MongrelREST.new(:server => @mock_mongrel, :handler => :foo)
end
-
+
def setup_find_request(params = {})
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET',
Mongrel::Const::REQUEST_PATH => '/foo/key',
'QUERY_STRING' => ''}.merge(params))
@mock_model_class.stubs(:find)
end
-
+
def setup_search_request(params = {})
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET',
Mongrel::Const::REQUEST_PATH => '/foos',
'QUERY_STRING' => '' }.merge(params))
@mock_model_class.stubs(:search).returns([])
end
-
+
def setup_destroy_request(params = {})
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE',
Mongrel::Const::REQUEST_PATH => '/foo/key',
'QUERY_STRING' => '' }.merge(params))
@mock_model_class.stubs(:destroy)
end
-
+
def setup_save_request(params = {})
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT',
Mongrel::Const::REQUEST_PATH => '/foo',
@@ -75,26 +77,26 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_model_instance = stub('indirected model instance', :save => true)
@mock_model_class.stubs(:from_yaml).returns(@mock_model_instance)
end
-
+
def setup_bad_request
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'POST', Mongrel::Const::REQUEST_PATH => '/foos'})
end
it "should call the model find method if the request represents a singular HTTP GET" do
setup_find_request
- @mock_model_class.expects(:find).with('key', {})
+ @mock_model_class.expects(:find).with { |key, args| key == 'key' }
@handler.process(@mock_request, @mock_response)
end
it "should call the model search method if the request represents a plural HTTP GET" do
setup_search_request
- @mock_model_class.expects(:search).with({}).returns([])
+ @mock_model_class.expects(:search).returns([])
@handler.process(@mock_request, @mock_response)
end
-
+
it "should call the model destroy method if the request represents an HTTP DELETE" do
setup_destroy_request
- @mock_model_class.expects(:destroy).with('key', {})
+ @mock_model_class.expects(:destroy).with { |key, args| key == 'key' }
@handler.process(@mock_request, @mock_response)
end
@@ -103,13 +105,13 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_model_instance.expects(:save)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should fail if the HTTP method isn't supported" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'POST', Mongrel::Const::REQUEST_PATH => '/foo'})
@mock_response.expects(:start).with(404)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should fail if the request's pluralization is wrong" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foos/key'})
@mock_response.expects(:start).with(404)
@@ -127,8 +129,74 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_response.expects(:start).with(404)
@handler.process(@mock_request, @mock_response)
end
-
-
+
+ describe "and determining the request parameters", :shared => true do
+ before do
+ @mock_request.stubs(:params).returns({})
+ end
+
+ it "should include the HTTP request parameters" do
+ @mock_request.expects(:params).returns('QUERY_STRING' => 'foo=baz&bar=xyzzy')
+ result = @handler.params(@mock_request)
+ result["foo"].should == "baz"
+ result["bar"].should == "xyzzy"
+ end
+
+ it "should pass the client's ip address to model find" do
+ @mock_request.stubs(:params).returns("REMOTE_ADDR" => "ipaddress")
+ @handler.params(@mock_request)[:ip].should == "ipaddress"
+ end
+
+ it "should use the :ssl_client_header to determine the parameter when looking for the certificate" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => "/CN=host.domain.com")
+ @handler.params(@mock_request)
+ end
+
+ it "should retrieve the hostname by matching the certificate parameter" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => "/CN=host.domain.com")
+ @handler.params(@mock_request)[:node].should == "host.domain.com"
+ end
+
+ it "should use the :ssl_client_header to determine the parameter for checking whether the host certificate is valid" do
+ Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
+ Puppet.settings.expects(:value).with(:ssl_client_verify_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com")
+ @handler.params(@mock_request)
+ end
+
+ it "should consider the host authenticated if the validity parameter contains 'SUCCESS'" do
+ Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
+ Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com")
+ @handler.params(@mock_request)[:authenticated].should be_true
+ end
+
+ it "should consider the host unauthenticated if the validity parameter does not contain 'SUCCESS'" do
+ Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
+ Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => "whatever", "certheader" => "/CN=host.domain.com")
+ @handler.params(@mock_request)[:authenticated].should be_false
+ end
+
+ it "should consider the host unauthenticated if no certificate information is present" do
+ Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
+ Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => nil, "certheader" => "SUCCESS")
+ @handler.params(@mock_request)[:authenticated].should be_false
+ end
+
+ it "should not pass a node name to model method if no certificate information is present" do
+ Puppet.settings.stubs(:value).returns "eh"
+ Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
+ @mock_request.stubs(:params).returns("myheader" => nil)
+ @handler.params(@mock_request).should_not be_include(:node)
+ end
+ end
+
describe "when finding a model instance" do |variable|
it "should fail to find model if key is not specified" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foo'})
@@ -136,20 +204,21 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
- it "should pass HTTP request parameters to model find" do
+ it "should use a common method for determining the request parameters" do
setup_find_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
+ @handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
@mock_model_class.expects(:find).with do |key, args|
- key == 'key' and args['foo'] == 'baz' and args['bar'] == 'xyzzy'
+ args[:foo] == :baz and args[:bar] == :xyzzy
end
@handler.process(@mock_request, @mock_response)
end
-
+
it "should generate a 200 response when a model find call succeeds" do
setup_find_request
@mock_response.expects(:start).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized object when a model find call succeeds" do
setup_find_request
@mock_model_instance = stub('model instance')
@@ -157,7 +226,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_model_class.stubs(:find).returns(@mock_model_instance)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should serialize a controller exception when an exception is thrown by find" do
setup_find_request
@mock_model_class.expects(:find).raises(ArgumentError)
@@ -172,7 +241,16 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_response.expects(:start).with(404)
@handler.process(@mock_request, @mock_response)
end
-
+
+ it "should use a common method for determining the request parameters" do
+ setup_destroy_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
+ @handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_model_class.expects(:destroy).with do |key, args|
+ args[:foo] == :baz and args[:bar] == :xyzzy
+ end
+ @handler.process(@mock_request, @mock_response)
+ end
+
it "should pass HTTP request parameters to model destroy" do
setup_destroy_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
@mock_model_class.expects(:destroy).with do |key, args|
@@ -180,20 +258,20 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
@handler.process(@mock_request, @mock_response)
end
-
+
it "should generate a 200 response when a model destroy call succeeds" do
setup_destroy_request
@mock_response.expects(:start).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized success result when a model destroy call succeeds" do
setup_destroy_request
@mock_model_class.stubs(:destroy).returns(true)
@mock_body.expects(:write).with("--- true\n")
@handler.process(@mock_request, @mock_response)
end
-
+
it "should serialize a controller exception when an exception is thrown by destroy" do
setup_destroy_request
@mock_model_class.expects(:destroy).raises(ArgumentError)
@@ -201,7 +279,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
end
-
+
describe "when saving a model instance" do |variable|
it "should fail to save model if data is not specified" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foo'})
@@ -209,20 +287,29 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_response.expects(:start).with(404)
@handler.process(@mock_request, @mock_response)
end
-
+
+ it "should use a common method for determining the request parameters" do
+ setup_save_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
+ @handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_model_instance.expects(:save).with do |args|
+ args[:foo] == :baz and args[:bar] == :xyzzy
+ end
+ @handler.process(@mock_request, @mock_response)
+ end
+
it "should generate a 200 response when a model save call succeeds" do
setup_save_request
@mock_response.expects(:start).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized object when a model save call succeeds" do
setup_save_request
@mock_model_instance.stubs(:save).returns(@mock_model_instance)
@mock_model_instance.expects(:to_yaml).returns('foo')
@handler.process(@mock_request, @mock_response)
end
-
+
it "should serialize a controller exception when an exception is thrown by save" do
setup_save_request
@mock_model_instance.expects(:save).raises(ArgumentError)
@@ -230,8 +317,17 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
end
-
+
describe "when searching for model instances" do |variable|
+ it "should use a common method for determining the request parameters" do
+ setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
+ @handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_model_class.expects(:search).with do |args|
+ args[:foo] == :baz and args[:bar] == :xyzzy
+ end
+ @handler.process(@mock_request, @mock_response)
+ end
+
it "should pass HTTP request parameters to model search" do
setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
@mock_model_class.expects(:search).with do |args|
@@ -245,7 +341,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@mock_response.expects(:start).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a list of serialized objects when a model search call succeeds" do
setup_search_request
mock_matches = [1..5].collect {|i| mock("model instance #{i}", :to_yaml => "model instance #{i}") }
@@ -260,7 +356,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
end
-
+
it "should serialize a controller exception if the request fails" do
setup_bad_request
@mock_response.expects(:start).with(404)
diff --git a/spec/unit/network/http/mongrel/xmlrpc.rb b/spec/unit/network/http/mongrel/xmlrpc.rb
index e69de29bb..e69de29bb 100644..100755
--- a/spec/unit/network/http/mongrel/xmlrpc.rb
+++ b/spec/unit/network/http/mongrel/xmlrpc.rb
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 6d006992c..e3c3b81c0 100644..100755
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -162,7 +162,7 @@ describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a
end
it "should accept a protocol" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError)
+ 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
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index b7bd33880..45e5f0bd2 100644..100755
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
require 'puppet/network/http'
@@ -8,23 +10,23 @@ describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do
Puppet::Indirector::Indirection.stubs(:model).returns(@mock_model)
@params = [ @mock_webrick, :foo ]
end
-
+
it "should require access to a WEBrick server" do
Proc.new {
@params[0] = nil
Puppet::Network::HTTP::WEBrickREST.new(*@params)
}.should raise_error(ArgumentError)
end
-
+
it "should require an indirection name" do
Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params.first) }.should raise_error(ArgumentError)
end
-
+
it "should look up the indirection model from the indirection name" do
Puppet::Indirector::Indirection.expects(:model).returns(@mock_model)
Puppet::Network::HTTP::WEBrickREST.new(*@params)
end
-
+
it "should fail if the indirection is not known" do
Puppet::Indirector::Indirection.expects(:model).returns(nil)
Proc.new { Puppet::Network::HTTP::WEBrickREST.new(*@params) }.should raise_error(ArgumentError)
@@ -33,7 +35,7 @@ end
describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
before do
- @mock_request = stub('webrick http request', :query => {})
+ @mock_request = stub('webrick http request', :query => {}, :peeraddr => %w{eh boo host ip}, :client_cert => nil)
@mock_response = stub('webrick http response', :status= => true, :body= => true)
@mock_model_class = stub('indirected model class')
@mock_webrick = stub('webrick http server', :mount => true, :[] => {})
@@ -46,19 +48,19 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_request.stubs(:path).returns('/foo/key')
@mock_model_class.stubs(:find)
end
-
+
def setup_search_request
@mock_request.stubs(:request_method).returns('GET')
@mock_request.stubs(:path).returns('/foos')
@mock_model_class.stubs(:search).returns([])
end
-
+
def setup_destroy_request
@mock_request.stubs(:request_method).returns('DELETE')
@mock_request.stubs(:path).returns('/foo/key')
@mock_model_class.stubs(:destroy)
end
-
+
def setup_save_request
@mock_request.stubs(:request_method).returns('PUT')
@mock_request.stubs(:path).returns('/foo')
@@ -66,44 +68,48 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_model_instance = stub('indirected model instance', :save => true)
@mock_model_class.stubs(:from_yaml).returns(@mock_model_instance)
end
-
+
def setup_bad_request
@mock_request.stubs(:request_method).returns('POST')
@mock_request.stubs(:path).returns('/foos')
end
-
-
+
+ it "should delegate its :service method to its :process method" do
+ @handler.expects(:process).with(@mock_request, @mock_response).returns "stuff"
+ @handler.service(@mock_request, @mock_response).should == "stuff"
+ end
+
it "should call the model find method if the request represents a singular HTTP GET" do
setup_find_request
- @mock_model_class.expects(:find).with('key', {})
- @handler.service(@mock_request, @mock_response)
+ @mock_model_class.expects(:find).with { |key, args| key == 'key' }
+ @handler.process(@mock_request, @mock_response)
end
it "should call the model search method if the request represents a plural HTTP GET" do
setup_search_request
@mock_model_class.expects(:search).returns([])
- @handler.service(@mock_request, @mock_response)
+ @handler.process(@mock_request, @mock_response)
end
-
+
it "should call the model destroy method if the request represents an HTTP DELETE" do
setup_destroy_request
- @mock_model_class.expects(:destroy).with('key', {})
- @handler.service(@mock_request, @mock_response)
+ @mock_model_class.expects(:destroy).with { |key, args| key == 'key' }
+ @handler.process(@mock_request, @mock_response)
end
it "should call the model save method if the request represents an HTTP PUT" do
setup_save_request
@mock_model_instance.expects(:save)
- @handler.service(@mock_request, @mock_response)
+ @handler.process(@mock_request, @mock_response)
end
-
+
it "should fail if the HTTP method isn't supported" do
@mock_request.stubs(:request_method).returns('POST')
@mock_request.stubs(:path).returns('/foo')
@mock_response.expects(:status=).with(404)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should fail if delete request's pluralization is wrong" do
@mock_request.stubs(:request_method).returns('DELETE')
@mock_request.stubs(:path).returns('/foos/key')
@@ -125,6 +131,42 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
+ describe "and determining the request parameters" do
+ it "should include the HTTP request parameters" do
+ @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ result = @handler.params(@mock_request)
+ result[:foo].should == :baz
+ result[:bar].should == :xyzzy
+ end
+
+ it "should pass the client's ip address to model find" do
+ @mock_request.stubs(:peeraddr).returns(%w{noidea dunno hostname ipaddress})
+ @handler.params(@mock_request)[:ip].should == "ipaddress"
+ end
+
+ it "should set 'authenticated' to true if a certificate is present" do
+ cert = stub 'cert', :subject => [%w{CN host.domain.com}]
+ @mock_request.stubs(:client_cert).returns cert
+ @handler.params(@mock_request)[:authenticated].should be_true
+ end
+
+ it "should set 'authenticated' to false if no certificate is present" do
+ @mock_request.stubs(:client_cert).returns nil
+ @handler.params(@mock_request)[:authenticated].should be_false
+ end
+
+ it "should pass the client's certificate name to model method if a certificate is present" do
+ cert = stub 'cert', :subject => [%w{CN host.domain.com}]
+ @mock_request.stubs(:client_cert).returns cert
+ @handler.params(@mock_request)[:node].should == "host.domain.com"
+ end
+
+ it "should not pass a node name to model method if no certificate is present" do
+ @mock_request.stubs(:client_cert).returns nil
+ @handler.params(@mock_request).should_not be_include(:node)
+ end
+ end
+
describe "when finding a model instance" do |variable|
it "should fail to find model if key is not specified" do
@mock_request.stubs(:request_method).returns('GET')
@@ -132,22 +174,22 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_response.expects(:status=).with(404)
@handler.process(@mock_request, @mock_response)
end
-
- it "should pass HTTP request parameters to model find" do
+
+ it "should use a common method for determining the request parameters" do
setup_find_request
- @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @handler.stubs(:params).returns(:foo => :baz, :bar => :xyzzy)
@mock_model_class.expects(:find).with do |key, args|
- key == 'key' and args[:foo] == :baz and args[:bar] == :xyzzy
+ args[:foo] == :baz and args[:bar] == :xyzzy
end
- @handler.service(@mock_request, @mock_response)
+ @handler.process(@mock_request, @mock_response)
end
-
+
it "should generate a 200 response when a model find call succeeds" do
setup_find_request
@mock_response.expects(:status=).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized object when a model find call succeeds" do
setup_find_request
@mock_model_instance = stub('model instance')
@@ -155,7 +197,7 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_model_class.stubs(:find).returns(@mock_model_instance)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should serialize a controller exception when an exception is thrown by find" do
setup_find_request
@mock_model_class.expects(:find).raises(ArgumentError)
@@ -163,7 +205,7 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
end
-
+
describe "when destroying a model instance" do |variable|
it "should fail to destroy model if key is not specified" do
@mock_request.stubs(:request_method).returns('DELETE')
@@ -171,37 +213,37 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_response.expects(:status=).with(404)
@handler.process(@mock_request, @mock_response)
end
-
- it "should pass HTTP request parameters to model destroy" do
+
+ it "should use a common method for determining the request parameters" do
setup_destroy_request
- @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @handler.stubs(:params).returns(:foo => :baz, :bar => :xyzzy)
@mock_model_class.expects(:destroy).with do |key, args|
- key == 'key' and args[:foo] == :baz and args[:bar] == :xyzzy
+ args[:foo] == :baz and args[:bar] == :xyzzy
end
- @handler.service(@mock_request, @mock_response)
+ @handler.process(@mock_request, @mock_response)
end
-
+
it "should generate a 200 response when a model destroy call succeeds" do
setup_destroy_request
@mock_response.expects(:status=).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized success result when a model destroy call succeeds" do
setup_destroy_request
@mock_model_class.stubs(:destroy).returns(true)
@mock_response.expects(:body=).with("--- true\n")
@handler.process(@mock_request, @mock_response)
end
-
- it "should serialize a controller exception when an exception is thrown by search" do
- setup_search_request
- @mock_model_class.expects(:search).raises(ArgumentError)
+
+ it "should serialize a controller exception when an exception is thrown by destroy" do
+ setup_destroy_request
+ @mock_model_class.expects(:destroy).raises(ArgumentError)
@mock_response.expects(:status=).with(404)
- @handler.process(@mock_request, @mock_response)
- end
+ @handler.process(@mock_request, @mock_response)
+ end
end
-
+
describe "when saving a model instance" do
it "should fail to save model if data is not specified" do
@mock_request.stubs(:request_method).returns('PUT')
@@ -210,20 +252,29 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_response.expects(:status=).with(404)
@handler.process(@mock_request, @mock_response)
end
-
+
+ it "should use a common method for determining the request parameters" do
+ setup_save_request
+ @handler.stubs(:params).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_model_instance.expects(:save).with do |args|
+ args[:foo] == :baz and args[:bar] == :xyzzy
+ end
+ @handler.process(@mock_request, @mock_response)
+ end
+
it "should generate a 200 response when a model save call succeeds" do
setup_save_request
@mock_response.expects(:status=).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a serialized object when a model save call succeeds" do
setup_save_request
@mock_model_instance.stubs(:save).returns(@mock_model_instance)
@mock_model_instance.expects(:to_yaml).returns('foo')
@handler.process(@mock_request, @mock_response)
end
-
+
it "should serialize a controller exception when an exception is thrown by save" do
setup_save_request
@mock_model_instance.expects(:save).raises(ArgumentError)
@@ -231,15 +282,15 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
end
-
+
describe "when searching for model instances" do
- it "should pass HTTP request parameters to model search" do
+ it "should use a common method for determining the request parameters" do
setup_search_request
- @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @handler.stubs(:params).returns(:foo => :baz, :bar => :xyzzy)
@mock_model_class.expects(:search).with do |args|
args[:foo] == :baz and args[:bar] == :xyzzy
- end.returns([])
- @handler.service(@mock_request, @mock_response)
+ end
+ @handler.process(@mock_request, @mock_response)
end
it "should generate a 200 response when a model search call succeeds" do
@@ -247,20 +298,20 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_response.expects(:status=).with(200)
@handler.process(@mock_request, @mock_response)
end
-
+
it "should return a list of serialized objects when a model search call succeeds" do
setup_search_request
mock_matches = [1..5].collect {|i| mock("model instance #{i}", :to_yaml => "model instance #{i}") }
@mock_model_class.stubs(:search).returns(mock_matches)
@handler.process(@mock_request, @mock_response)
end
-
- it "should serialize a controller exception when an exception is thrown by destroy" do
- setup_destroy_request
- @mock_model_class.expects(:destroy).raises(ArgumentError)
+
+ it "should serialize a controller exception when an exception is thrown by search" do
+ setup_search_request
+ @mock_model_class.expects(:search).raises(ArgumentError)
@mock_response.expects(:status=).with(404)
- @handler.process(@mock_request, @mock_response)
- end
+ @handler.process(@mock_request, @mock_response)
+ end
end
it "should serialize a controller exception if the request fails" do
diff --git a/spec/unit/network/http/webrick/xmlrpc.rb b/spec/unit/network/http/webrick/xmlrpc.rb
index e69de29bb..e69de29bb 100644..100755
--- a/spec/unit/network/http/webrick/xmlrpc.rb
+++ b/spec/unit/network/http/webrick/xmlrpc.rb