summaryrefslogtreecommitdiffstats
path: root/test/executables/puppetca.rb
blob: b69edb314c3a8b201158c28096f899b8334741a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
if __FILE__ == $0
    $:.unshift '../../lib'
    $:.unshift '..'
    $puppetbase = "../.."
end

require 'puppet'
require 'puppet/server'
require 'puppet/sslcertificates'
require 'test/unit'
require 'puppettest.rb'

class TestPuppetCA < Test::Unit::TestCase
	include ExeTest
    def mkcert(hostname)
        cert = nil
        assert_nothing_raised {
            cert = Puppet::SSLCertificates::Certificate.new(
                :name => hostname
            )
            cert.mkcsr
        }

        return cert
    end

    def test_signing
        ca = nil
        Puppet[:ssldir] = tempfile()
        @@tmpfiles << Puppet[:ssldir]
        Puppet[:autosign] = false
        assert_nothing_raised {
            ca = Puppet::Server::CA.new()
        }
        #Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
        #system("find %s" % Puppet[:ssldir])

        cert = mkcert("host.test.com")
        resp = nil
        assert_nothing_raised {
            # We need to use a fake name so it doesn't think the cert is from
            # itself.
            resp = ca.getcert(cert.csr.to_pem, "fakename", "127.0.0.1")
        }
        assert_equal(["",""], resp)
        #Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
        #system("find %s" % Puppet[:ssldir])

        output = nil
        assert_nothing_raised {
            output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n").reject { |line| line =~ /warning:/ } # stupid ssl.rb
        }
        #Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
        #system("find %s" % Puppet[:ssldir])
        assert_equal($?,0)
        assert_equal(%w{host.test.com}, output)
        assert_nothing_raised {
            output = %x{puppetca --sign -a --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n")
        }
        assert_equal($?,0)
        assert_equal([], output)
        assert_nothing_raised {
            output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n")
        }
        assert_equal($?,0)
        assert_equal([], output)
    end
end

# $Id$