summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2010-09-21 13:28:24 -0700
committerMarkus Roberts <Markus@reality.com>2010-09-28 15:36:23 -0700
commitd54352a0cc305cfada05d9ecb927e79957c8d744 (patch)
tree0512006cabf59ccdbb28516177821f460792f22a /spec
parenteffc6b8e292992d2df1d321b5d5bf68208db6b24 (diff)
downloadpuppet-d54352a0cc305cfada05d9ecb927e79957c8d744.tar.gz
puppet-d54352a0cc305cfada05d9ecb927e79957c8d744.tar.xz
puppet-d54352a0cc305cfada05d9ecb927e79957c8d744.zip
Port Puppet::SSLCertificates::CA test to rspec
Signed-off-by: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/sslcertificates/ca_spec.rb99
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/unit/sslcertificates/ca_spec.rb b/spec/unit/sslcertificates/ca_spec.rb
new file mode 100644
index 000000000..aa7e25ff3
--- /dev/null
+++ b/spec/unit/sslcertificates/ca_spec.rb
@@ -0,0 +1,99 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'puppet'
+require 'puppet/sslcertificates'
+require 'puppet/sslcertificates/ca'
+
+describe Puppet::SSLCertificates::CA do
+ before :all do
+ @hosts = %w{host.domain.com Other.Testing.Com}
+ end
+
+ before :each do
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
+ file = Tempfile.new("ca_testing")
+ @dir = file.path
+ file.delete
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+
+ @ca = Puppet::SSLCertificates::CA.new
+ end
+
+ after :each do
+ system("rm -rf #{@dir}")
+ end
+
+ describe 'when cleaning' do
+ it 'should remove associated files' do
+ dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
+
+ @hosts.each do |host|
+ files = []
+ dirs.each do |dir|
+ dir = Puppet[dir]
+
+ # Case insensitivity is handled through downcasing
+ file = File.join(dir, host.downcase + '.pem')
+
+ File.open(file, "w") do |f|
+ f.puts "testing"
+ end
+
+ files << file
+ end
+
+ lambda { @ca.clean(host) }.should_not raise_error
+
+ files.reject {|f| ! File.exists?(f)}.should be_empty
+ end
+ end
+ end
+
+ describe 'when mapping hosts to files' do
+ it 'should correctly return the certfile' do
+ @hosts.each do |host|
+ value = nil
+ lambda { value = @ca.host2certfile host }.should_not raise_error
+
+ File.join(Puppet[:signeddir], host.downcase + '.pem').should == value
+ end
+ end
+
+ it 'should correctly return the csrfile' do
+ @hosts.each do |host|
+ value = nil
+ lambda { value = @ca.host2csrfile host }.should_not raise_error
+
+ File.join(Puppet[:csrdir], host.downcase + '.pem').should == value
+ end
+ end
+ end
+
+ describe 'when listing' do
+ it 'should find all csr' do
+ list = []
+
+ # Make some fake CSRs
+ @hosts.each do |host|
+ file = File.join(Puppet[:csrdir], host.downcase + '.pem')
+ File.open(file, 'w') { |f| f.puts "yay" }
+ list << host.downcase
+ end
+
+ @ca.list.sort.should == list.sort
+ end
+ end
+
+ describe 'when creating a root certificate' do
+ before :each do
+ lambda { @ca.mkrootcert }.should_not raise_exception
+ end
+
+ it 'should store the public key' do
+ File.exists?(Puppet[:capub]).should be_true
+ end
+ end
+end