summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-04-19 15:30:11 -0500
committerLuke Kanies <luke@madstop.com>2008-04-19 15:30:11 -0500
commit934fbba81cb18f05e07675d79a2e830c4e95c918 (patch)
tree271bc1b8f94904e24be6b4823b304ef8787f4e9e
parentd4813f1e03d96551e91b104e48b028fb4074d398 (diff)
downloadpuppet-934fbba81cb18f05e07675d79a2e830c4e95c918.tar.gz
puppet-934fbba81cb18f05e07675d79a2e830c4e95c918.tar.xz
puppet-934fbba81cb18f05e07675d79a2e830c4e95c918.zip
Making the SSL::Host's destroy method a class method,
rather than an instance method.
-rw-r--r--lib/puppet/ssl/host.rb17
-rwxr-xr-xspec/unit/ssl/host.rb46
2 files changed, 40 insertions, 23 deletions
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index c1dac2050..931d64ab3 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -74,6 +74,16 @@ class Puppet::SSL::Host
end
end
+ # Remove all traces of a given host
+ def self.destroy(name)
+ [Key, Certificate, CertificateRequest].inject(false) do |result, klass|
+ if klass.destroy(name)
+ result = true
+ end
+ result
+ end
+ end
+
# Search for more than one host, optionally only specifying
# an interest in hosts with a given file type.
# This just allows our non-indirected class to have one of
@@ -131,13 +141,6 @@ class Puppet::SSL::Host
@certificate
end
- # Remove all traces of this ssl host
- def destroy
- [key, certificate, certificate_request].each do |instance|
- instance.class.destroy(name) if instance
- end
- end
-
def initialize(name)
@name = name
@key = @certificate = @certificate_request = nil
diff --git a/spec/unit/ssl/host.rb b/spec/unit/ssl/host.rb
index d3756a016..b214aa44a 100755
--- a/spec/unit/ssl/host.rb
+++ b/spec/unit/ssl/host.rb
@@ -125,6 +125,36 @@ describe Puppet::SSL::Host do
end
end
+ it "should have a class method for destroying all files related to a given host" do
+ Puppet::SSL::Host.should respond_to(:destroy)
+ end
+
+ describe "when destroying a host's SSL files" do
+ before do
+ Puppet::SSL::Key.stubs(:destroy).returns false
+ Puppet::SSL::Certificate.stubs(:destroy).returns false
+ Puppet::SSL::CertificateRequest.stubs(:destroy).returns false
+ end
+
+ it "should destroy its certificate, certificate request, and key" do
+ Puppet::SSL::Key.expects(:destroy).with("myhost")
+ Puppet::SSL::Certificate.expects(:destroy).with("myhost")
+ Puppet::SSL::CertificateRequest.expects(:destroy).with("myhost")
+
+ Puppet::SSL::Host.destroy("myhost")
+ end
+
+ it "should return true if any of the classes returned true" do
+ Puppet::SSL::Certificate.expects(:destroy).with("myhost").returns true
+
+ Puppet::SSL::Host.destroy("myhost").should be_true
+ end
+
+ it "should return false if none of the classes returned true" do
+ Puppet::SSL::Host.destroy("myhost").should be_false
+ end
+ end
+
describe "when managing its private key" do
before do
@realkey = "mykey"
@@ -229,22 +259,6 @@ describe Puppet::SSL::Host do
end
end
- describe "when being destroyed" do
- before do
- @host.stubs(:key).returns Puppet::SSL::Key.new("myname")
- @host.stubs(:certificate).returns Puppet::SSL::Certificate.new("myname")
- @host.stubs(:certificate_request).returns Puppet::SSL::CertificateRequest.new("myname")
- end
-
- it "should destroy its certificate, certificate request, and key" do
- Puppet::SSL::Key.expects(:destroy).with(@host.name)
- Puppet::SSL::Certificate.expects(:destroy).with(@host.name)
- Puppet::SSL::CertificateRequest.expects(:destroy).with(@host.name)
-
- @host.destroy
- end
- end
-
it "should have a method for listing certificate hosts" do
Puppet::SSL::Host.should respond_to(:search)
end