summaryrefslogtreecommitdiffstats
path: root/spec/unit/ssl/certificate_factory_spec.rb
blob: f34dafe4371dc29c8293cddba5e9b5ca8966bb69 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/ssl/certificate_factory'

describe Puppet::SSL::CertificateFactory do
  before do
    @cert_type = mock 'cert_type'
    @name = mock 'name'
    @csr = stub 'csr', :subject => @name
    @issuer = mock 'issuer'
    @serial = mock 'serial'

    @factory = Puppet::SSL::CertificateFactory.new(@cert_type, @csr, @issuer, @serial)
  end

  describe "when initializing" do
    it "should set its :cert_type to its first argument" do
      @factory.cert_type.should equal(@cert_type)
    end

    it "should set its :csr to its second argument" do
      @factory.csr.should equal(@csr)
    end

    it "should set its :issuer to its third argument" do
      @factory.issuer.should equal(@issuer)
    end

    it "should set its :serial to its fourth argument" do
      @factory.serial.should equal(@serial)
    end

    it "should set its name to the subject of the csr" do
      @factory.name.should equal(@name)
    end
  end

  describe "when generating the certificate" do
    before do
      @cert = mock 'cert'

      @cert.stub_everything

      @factory.stubs :build_extensions

      @factory.stubs :set_ttl

      @issuer_name = mock 'issuer_name'
      @issuer.stubs(:subject).returns @issuer_name

      @public_key = mock 'public_key'
      @csr.stubs(:public_key).returns @public_key

      OpenSSL::X509::Certificate.stubs(:new).returns @cert
    end

    it "should return a new X509 certificate" do
      OpenSSL::X509::Certificate.expects(:new).returns @cert
      @factory.result.should equal(@cert)
    end

    it "should set the certificate's version to 2" do
      @cert.expects(:version=).with 2
      @factory.result
    end

    it "should set the certificate's subject to the CSR's subject" do
      @cert.expects(:subject=).with @name
      @factory.result
    end

    it "should set the certificate's issuer to the Issuer's subject" do
      @cert.expects(:issuer=).with @issuer_name
      @factory.result
    end

    it "should set the certificate's public key to the CSR's public key" do
      @cert.expects(:public_key=).with @public_key
      @factory.result
    end

    it "should set the certificate's serial number to the provided serial number" do
      @cert.expects(:serial=).with @serial
      @factory.result
    end

    it "should build extensions for the certificate" do
      @factory.expects(:build_extensions)
      @factory.result
    end

    it "should set the ttl of the certificate" do
      @factory.expects(:set_ttl)
      @factory.result
    end
  end

  describe "when building extensions" do
    it "should have tests"
  end

  describe "when setting the ttl" do
    it "should have tests"
  end
end