summaryrefslogtreecommitdiffstats
path: root/spec/unit/executables/client
diff options
context:
space:
mode:
authorAndrew Shafer <andrew@reductivelabs.com>2008-06-14 12:37:58 -0600
committerAndrew Shafer <andrew@reductivelabs.com>2008-06-14 12:37:58 -0600
commit4d70449a61b2e1ed198b38c8e75a44410c6adcaf (patch)
treec66bbdb71e533339b5c8744e1a8e04d86f50d4d1 /spec/unit/executables/client
parent7b2c310e18b214424ae082e6ed2354a07b708c6f (diff)
Fix bug in test, add more specs and small refactor
The tests were failing when run on a machine with certs on the file system Stub out failure to read where appropriate Worked fine at my desk :(
Diffstat (limited to 'spec/unit/executables/client')
-rwxr-xr-xspec/unit/executables/client/certhandler.rb106
1 files changed, 74 insertions, 32 deletions
diff --git a/spec/unit/executables/client/certhandler.rb b/spec/unit/executables/client/certhandler.rb
index 0a7b77f15..4f8f8139c 100755
--- a/spec/unit/executables/client/certhandler.rb
+++ b/spec/unit/executables/client/certhandler.rb
@@ -14,67 +14,109 @@ describe cert_handler, "when handling certificates" do
Puppet::Network::Client.stubs(:ca).returns(caclient_class)
end
- it "should return true if the certificate exists" do
- Puppet::Network::HttpPool.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
- Puppet::Network::HttpPool.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
+ describe "when reading or retrieving the certificate" do
+ before do
+ @handler = cert_handler.new(1,true)
+ end
+
+ it "should attempt to read the certificate" do
+ @handler.expects(:read_cert).returns true
+ @handler.read_retrieve
+ end
+
+ it "should delegate to Puppet::Network::HttpPool to read the certificate" do
+ Puppet::Network::HttpPool.expects(:read_cert).returns(true)
+ @handler.read_retrieve
+ end
+
+ it "should not attempt to retrieve a certificate if one can be read" do
+ @handler.stubs(:read_cert).returns true
+ @handler.expects(:retrieve_cert).never
+ @handler.read_retrieve
+ end
+
+ it "should attempt to retrieve a certificate if none can be read" do
+ @handler.stubs(:read_cert).returns false
+ @handler.expects(:retrieve_cert)
+ @handler.read_retrieve
+ end
+
+ it "should delegate to caclient to retrieve a certificate" do
+ @handler.stubs(:read_cert).returns false
+ @caclient.expects(:request_cert).returns(true)
+ @handler.stubs(:read_new_cert).returns(true)
+ @handler.read_retrieve
+ end
+
+ it "should return true if the certificate exists" do
+ @handler.stubs(:read_cert).returns true
+ @handler.read_retrieve.should be_true
+ end
+
+ it "should return false when getting a new cert" do
+ #This is the second call to httppool that happens in 'read_new_cert'
+ Puppet::Network::HttpPool.expects(:read_cert).returns(true)
+ @caclient.stubs(:request_cert).returns(true)
+ @handler.stubs(:read_cert).returns(false)
+ @handler.read_retrieve.should be_false
+ end
end
describe "when waiting for cert" do
+ before do
+ @handler = cert_handler.new(1,false)
+ @handler.stubs(:read_cert).returns false
+ #all waiting for cert tests should loop, which will always happen if sleep is called
+ #yeah, I put the expectation in the setup, deal with it
+ @handler.expects(:sleep).with(1)
+
+ #This is needed to get out of the loop
+ @handler.stubs(:read_new_cert).returns(true)
+ 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
+ @handler.retrieve_cert
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
+ @handler.retrieve_cert
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
+ @handler.stubs(:read_new_cert).times(2).returns(false).then.returns(true)
+ @handler.retrieve_cert
end
end
describe "when in one time mode" do
+ before do
+ #true puts us in onetime mode
+ @handler = cert_handler.new(1,true)
+ @handler.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)
+ @handler.expects(:exit).with(1).raises(SystemExit)
+ lambda { @handler.retrieve_cert }.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)
+ @handler.expects(:exit).with(23).raises(SystemExit)
+ lambda { @handler.retrieve_cert }.should raise_error(SystemExit)
end
it "should exit if the new cert can't be read" do
@caclient.stubs(:request_cert).returns(true)
+ #this is the second, call to httppool inside read_new_cert
Puppet::Network::HttpPool.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)
+ @handler.expects(:exit).with(34).raises(SystemExit)
+ lambda { @handler.retrieve_cert }.should raise_error(SystemExit)
end
end
end