3
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
5
require 'puppet/ssl/certificate'
6
require 'puppet/network/server'
7
require 'puppet/network/http/webrick/rest'
9
describe "Certificate REST Terminus" do
11
Puppet[:masterport] = 34343
12
Puppet[:server] = "localhost"
14
# Get a safe temporary file
15
@tmpfile = Tempfile.new("webrick_integration_testing")
16
@dir = @tmpfile.path + "_dir"
18
Puppet.settings[:confdir] = @dir
19
Puppet.settings[:vardir] = @dir
20
Puppet.settings[:group] = Process.gid
21
Puppet.settings[:server] = "127.0.0.1"
22
Puppet.settings[:masterport] = "34343"
24
Puppet::Util::Cacher.expire
26
Puppet[:servertype] = 'webrick'
27
Puppet[:server] = '127.0.0.1'
28
Puppet[:certname] = '127.0.0.1'
30
# Generate the certificate with a local CA
31
Puppet::SSL::Host.ca_location = :local
32
ca = Puppet::SSL::CertificateAuthority.new
33
ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
35
@params = { :port => 34343, :handlers => [ :certificate_revocation_list ] }
38
@server = Puppet::Network::Server.new(@params)
40
rescue Errno::EADDRINUSE => e
42
puts "Port 34343 is in use; waiting for it to be free" if retries == 50
43
retry if (retries += 1) < 100
44
pending "Can't run too many simultaneous tests"
47
# And make sure we've generated the CRL
50
# Now remove the cached crl
51
Puppet::SSL::Host.ca_location = :none
52
Puppet::SSL::CertificateRevocationList.destroy(Puppet::SSL::CA_NAME)
54
# This is necessary so that we create the SSL store before we start
55
# using REST. This is necessary to prevent an infinite loop,
56
# which only occurs during testing.
57
Puppet::Network::HttpPool.ssl_host.ssl_store
59
# Then switch to a remote CA, so that we go through REST.
60
Puppet::SSL::Host.ca_location = :remote
62
# LAK:NOTE We need to have a fake model here so that our indirected methods get
63
# passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
65
@mock_model = stub('faked model', :name => "certificate")
66
Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
68
Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
72
Puppet::Network::HttpPool.expire
73
Puppet::SSL::Host.ca_location = :none
78
it "should be able to retrieve a remote CRL" do
79
@mock_model.expects(:find).returns @crl
80
result = Puppet::SSL::CertificateRevocationList.find('bar')
82
# There's no good '==' method on certs.
83
result.content.to_s.should == @crl.content.to_s