~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to test/certmgr/ca.rb

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2010-10-21 12:52:13 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20101021125213-x5pjaatmuv0i79jv
Tags: 2.6.3~rc1-0ubuntu1
* New upstream version
* debian/control:
  - move all puppet dependencies to puppet-common since all the code is
    actually located in puppet-common. 
  - move libaugeas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
require File.dirname(__FILE__) + '/../lib/puppettest'
4
 
 
5
 
require 'puppet'
6
 
require 'puppet/sslcertificates/ca.rb'
7
 
require 'puppettest'
8
 
require 'puppettest/certificates'
9
 
require 'mocha'
10
 
 
11
 
class TestCA < Test::Unit::TestCase
12
 
  include PuppetTest
13
 
 
14
 
  def setup
15
 
    super
16
 
    Puppet::Util::SUIDManager.stubs(:asuser).yields
17
 
  end
18
 
 
19
 
  def hosts
20
 
    %w{host.domain.com Other.Testing.Com}
21
 
  end
22
 
  def mkca
23
 
    Puppet::SSLCertificates::CA.new
24
 
  end
25
 
 
26
 
  def test_clean
27
 
    dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
28
 
    ca = mkca
29
 
 
30
 
    hosts.each do |host|
31
 
      files = []
32
 
      dirs.each do |dir|
33
 
        dir = Puppet[dir]
34
 
        # We handle case insensitivity through downcasing
35
 
        file = File.join(dir, host.downcase + ".pem")
36
 
        File.open(file, "w") do |f|
37
 
          f.puts "testing"
38
 
        end
39
 
        files << file
40
 
      end
41
 
      assert_nothing_raised do
42
 
        ca.clean(host)
43
 
      end
44
 
      files.each do |f|
45
 
        assert(! FileTest.exists?(f), "File #{f} was not deleted")
46
 
      end
47
 
    end
48
 
  end
49
 
 
50
 
  def test_host2Xfile
51
 
    ca = mkca
52
 
    hosts.each do |host|
53
 
      {:signeddir => :host2certfile, :csrdir => :host2csrfile}.each do |dir, method|
54
 
        val = nil
55
 
        assert_nothing_raised do
56
 
          val = ca.send(method, host)
57
 
        end
58
 
        assert_equal(File.join(Puppet[dir], host.downcase + ".pem"), val,
59
 
          "incorrect response from #{method}")
60
 
      end
61
 
    end
62
 
  end
63
 
 
64
 
  def test_list
65
 
    ca = mkca
66
 
    # Make a fake csr
67
 
    dir = Puppet[:csrdir]
68
 
    list = []
69
 
    hosts.each do |host|
70
 
      file = File.join(dir, host.downcase + ".pem")
71
 
      File.open(file, "w") { |f| f.puts "yay" }
72
 
      list << host.downcase
73
 
    end
74
 
 
75
 
    assert_equal(list.sort, ca.list.sort, "list was not correct")
76
 
  end
77
 
 
78
 
  # #142 - test storing the public key
79
 
  def test_store_public_key
80
 
    ca = mkca
81
 
    assert_nothing_raised do
82
 
      ca.mkrootcert
83
 
    end
84
 
    assert(FileTest.exists?(Puppet[:capub]), "did not store public key")
85
 
  end
86
 
end
87