~lynxman/ubuntu/precise/puppet/puppetlabsfixbug12844

« back to all changes in this revision

Viewing changes to test/certmgr/inventory.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 ruby
2
 
 
3
 
require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
4
 
 
5
 
require 'puppet'
6
 
require 'puppettest/certificates'
7
 
require 'puppet/sslcertificates/inventory.rb'
8
 
require 'mocha'
9
 
 
10
 
class TestCertInventory < Test::Unit::TestCase
11
 
  include PuppetTest::Certificates
12
 
 
13
 
  Inventory = Puppet::SSLCertificates::Inventory
14
 
 
15
 
  def setup
16
 
    super
17
 
    Puppet::Util::SUIDManager.stubs(:asuser).yields
18
 
  end
19
 
 
20
 
  def test_format
21
 
    cert = mksignedcert
22
 
 
23
 
    format = nil
24
 
    assert_nothing_raised do
25
 
      format = Inventory.format(cert)
26
 
    end
27
 
 
28
 
 
29
 
      assert(
30
 
        format =~ /^0x0001 \S+ \S+ #{cert.subject}/,
31
 
 
32
 
        "Did not create correct format")
33
 
    end
34
 
 
35
 
  def test_init
36
 
    # First create a couple of certificates
37
 
    ca = mkCA
38
 
 
39
 
    cert1 = mksignedcert(ca, "host1.madstop.com")
40
 
    cert2 = mksignedcert(ca, "host2.madstop.com")
41
 
 
42
 
    init = nil
43
 
    assert_nothing_raised do
44
 
      init = Inventory.init
45
 
    end
46
 
 
47
 
    [cert1, cert2].each do |cert|
48
 
      assert(init.include?(cert.subject.to_s), "Did not catch #{cert.subject}")
49
 
    end
50
 
  end
51
 
 
52
 
  def test_add
53
 
    ca = mkCA
54
 
    cert = mksignedcert(ca, "host.domain.com")
55
 
 
56
 
    assert_nothing_raised do
57
 
      file = mock
58
 
      file.expects(:puts).with do |written|
59
 
        written.include? cert.subject.to_s
60
 
      end
61
 
      Puppet::Util::Settings.any_instance.stubs(:write)
62
 
      Puppet::Util::Settings.any_instance.expects(:write).
63
 
        with(:cert_inventory, 'a').yields(file)
64
 
 
65
 
      Puppet::SSLCertificates::Inventory.add(cert)
66
 
    end
67
 
  end
68
 
end
69