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

« back to all changes in this revision

Viewing changes to spec/integration/indirector/certificate_revocation_list/rest_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas 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
 
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
4
 
 
5
 
require 'puppet/ssl/certificate'
6
 
require 'puppet/network/server'
7
 
require 'puppet/network/http/webrick/rest'
8
 
 
9
 
describe "Certificate REST Terminus" do
10
 
  before do
11
 
    Puppet[:masterport] = 34343
12
 
    Puppet[:server] = "localhost"
13
 
 
14
 
    # Get a safe temporary file
15
 
    @tmpfile = Tempfile.new("webrick_integration_testing")
16
 
    @dir = @tmpfile.path + "_dir"
17
 
 
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"
23
 
 
24
 
    Puppet::Util::Cacher.expire
25
 
 
26
 
    Puppet[:servertype] = 'webrick'
27
 
    Puppet[:server] = '127.0.0.1'
28
 
    Puppet[:certname] = '127.0.0.1'
29
 
 
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])
34
 
 
35
 
    @params = { :port => 34343, :handlers => [ :certificate_revocation_list ] }
36
 
    retries = 0
37
 
    begin
38
 
      @server = Puppet::Network::Server.new(@params)
39
 
      @server.listen
40
 
    rescue Errno::EADDRINUSE => e
41
 
      sleep 0.1
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"
45
 
    end
46
 
 
47
 
    # And make sure we've generated the CRL
48
 
    @crl = ca.crl
49
 
 
50
 
    # Now remove the cached crl
51
 
    Puppet::SSL::Host.ca_location = :none
52
 
    Puppet::SSL::CertificateRevocationList.destroy(Puppet::SSL::CA_NAME)
53
 
 
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
58
 
 
59
 
    # Then switch to a remote CA, so that we go through REST.
60
 
    Puppet::SSL::Host.ca_location = :remote
61
 
 
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
64
 
    # return.
65
 
    @mock_model = stub('faked model', :name => "certificate")
66
 
    Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
67
 
 
68
 
    Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
69
 
  end
70
 
 
71
 
  after do
72
 
    Puppet::Network::HttpPool.expire
73
 
    Puppet::SSL::Host.ca_location = :none
74
 
    Puppet.settings.clear
75
 
    @server.unlisten
76
 
  end
77
 
 
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')
81
 
 
82
 
    # There's no good '==' method on certs.
83
 
    result.content.to_s.should == @crl.content.to_s
84
 
  end
85
 
end