5
require 'puppet/sslcertificates'
6
require 'puppet/sslcertificates/ca'
8
describe Puppet::SSLCertificates::CA do
10
@hosts = %w{host.domain.com Other.Testing.Com}
14
Puppet::Util::SUIDManager.stubs(:asuser).yields
15
file = Tempfile.new("ca_testing")
19
Puppet.settings[:confdir] = @dir
20
Puppet.settings[:vardir] = @dir
22
@ca = Puppet::SSLCertificates::CA.new
26
system("rm -rf #{@dir}")
29
describe 'when cleaning' do
30
it 'should remove associated files' do
31
dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
38
# Case insensitivity is handled through downcasing
39
file = File.join(dir, host.downcase + '.pem')
41
File.open(file, "w") do |f|
48
lambda { @ca.clean(host) }.should_not raise_error
50
files.reject {|f| ! File.exists?(f)}.should be_empty
55
describe 'when mapping hosts to files' do
56
it 'should correctly return the certfile' do
59
lambda { value = @ca.host2certfile host }.should_not raise_error
61
File.join(Puppet[:signeddir], host.downcase + '.pem').should == value
65
it 'should correctly return the csrfile' do
68
lambda { value = @ca.host2csrfile host }.should_not raise_error
70
File.join(Puppet[:csrdir], host.downcase + '.pem').should == value
75
describe 'when listing' do
76
it 'should find all csr' do
81
file = File.join(Puppet[:csrdir], host.downcase + '.pem')
82
File.open(file, 'w') { |f| f.puts "yay" }
86
@ca.list.sort.should == list.sort
90
describe 'when creating a root certificate' do
92
lambda { @ca.mkrootcert }.should_not raise_exception
95
it 'should store the public key' do
96
File.exists?(Puppet[:capub]).should be_true
99
it 'should prepend "Puppet CA: " to the fqdn as the ca_name by default' do
100
host_mock_fact = mock()
101
host_mock_fact.expects(:value).returns('myhost')
102
domain_mock_fact = mock()
103
domain_mock_fact.expects(:value).returns('puppetlabs.lan')
104
Facter.stubs(:[]).with('hostname').returns(host_mock_fact)
105
Facter.stubs(:[]).with('domain').returns(domain_mock_fact)
107
@ca.mkrootcert.name.should == 'Puppet CA: myhost.puppetlabs.lan'