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

require 'puppet/ssl/certificate'

class TestCertificate < Puppet::SSL::Base; end

describe Puppet::SSL::Certificate do
  before :each do
    @base = TestCertificate.new("name")
  end

  describe "when fingerprinting content" do
    before :each do
      @cert = stub 'cert', :to_der => "DER"
      @base.stubs(:content).returns(@cert)
      OpenSSL::Digest.stubs(:constants).returns ["MD5", "DIGEST"]
      @digest = stub_everything
      OpenSSL::Digest.stubs(:const_get).returns @digest
    end

    it "should digest the certificate DER value and return a ':' seperated nibblet string" do
      @cert.expects(:to_der).returns("DER")
      @digest.expects(:hexdigest).with("DER").returns "digest"

      @base.fingerprint.should == "DI:GE:ST"
    end

    it "should raise an error if the digest algorithm is not defined" do
      OpenSSL::Digest.expects(:constants).returns []

      lambda { @base.fingerprint }.should raise_error
    end

    it "should use the given digest algorithm" do
      OpenSSL::Digest.stubs(:const_get).with("DIGEST").returns @digest
      @digest.expects(:hexdigest).with("DER").returns "digest"

      @base.fingerprint(:digest).should == "DI:GE:ST"
    end
  end
end