summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-05 17:10:07 -0500
committerLuke Kanies <luke@madstop.com>2008-05-05 17:10:07 -0500
commit67dc268fae0489de93f247b08fdaf7b1eec0e15d (patch)
tree727206889dcccab3d9d3292726e87a663ae539f9 /spec
parent6356c043a44c771d707750f96f7660a1093be9ac (diff)
downloadpuppet-67dc268fae0489de93f247b08fdaf7b1eec0e15d.tar.gz
puppet-67dc268fae0489de93f247b08fdaf7b1eec0e15d.tar.xz
puppet-67dc268fae0489de93f247b08fdaf7b1eec0e15d.zip
The CA now initializes itself.
I realized that it never made sense to have a CA that didn't know how to initialize itself, so we now have a singleton method for the CA, and it also automatically initializes itself.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/ssl/certificate_authority.rb2
-rwxr-xr-xspec/unit/ssl/certificate_authority.rb89
2 files changed, 80 insertions, 11 deletions
diff --git a/spec/integration/ssl/certificate_authority.rb b/spec/integration/ssl/certificate_authority.rb
index f7eb0f46a..447dabe43 100755
--- a/spec/integration/ssl/certificate_authority.rb
+++ b/spec/integration/ssl/certificate_authority.rb
@@ -32,6 +32,8 @@ describe Puppet::SSL::CertificateAuthority do
Puppet::SSL::Key.indirection.clear_cache
Puppet::SSL::Certificate.indirection.clear_cache
Puppet::SSL::CertificateRequest.indirection.clear_cache
+
+ Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
}
it "should create a CA host" do
diff --git a/spec/unit/ssl/certificate_authority.rb b/spec/unit/ssl/certificate_authority.rb
index 424f47512..0cb2f2f1c 100755
--- a/spec/unit/ssl/certificate_authority.rb
+++ b/spec/unit/ssl/certificate_authority.rb
@@ -27,12 +27,69 @@ describe "a normal interface method", :shared => true do
end
describe Puppet::SSL::CertificateAuthority do
+ after do
+ # Clear out the var, yay unit tests.
+ Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
+ Puppet.settings.clearused
+ end
+
+ it "should have a class method for returning a singleton instance" do
+ Puppet::SSL::CertificateAuthority.should respond_to(:instance)
+ end
+
+ describe "when finding an existing instance" do
+ describe "and the host is a CA host and the proces name is 'puppetmasterd'" do
+ before do
+ Puppet.settings.stubs(:value).with(:ca).returns true
+ Puppet.settings.stubs(:value).with(:name).returns "puppetmasterd"
+
+ @ca = mock('ca')
+ Puppet::SSL::CertificateAuthority.stubs(:new).returns @ca
+ end
+
+ after do
+ # Clear out the var, yay unit tests.
+ Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
+ end
+
+ it "should return an instance" do
+ Puppet::SSL::CertificateAuthority.instance.should equal(@ca)
+ end
+
+ it "should always return the same instance" do
+ Puppet::SSL::CertificateAuthority.instance.should equal(Puppet::SSL::CertificateAuthority.instance)
+ end
+ end
+
+ describe "and the host is not a CA host" do
+ it "should return nil" do
+ Puppet.settings.stubs(:value).with(:ca).returns false
+ Puppet.settings.stubs(:value).with(:name).returns "puppetmasterd"
+
+ ca = mock('ca')
+ Puppet::SSL::CertificateAuthority.expects(:new).never
+ Puppet::SSL::CertificateAuthority.instance.should be_nil
+ end
+ end
+
+ describe "and the process name is not 'puppetmasterd'" do
+ it "should return nil" do
+ Puppet.settings.stubs(:value).with(:ca).returns true
+ Puppet.settings.stubs(:value).with(:name).returns "puppetd"
+
+ ca = mock('ca')
+ Puppet::SSL::CertificateAuthority.expects(:new).never
+ Puppet::SSL::CertificateAuthority.instance.should be_nil
+ end
+ end
+ end
+
describe "when initializing" do
before do
Puppet.settings.stubs(:use)
Puppet.settings.stubs(:value).returns "whatever"
- Puppet::SSL::CertificateAuthority.any_instance.stubs(:generate_ca_certificate)
+ Puppet::SSL::CertificateAuthority.any_instance.stubs(:setup)
end
it "should always set its name to the value of :certname" do
@@ -60,6 +117,24 @@ describe Puppet::SSL::CertificateAuthority do
Puppet::SSL::CertificateAuthority.new.inventory.should == "inventory"
end
+
+ it "should make sure the CA is set up" do
+ Puppet::SSL::CertificateAuthority.any_instance.expects(:setup)
+
+ Puppet::SSL::CertificateAuthority.new
+ end
+ end
+
+ describe "when setting itself up" do
+ it "should generate the CA certificate if it does not have one" do
+ host = stub 'host'
+ Puppet::SSL::Host.stubs(:new).returns host
+
+ host.expects(:certificate).returns nil
+
+ Puppet::SSL::CertificateAuthority.any_instance.expects(:generate_ca_certificate)
+ Puppet::SSL::CertificateAuthority.new
+ end
end
describe "when retrieving the certificate revocation list" do
@@ -67,7 +142,7 @@ describe Puppet::SSL::CertificateAuthority do
Puppet.settings.stubs(:use)
Puppet.settings.stubs(:value).returns "whatever"
- Puppet::SSL::CertificateAuthority.any_instance.stubs(:generate_ca_certificate)
+ Puppet::SSL::CertificateAuthority.any_instance.stubs(:setup)
@ca = Puppet::SSL::CertificateAuthority.new
end
@@ -124,6 +199,7 @@ describe Puppet::SSL::CertificateAuthority do
Puppet.settings.stubs(:use)
Puppet.settings.stubs(:value).returns "whatever"
+ Puppet::SSL::CertificateAuthority.any_instance.stubs(:setup)
@ca = Puppet::SSL::CertificateAuthority.new
@host = stub 'host', :key => mock("key"), :name => "hostname"
@@ -298,15 +374,6 @@ describe Puppet::SSL::CertificateAuthority do
@cert.stubs :save
end
- it "should generate a self-signed certificate if its Host instance has no certificate" do
- cert = stub 'ca_certificate', :content => "mock_cert"
-
- @ca.host.expects(:certificate).times(2).returns(nil).then.returns cert
- @ca.expects(:generate_ca_certificate)
-
- @ca.sign(@name)
- end
-
it "should use a certificate type of :server" do
Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
args[0] == :server