diff options
| author | Luke Kanies <luke@madstop.com> | 2008-03-19 17:50:09 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-04-15 21:34:05 -0500 |
| commit | 1efed0304ebdc13a55eb2d865cdc4965c5253d3a (patch) | |
| tree | b571ac1f93e07f01a0d52bae47cd641916cc8571 /spec | |
| parent | ee07d0b7f198857f700b9ad09713fe6b992ffee8 (diff) | |
| download | puppet-1efed0304ebdc13a55eb2d865cdc4965c5253d3a.tar.gz puppet-1efed0304ebdc13a55eb2d865cdc4965c5253d3a.tar.xz puppet-1efed0304ebdc13a55eb2d865cdc4965c5253d3a.zip | |
Adding tests for the easy bits of the CertificateFactory.
I probably am going to skip the tests for the rest, since
the code is unlikely to ever change, and it's going to be
a royal pain to test.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/ssl/certificate_factory.rb | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/unit/ssl/certificate_factory.rb b/spec/unit/ssl/certificate_factory.rb new file mode 100755 index 000000000..822b330f2 --- /dev/null +++ b/spec/unit/ssl/certificate_factory.rb @@ -0,0 +1,107 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/ssl/certificate_factory' + +describe Puppet::SSL::CertificateFactory do + before do + @cert_type = mock 'cert_type' + @name = mock 'name' + @csr = stub 'csr', :subject => @name + @issuer = mock 'issuer' + @serial = mock 'serial' + + @factory = Puppet::SSL::CertificateFactory.new(@cert_type, @csr, @issuer, @serial) + end + + describe "when initializing" do + it "should set its :cert_type to its first argument" do + @factory.cert_type.should equal(@cert_type) + end + + it "should set its :csr to its second argument" do + @factory.csr.should equal(@csr) + end + + it "should set its :issuer to its third argument" do + @factory.issuer.should equal(@issuer) + end + + it "should set its :serial to its fourth argument" do + @factory.serial.should equal(@serial) + end + + it "should set its name to the subject of the csr" do + @factory.name.should equal(@name) + end + end + + describe "when generating the certificate" do + before do + @cert = mock 'cert' + + @cert.stub_everything + + @factory.stubs :build_extensions + + @factory.stubs :set_ttl + + @issuer_name = mock 'issuer_name' + @issuer.stubs(:subject).returns @issuer_name + + @public_key = mock 'public_key' + @csr.stubs(:public_key).returns @public_key + + OpenSSL::X509::Certificate.stubs(:new).returns @cert + end + + it "should return a new X509 certificate" do + OpenSSL::X509::Certificate.expects(:new).returns @cert + @factory.result.should equal(@cert) + end + + it "should set the certificate's version to 2" do + @cert.expects(:version=).with 2 + @factory.result + end + + it "should set the certificate's subject to the CSR's subject" do + @cert.expects(:subject=).with @name + @factory.result + end + + it "should set the certificate's issuer to the Issuer's subject" do + @cert.expects(:issuer=).with @issuer_name + @factory.result + end + + it "should set the certificate's public key to the CSR's public key" do + @cert.expects(:public_key=).with @public_key + @factory.result + end + + it "should set the certificate's serial number to the provided serial number" do + @cert.expects(:serial=).with @serial + @factory.result + end + + it "should build extensions for the certificate" do + @factory.expects(:build_extensions) + @factory.result + end + + it "should set the ttl of the certificate" do + @factory.expects(:set_ttl) + @factory.result + end + end + + describe "when building extensions" do + it "should have tests" + end + + describe "when setting the ttl" do + it "should have tests" + end +end |
