summaryrefslogtreecommitdiffstats
path: root/spec/integration/ssl/certificate_request_spec.rb
blob: bcfcd2b438170893a1fe356fae94603c040ec74f (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
#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/ssl/certificate_request'

# REMIND: Fails on windows because there is no user provider yet
describe Puppet::SSL::CertificateRequest, :fails_on_windows => true do
  include PuppetSpec::Files

  before do
    # Get a safe temporary file
    dir = tmpdir("csr_integration_testing")

    Puppet.settings.clear

    Puppet.settings[:confdir] = dir
    Puppet.settings[:vardir] = dir
    Puppet.settings[:group] = Process.gid

    Puppet::SSL::Host.ca_location = :none

    @csr = Puppet::SSL::CertificateRequest.new("luke.madstop.com")

    @key = OpenSSL::PKey::RSA.new(512)

    # This is necessary so the terminus instances don't lie around.
    Puppet::SSL::CertificateRequest.indirection.termini.clear
  end

  after do
    Puppet.settings.clear
  end

  it "should be able to generate CSRs" do
    @csr.generate(@key)
  end

  it "should be able to save CSRs" do
    Puppet::SSL::CertificateRequest.indirection.save(@csr)
  end

  it "should be able to find saved certificate requests via the Indirector" do
    @csr.generate(@key)
    Puppet::SSL::CertificateRequest.indirection.save(@csr)

    Puppet::SSL::CertificateRequest.indirection.find("luke.madstop.com").should be_instance_of(Puppet::SSL::CertificateRequest)
  end

  it "should save the completely CSR when saving" do
    @csr.generate(@key)
    Puppet::SSL::CertificateRequest.indirection.save(@csr)

    Puppet::SSL::CertificateRequest.indirection.find("luke.madstop.com").content.to_s.should == @csr.content.to_s
  end
end