diff options
| author | Luke Kanies <luke@madstop.com> | 2008-06-14 13:53:56 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-06-14 13:53:56 -0500 |
| commit | 6a61198f9293674a4bf0aa75bfbca10e20f64d20 (patch) | |
| tree | 0b1b6c4ffe6e69c3c9d3e9650620e3afbd486f18 /spec/unit/executables/client | |
| parent | eaa6eabc680cb6264594e30fd6a56e3e36765269 (diff) | |
| parent | 7b2c310e18b214424ae082e6ed2354a07b708c6f (diff) | |
| download | puppet-6a61198f9293674a4bf0aa75bfbca10e20f64d20.tar.gz puppet-6a61198f9293674a4bf0aa75bfbca10e20f64d20.tar.xz puppet-6a61198f9293674a4bf0aa75bfbca10e20f64d20.zip | |
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/executables/client')
| -rwxr-xr-x | spec/unit/executables/client/certhandler.rb | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/unit/executables/client/certhandler.rb b/spec/unit/executables/client/certhandler.rb new file mode 100755 index 000000000..3737c9a57 --- /dev/null +++ b/spec/unit/executables/client/certhandler.rb @@ -0,0 +1,88 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/executables/client/certhandler' + +cert_handler = Puppet::Executables::Client::CertHandler + +describe cert_handler, "when handling certificates" do + before do + @caclient = mock('caclient') + caclient_class = mock('caclient_class') + caclient_class.stubs(:new).returns(@caclient) + Puppet::Network::Client.stubs(:ca).returns(caclient_class) + end + + it "should return true if the certificate exists" do + @caclient.expects(:read_cert).returns(true) + cert_handler.new(1,true).read_retrieve.should be_true + end + + it "should return false when getting a new cert" do + @caclient.expects(:read_cert).returns(true) + @caclient.stubs(:request_cert).returns(true) + ch = cert_handler.new(1,true) + ch.stubs(:read_cert).returns(false) + ch.read_retrieve.should be_false + end + + describe "when waiting for cert" do + before do + @caclient.stubs(:read_cert).returns false + end + + it "should loop when the cert request does not return a certificate" do + @caclient.stubs(:request_cert).times(2).returns(false).then.returns(true) + ch = cert_handler.new(1,false) + ch.expects(:sleep) + ch.expects(:read_new_cert).returns(true) + ch.read_retrieve + end + + it "should loop when the cert request raises an Error" do + @caclient.stubs(:request_cert).times(2).raises(StandardError, 'Testing').then.returns(true) + ch = cert_handler.new(1,false) + ch.expects(:sleep) + ch.expects(:read_new_cert).returns(true) + ch.read_retrieve + end + + it "should loop when the new cert can't be read" do + @caclient.stubs(:request_cert).returns(true) + ch = cert_handler.new(1,false) + ch.expects(:sleep) + ch.expects(:read_new_cert).times(2).returns(false).then.returns(true) + ch.read_retrieve + end + end + + describe "when in one time mode" do + before do + @caclient.stubs(:read_cert).returns false + end + + it "should exit if the cert request does not return a certificate" do + @caclient.stubs(:request_cert).returns(false) + ch = cert_handler.new(1,true) + ch.expects(:exit).with(1).raises(SystemExit) + lambda { ch.read_retrieve }.should raise_error(SystemExit) + end + + + it "should exit if the cert request raises an exception" do + @caclient.stubs(:request_cert).raises(StandardError, 'Testing') + ch = cert_handler.new(1,true) + ch.expects(:exit).with(23).raises(SystemExit) + lambda { ch.read_retrieve }.should raise_error(SystemExit) + end + + it "should exit if the new cert can't be read" do + @caclient.stubs(:request_cert).returns(true) + @caclient.stubs(:read_cert).returns(false) + ch = cert_handler.new(1,true) + ch.expects(:exit).with(34).raises(SystemExit) + lambda { ch.read_retrieve }.should raise_error(SystemExit) + end + end +end |
