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

« back to all changes in this revision

Viewing changes to spec/unit/ssl/certificate_authority/interface_spec.rb

  • Committer: Benjamin Kerensa
  • Date: 2012-11-21 23:50:52 UTC
  • mfrom: (1.1.30)
  • Revision ID: bkerensa@ubuntu.com-20121121235052-ah7nzabp77sh69gb
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env rspec
 
1
#! /usr/bin/env ruby
2
2
require 'spec_helper'
3
3
 
4
4
require 'puppet/ssl/certificate_authority'
44
44
      interface = @class.new(:generate, :to => :all, :digest => :digest)
45
45
      interface.digest.should == :digest
46
46
    end
47
 
 
48
 
    it "should set the digest to md5 if none given" do
49
 
      interface = @class.new(:generate, :to => :all)
50
 
      interface.digest.should == :MD5
51
 
    end
52
47
  end
53
48
 
54
49
  describe "when setting the method" do
87
82
      @ca = Object.new
88
83
    end
89
84
 
90
 
    it "should raise InterfaceErrors" do
91
 
      @applier = @class.new(:revoke, :to => :all)
92
 
 
93
 
      @ca.expects(:list).raises Puppet::SSL::CertificateAuthority::Interface::InterfaceError
94
 
 
95
 
      lambda { @applier.apply(@ca) }.should raise_error(Puppet::SSL::CertificateAuthority::Interface::InterfaceError)
96
 
    end
97
 
 
98
 
    it "should log non-Interface failures rather than failing" do
99
 
      @applier = @class.new(:revoke, :to => :all)
100
 
 
101
 
      @ca.expects(:list).raises ArgumentError
102
 
 
103
 
      Puppet.expects(:err)
104
 
 
105
 
      lambda { @applier.apply(@ca) }.should_not raise_error
106
 
    end
107
 
 
108
85
    describe "with an empty array specified and the method is not list" do
109
86
      it "should fail" do
110
87
        @applier = @class.new(:sign, :to => [])
205
182
        Puppet::SSL::Certificate.indirection.stubs(:find).returns @cert
206
183
        Puppet::SSL::CertificateRequest.indirection.stubs(:find).returns @csr
207
184
 
 
185
        @digest = mock("digest")
 
186
        @digest.stubs(:to_s).returns("(fingerprint)")
208
187
        @ca.expects(:waiting?).returns %w{host1 host2 host3}
209
188
        @ca.expects(:list).returns %w{host4 host5 host6}
210
 
        @ca.stubs(:fingerprint).returns "fingerprint"
 
189
        @csr.stubs(:digest).returns @digest
 
190
        @cert.stubs(:digest).returns @digest
211
191
        @ca.stubs(:verify)
212
192
      end
213
193
 
331
311
    end
332
312
 
333
313
    describe ":fingerprint" do
 
314
      before(:each) do
 
315
        @cert = Puppet::SSL::Certificate.new 'foo'
 
316
        @csr = Puppet::SSL::CertificateRequest.new 'bar'
 
317
        Puppet::SSL::Certificate.indirection.stubs(:find)
 
318
        Puppet::SSL::CertificateRequest.indirection.stubs(:find)
 
319
        Puppet::SSL::Certificate.indirection.stubs(:find).with('host1').returns(@cert)
 
320
        Puppet::SSL::CertificateRequest.indirection.stubs(:find).with('host2').returns(@csr)
 
321
      end
 
322
 
334
323
      it "should fingerprint with the set digest algorithm" do
335
 
        @applier = @class.new(:fingerprint, :to => %w{host1}, :digest => :digest)
 
324
        @applier = @class.new(:fingerprint, :to => %w{host1}, :digest => :shaonemillion)
 
325
        @cert.expects(:digest).with(:shaonemillion).returns("fingerprint1")
336
326
 
337
 
        @ca.expects(:fingerprint).with("host1", :digest).returns "fingerprint1"
338
327
        @applier.expects(:puts).with "host1 fingerprint1"
339
328
 
340
329
        @applier.apply(@ca)
347
336
 
348
337
          @applier = @class.new(:fingerprint, :to => :all)
349
338
 
350
 
          @ca.expects(:fingerprint).with("host1", :MD5).returns "fingerprint1"
 
339
          @cert.expects(:digest).returns("fingerprint1")
351
340
          @applier.expects(:puts).with "host1 fingerprint1"
352
341
 
353
 
          @ca.expects(:fingerprint).with("host2", :MD5).returns "fingerprint2"
 
342
          @csr.expects(:digest).returns("fingerprint2")
354
343
          @applier.expects(:puts).with "host2 fingerprint2"
355
344
 
356
345
          @applier.apply(@ca)
361
350
        it "should print each named certificate if found" do
362
351
          @applier = @class.new(:fingerprint, :to => %w{host1 host2})
363
352
 
364
 
          @ca.expects(:fingerprint).with("host1", :MD5).returns "fingerprint1"
 
353
          @cert.expects(:digest).returns("fingerprint1")
365
354
          @applier.expects(:puts).with "host1 fingerprint1"
366
355
 
367
 
          @ca.expects(:fingerprint).with("host2", :MD5).returns "fingerprint2"
 
356
          @csr.expects(:digest).returns("fingerprint2")
368
357
          @applier.expects(:puts).with "host2 fingerprint2"
369
358
 
370
359
          @applier.apply(@ca)