~lynxman/ubuntu/precise/puppet/puppetlabsfixbug12844

« back to all changes in this revision

Viewing changes to spec/unit/sslcertificates/ca_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-10-24 15:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20111024150512-yxqwfdp6hcs6of5l
Tags: 2.7.1-1ubuntu3.2
* SECURITY UPDATE: puppet master impersonation via incorrect certificates
  - debian/patches/CVE-2011-3872.patch: refactor certificate handling.
  - Thanks to upstream for providing the patch.
  - CVE-2011-3872

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env rspec
2
 
require 'spec_helper'
3
 
 
4
 
require 'puppet'
5
 
require 'puppet/sslcertificates'
6
 
require 'puppet/sslcertificates/ca'
7
 
 
8
 
describe Puppet::SSLCertificates::CA do
9
 
  before :all do
10
 
    @hosts = %w{host.domain.com Other.Testing.Com}
11
 
  end
12
 
 
13
 
  before :each do
14
 
    Puppet::Util::SUIDManager.stubs(:asuser).yields
15
 
    file = Tempfile.new("ca_testing")
16
 
    @dir = file.path
17
 
    file.delete
18
 
 
19
 
    Puppet.settings[:confdir] = @dir
20
 
    Puppet.settings[:vardir]  = @dir
21
 
 
22
 
    @ca = Puppet::SSLCertificates::CA.new
23
 
  end
24
 
 
25
 
  after :each do
26
 
    system("rm -rf #{@dir}")
27
 
  end
28
 
 
29
 
  describe 'when cleaning' do
30
 
    it 'should remove associated files' do
31
 
      dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
32
 
 
33
 
      @hosts.each do |host|
34
 
        files = []
35
 
        dirs.each do |dir|
36
 
          dir = Puppet[dir]
37
 
 
38
 
          # Case insensitivity is handled through downcasing
39
 
          file = File.join(dir, host.downcase + '.pem')
40
 
 
41
 
          File.open(file, "w") do |f|
42
 
            f.puts "testing"
43
 
          end
44
 
 
45
 
          files << file
46
 
        end
47
 
 
48
 
        lambda { @ca.clean(host) }.should_not raise_error
49
 
 
50
 
        files.reject {|f| ! File.exists?(f)}.should be_empty
51
 
      end
52
 
    end
53
 
  end
54
 
 
55
 
  describe 'when mapping hosts to files' do
56
 
    it 'should correctly return the certfile' do
57
 
      @hosts.each do |host|
58
 
        value = nil
59
 
        lambda { value = @ca.host2certfile host }.should_not raise_error
60
 
 
61
 
        File.join(Puppet[:signeddir], host.downcase + '.pem').should == value
62
 
      end
63
 
    end
64
 
 
65
 
    it 'should correctly return the csrfile' do
66
 
      @hosts.each do |host|
67
 
        value = nil
68
 
        lambda { value = @ca.host2csrfile host }.should_not raise_error
69
 
 
70
 
        File.join(Puppet[:csrdir], host.downcase + '.pem').should == value
71
 
      end
72
 
    end
73
 
  end
74
 
 
75
 
  describe 'when listing' do
76
 
    it 'should find all csr' do
77
 
      list = []
78
 
 
79
 
      # Make some fake CSRs
80
 
      @hosts.each do |host|
81
 
        file = File.join(Puppet[:csrdir], host.downcase + '.pem')
82
 
        File.open(file, 'w') { |f| f.puts "yay" }
83
 
        list << host.downcase
84
 
      end
85
 
 
86
 
      @ca.list.sort.should == list.sort
87
 
    end
88
 
  end
89
 
 
90
 
  describe 'when creating a root certificate' do
91
 
    before :each do
92
 
      lambda { @ca.mkrootcert }.should_not raise_exception
93
 
    end
94
 
 
95
 
    it 'should store the public key' do
96
 
      File.exists?(Puppet[:capub]).should be_true
97
 
    end
98
 
 
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)
106
 
 
107
 
      @ca.mkrootcert.name.should == 'Puppet CA: myhost.puppetlabs.lan'
108
 
    end
109
 
  end
110
 
end