puppet 2.6.11 → 2.6.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (67) hide show
  1. data/CHANGELOG +33 -0
  2. data/conf/redhat/puppet.spec +7 -4
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application/cert.rb +17 -3
  5. data/lib/puppet/application/kick.rb +0 -2
  6. data/lib/puppet/defaults.rb +52 -3
  7. data/lib/puppet/network/handler/ca.rb +16 -106
  8. data/lib/puppet/network/handler/master.rb +0 -3
  9. data/lib/puppet/network/handler/runner.rb +1 -0
  10. data/lib/puppet/ssl/certificate.rb +6 -0
  11. data/lib/puppet/ssl/certificate_authority.rb +86 -11
  12. data/lib/puppet/ssl/certificate_authority/interface.rb +64 -19
  13. data/lib/puppet/ssl/certificate_factory.rb +112 -91
  14. data/lib/puppet/ssl/certificate_request.rb +88 -1
  15. data/lib/puppet/ssl/host.rb +16 -3
  16. data/lib/puppet/type/file.rb +0 -1
  17. data/lib/puppet/util/command_line/puppetca +23 -2
  18. data/lib/puppet/util/monkey_patches.rb +69 -0
  19. data/lib/puppet/util/settings.rb +5 -0
  20. data/spec/integration/defaults_spec.rb +11 -0
  21. data/spec/integration/network/handler_spec.rb +1 -1
  22. data/spec/unit/configurer_spec.rb +2 -2
  23. data/spec/unit/network/handler/ca_spec.rb +86 -0
  24. data/spec/unit/ssl/certificate_authority/interface_spec.rb +92 -53
  25. data/spec/unit/ssl/certificate_authority_spec.rb +133 -23
  26. data/spec/unit/ssl/certificate_factory_spec.rb +90 -70
  27. data/spec/unit/ssl/certificate_request_spec.rb +62 -1
  28. data/spec/unit/ssl/certificate_spec.rb +31 -0
  29. data/spec/unit/ssl/host_spec.rb +44 -2
  30. data/spec/unit/util/settings_spec.rb +10 -0
  31. data/test/language/functions.rb +0 -1
  32. data/test/language/snippets.rb +0 -9
  33. data/test/lib/puppettest/exetest.rb +1 -1
  34. data/test/lib/puppettest/servertest.rb +0 -1
  35. data/test/rails/rails.rb +0 -1
  36. data/test/ral/type/filesources.rb +0 -60
  37. metadata +5 -34
  38. data/lib/puppet/network/client.rb +0 -179
  39. data/lib/puppet/network/client/ca.rb +0 -56
  40. data/lib/puppet/network/client/file.rb +0 -6
  41. data/lib/puppet/network/client/proxy.rb +0 -27
  42. data/lib/puppet/network/client/report.rb +0 -26
  43. data/lib/puppet/network/client/runner.rb +0 -10
  44. data/lib/puppet/network/client/status.rb +0 -4
  45. data/lib/puppet/network/http_server.rb +0 -3
  46. data/lib/puppet/network/http_server/mongrel.rb +0 -150
  47. data/lib/puppet/network/http_server/webrick.rb +0 -155
  48. data/lib/puppet/network/xmlrpc/client.rb +0 -211
  49. data/lib/puppet/sslcertificates.rb +0 -146
  50. data/lib/puppet/sslcertificates/ca.rb +0 -375
  51. data/lib/puppet/sslcertificates/certificate.rb +0 -255
  52. data/lib/puppet/sslcertificates/inventory.rb +0 -38
  53. data/lib/puppet/sslcertificates/monkey_patch.rb +0 -6
  54. data/lib/puppet/sslcertificates/support.rb +0 -146
  55. data/spec/integration/network/client_spec.rb +0 -19
  56. data/spec/unit/network/client_spec.rb +0 -45
  57. data/spec/unit/network/xmlrpc/client_spec.rb +0 -172
  58. data/spec/unit/sslcertificates/ca_spec.rb +0 -110
  59. data/test/certmgr/certmgr.rb +0 -308
  60. data/test/certmgr/inventory.rb +0 -69
  61. data/test/certmgr/support.rb +0 -105
  62. data/test/network/client/ca.rb +0 -69
  63. data/test/network/client/dipper.rb +0 -34
  64. data/test/network/handler/ca.rb +0 -273
  65. data/test/network/server/mongrel_test.rb +0 -99
  66. data/test/network/server/webrick.rb +0 -128
  67. data/test/network/xmlrpc/client.rb +0 -45
@@ -200,8 +200,9 @@ describe Puppet::SSL::CertificateAuthority do
200
200
  request = mock 'request'
201
201
  Puppet::SSL::CertificateRequest.expects(:new).with(@ca.host.name).returns request
202
202
  request.expects(:generate).with(@ca.host.key)
203
+ request.stubs(:request_extensions => [])
203
204
 
204
- @ca.expects(:sign).with(@host.name, :ca, request)
205
+ @ca.expects(:sign).with(@host.name, false, request)
205
206
 
206
207
  @ca.stubs :generate_password
207
208
 
@@ -243,10 +244,10 @@ describe Puppet::SSL::CertificateAuthority do
243
244
  @cert.stubs(:save)
244
245
 
245
246
  # Stub out the factory
246
- @factory = stub 'factory', :result => "my real cert"
247
- Puppet::SSL::CertificateFactory.stubs(:new).returns @factory
247
+ Puppet::SSL::CertificateFactory.stubs(:build).returns "my real cert"
248
248
 
249
- @request = stub 'request', :content => "myrequest", :name => @name
249
+ @request_content = stub "request content stub", :subject => @name
250
+ @request = stub 'request', :name => @name, :request_extensions => [], :subject_alt_names => [], :content => @request_content
250
251
 
251
252
  # And the inventory
252
253
  @inventory = stub 'inventory', :add => nil
@@ -297,37 +298,45 @@ describe Puppet::SSL::CertificateAuthority do
297
298
  it "should not look up a certificate request for the host" do
298
299
  Puppet::SSL::CertificateRequest.expects(:find).never
299
300
 
300
- @ca.sign(@name, :ca, @request)
301
+ @ca.sign(@name, true, @request)
301
302
  end
302
303
 
303
304
  it "should use a certificate type of :ca" do
304
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
305
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
305
306
  args[0] == :ca
306
- end.returns @factory
307
+ end.returns "my real cert"
307
308
  @ca.sign(@name, :ca, @request)
308
309
  end
309
310
 
310
311
  it "should pass the provided CSR as the CSR" do
311
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
312
- args[1] == "myrequest"
313
- end.returns @factory
312
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
313
+ args[1] == @request
314
+ end.returns "my real cert"
314
315
  @ca.sign(@name, :ca, @request)
315
316
  end
316
317
 
317
318
  it "should use the provided CSR's content as the issuer" do
318
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
319
- args[2] == "myrequest"
320
- end.returns @factory
319
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
320
+ args[2].subject == "myhost"
321
+ end.returns "my real cert"
321
322
  @ca.sign(@name, :ca, @request)
322
323
  end
323
324
 
324
325
  it "should pass the next serial as the serial number" do
325
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
326
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
326
327
  args[3] == @serial
327
- end.returns @factory
328
+ end.returns "my real cert"
328
329
  @ca.sign(@name, :ca, @request)
329
330
  end
330
331
 
332
+ it "should sign the certificate request even if it contains alt names" do
333
+ @request.stubs(:subject_alt_names).returns %w[DNS:foo DNS:bar DNS:baz]
334
+
335
+ expect do
336
+ @ca.sign(@name, false, @request)
337
+ end.should_not raise_error(Puppet::SSL::CertificateAuthority::CertificateSigningError)
338
+ end
339
+
331
340
  it "should save the resulting certificate" do
332
341
  @cert.expects(:save)
333
342
 
@@ -345,9 +354,9 @@ describe Puppet::SSL::CertificateAuthority do
345
354
  end
346
355
 
347
356
  it "should use a certificate type of :server" do
348
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
357
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
349
358
  args[0] == :server
350
- end.returns @factory
359
+ end.returns "my real cert"
351
360
 
352
361
  @ca.sign(@name)
353
362
  end
@@ -364,17 +373,45 @@ describe Puppet::SSL::CertificateAuthority do
364
373
  lambda { @ca.sign(@name) }.should raise_error(ArgumentError)
365
374
  end
366
375
 
376
+ it "should fail if an unknown request extension is present" do
377
+ @request.stubs :request_extensions => [{ "oid" => "bananas",
378
+ "value" => "delicious" }]
379
+ expect { @ca.sign(@name) }.
380
+ should raise_error(/CSR has request extensions that are not permitted/)
381
+ end
382
+
383
+ it "should fail if the CSR contains alt names and they are not expected" do
384
+ @request.stubs(:subject_alt_names).returns %w[DNS:foo DNS:bar DNS:baz]
385
+
386
+ expect do
387
+ @ca.sign(@name, false)
388
+ end.to raise_error(Puppet::SSL::CertificateAuthority::CertificateSigningError, /CSR '#{@name}' contains subject alternative names \(.*?\), which are disallowed. Use `puppet cert --allow-dns-alt-names sign #{@name}` to sign this request./)
389
+ end
390
+
391
+ it "should not fail if the CSR does not contain alt names and they are expected" do
392
+ @request.stubs(:subject_alt_names).returns []
393
+ expect { @ca.sign(@name, true) }.should_not raise_error
394
+ end
395
+
396
+ it "should reject alt names by default" do
397
+ @request.stubs(:subject_alt_names).returns %w[DNS:foo DNS:bar DNS:baz]
398
+
399
+ expect do
400
+ @ca.sign(@name)
401
+ end.to raise_error(Puppet::SSL::CertificateAuthority::CertificateSigningError, /CSR '#{@name}' contains subject alternative names \(.*?\), which are disallowed. Use `puppet cert --allow-dns-alt-names sign #{@name}` to sign this request./)
402
+ end
403
+
367
404
  it "should use the CA certificate as the issuer" do
368
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
405
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
369
406
  args[2] == @cacert.content
370
- end.returns @factory
407
+ end.returns "my real cert"
371
408
  @ca.sign(@name)
372
409
  end
373
410
 
374
411
  it "should pass the next serial as the serial number" do
375
- Puppet::SSL::CertificateFactory.expects(:new).with do |*args|
412
+ Puppet::SSL::CertificateFactory.expects(:build).with do |*args|
376
413
  args[3] == @serial
377
- end.returns @factory
414
+ end.returns "my real cert"
378
415
  @ca.sign(@name)
379
416
  end
380
417
 
@@ -399,6 +436,80 @@ describe Puppet::SSL::CertificateAuthority do
399
436
 
400
437
  @ca.sign(@name)
401
438
  end
439
+
440
+ it "should check the internal signing policies" do
441
+ @ca.expects(:check_internal_signing_policies).returns true
442
+ @ca.sign(@name)
443
+ end
444
+ end
445
+
446
+ context "#check_internal_signing_policies" do
447
+ before do
448
+ @serial = 10
449
+ @ca.stubs(:next_serial).returns @serial
450
+
451
+ Puppet::SSL::CertificateRequest.stubs(:find).with(@name).returns @request
452
+ @cert.stubs :save
453
+ end
454
+
455
+ it "should reject a critical extension that isn't on the whitelist" do
456
+ @request.stubs(:request_extensions).returns [{ "oid" => "banana",
457
+ "value" => "yumm",
458
+ "critical" => true }]
459
+ expect { @ca.sign(@name) }.to raise_error(
460
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
461
+ /request extensions that are not permitted/
462
+ )
463
+ end
464
+
465
+ it "should reject a non-critical extension that isn't on the whitelist" do
466
+ @request.stubs(:request_extensions).returns [{ "oid" => "peach",
467
+ "value" => "meh",
468
+ "critical" => false }]
469
+ expect { @ca.sign(@name) }.to raise_error(
470
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
471
+ /request extensions that are not permitted/
472
+ )
473
+ end
474
+
475
+ it "should reject non-whitelist extensions even if a valid extension is present" do
476
+ @request.stubs(:request_extensions).returns [{ "oid" => "peach",
477
+ "value" => "meh",
478
+ "critical" => false },
479
+ { "oid" => "subjectAltName",
480
+ "value" => "DNS:foo",
481
+ "critical" => true }]
482
+ expect { @ca.sign(@name) }.to raise_error(
483
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
484
+ /request extensions that are not permitted/
485
+ )
486
+ end
487
+
488
+ it "should reject a subjectAltName for a non-DNS value" do
489
+ @request.stubs(:subject_alt_names).returns ['DNS:foo', 'email:bar@example.com']
490
+ expect { @ca.sign(@name, true) }.to raise_error(
491
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
492
+ /subjectAltName outside the DNS label space/
493
+ )
494
+ end
495
+
496
+ it "should reject a wildcard subject" do
497
+ @request.content.stubs(:subject).
498
+ returns(OpenSSL::X509::Name.new([["CN", "*.local"]]))
499
+
500
+ expect { @ca.sign(@name) }.to raise_error(
501
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
502
+ /subject contains a wildcard/
503
+ )
504
+ end
505
+
506
+ it "should reject a wildcard subjectAltName" do
507
+ @request.stubs(:subject_alt_names).returns ['DNS:foo', 'DNS:*.bar']
508
+ expect { @ca.sign(@name, true) }.to raise_error(
509
+ Puppet::SSL::CertificateAuthority::CertificateSigningError,
510
+ /subjectAltName contains a wildcard/
511
+ )
512
+ end
402
513
  end
403
514
 
404
515
  it "should create a certificate instance with the content set to the newly signed x509 certificate" do
@@ -763,8 +874,7 @@ describe Puppet::SSL::CertificateAuthority do
763
874
  end
764
875
 
765
876
  it "should sign the generated request" do
766
- @ca.expects(:sign).with("him")
767
-
877
+ @ca.expects(:sign).with("him", false)
768
878
  @ca.generate("him")
769
879
  end
770
880
  end
@@ -5,103 +5,123 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  require 'puppet/ssl/certificate_factory'
6
6
 
7
7
  describe Puppet::SSL::CertificateFactory do
8
- before do
9
- @cert_type = mock 'cert_type'
10
- @name = mock 'name'
11
- @csr = stub 'csr', :subject => @name
12
- @issuer = mock 'issuer'
13
- @serial = mock 'serial'
14
-
15
- @factory = Puppet::SSL::CertificateFactory.new(@cert_type, @csr, @issuer, @serial)
8
+ let :serial do OpenSSL::BN.new('12') end
9
+ let :name do "example.local" end
10
+ let :x509_name do OpenSSL::X509::Name.new([['CN', name]]) end
11
+ let :key do Puppet::SSL::Key.new(name).generate end
12
+ let :csr do
13
+ csr = Puppet::SSL::CertificateRequest.new(name)
14
+ csr.generate(key)
15
+ csr
16
16
  end
17
-
18
- describe "when initializing" do
19
- it "should set its :cert_type to its first argument" do
20
- @factory.cert_type.should equal(@cert_type)
21
- end
22
-
23
- it "should set its :csr to its second argument" do
24
- @factory.csr.should equal(@csr)
25
- end
26
-
27
- it "should set its :issuer to its third argument" do
28
- @factory.issuer.should equal(@issuer)
29
- end
30
-
31
- it "should set its :serial to its fourth argument" do
32
- @factory.serial.should equal(@serial)
33
- end
34
-
35
- it "should set its name to the subject of the csr" do
36
- @factory.name.should equal(@name)
37
- end
17
+ let :issuer do
18
+ cert = OpenSSL::X509::Certificate.new
19
+ cert.subject = OpenSSL::X509::Name.new([["CN", 'issuer.local']])
20
+ cert
38
21
  end
39
22
 
40
23
  describe "when generating the certificate" do
41
- before do
42
- @cert = mock 'cert'
43
-
44
- @cert.stub_everything
45
-
46
- @factory.stubs :build_extensions
47
-
48
- @factory.stubs :set_ttl
49
-
50
- @issuer_name = mock 'issuer_name'
51
- @issuer.stubs(:subject).returns @issuer_name
52
-
53
- @public_key = mock 'public_key'
54
- @csr.stubs(:public_key).returns @public_key
55
-
56
- OpenSSL::X509::Certificate.stubs(:new).returns @cert
57
- end
58
-
59
24
  it "should return a new X509 certificate" do
60
- OpenSSL::X509::Certificate.expects(:new).returns @cert
61
- @factory.result.should equal(@cert)
25
+ subject.build(:server, csr, issuer, serial).should_not ==
26
+ subject.build(:server, csr, issuer, serial)
62
27
  end
63
28
 
64
29
  it "should set the certificate's version to 2" do
65
- @cert.expects(:version=).with 2
66
- @factory.result
30
+ subject.build(:server, csr, issuer, serial).version.should == 2
67
31
  end
68
32
 
69
33
  it "should set the certificate's subject to the CSR's subject" do
70
- @cert.expects(:subject=).with @name
71
- @factory.result
34
+ cert = subject.build(:server, csr, issuer, serial)
35
+ cert.subject.should eql x509_name
72
36
  end
73
37
 
74
38
  it "should set the certificate's issuer to the Issuer's subject" do
75
- @cert.expects(:issuer=).with @issuer_name
76
- @factory.result
39
+ cert = subject.build(:server, csr, issuer, serial)
40
+ cert.issuer.should eql issuer.subject
77
41
  end
78
42
 
79
43
  it "should set the certificate's public key to the CSR's public key" do
80
- @cert.expects(:public_key=).with @public_key
81
- @factory.result
44
+ cert = subject.build(:server, csr, issuer, serial)
45
+ cert.public_key.should be_public
46
+ cert.public_key.to_s.should == csr.content.public_key.to_s
82
47
  end
83
48
 
84
49
  it "should set the certificate's serial number to the provided serial number" do
85
- @cert.expects(:serial=).with @serial
86
- @factory.result
50
+ cert = subject.build(:server, csr, issuer, serial)
51
+ cert.serial.should == serial
52
+ end
53
+
54
+ it "should have 24 hours grace on the start of the cert" do
55
+ cert = subject.build(:server, csr, issuer, serial)
56
+ cert.not_before.should be_within(1).of(Time.now - 24*60*60)
57
+ end
58
+
59
+ it "should set the default TTL of the certificate" do
60
+ ttl = Puppet::SSL::CertificateFactory.ttl
61
+ cert = subject.build(:server, csr, issuer, serial)
62
+ cert.not_after.should be_within(1).of(Time.now + ttl)
63
+ end
64
+
65
+ it "should respect a custom TTL for the CA" do
66
+ Puppet[:ca_ttl] = 12
67
+ cert = subject.build(:server, csr, issuer, serial)
68
+ cert.not_after.should be_within(1).of(Time.now + 12)
87
69
  end
88
70
 
89
71
  it "should build extensions for the certificate" do
90
- @factory.expects(:build_extensions)
91
- @factory.result
72
+ cert = subject.build(:server, csr, issuer, serial)
73
+ cert.extensions.map {|x| x.to_h }.find {|x| x["oid"] == "nsComment" }.should ==
74
+ { "oid" => "nsComment",
75
+ "value" => "Puppet Ruby/OpenSSL Internal Certificate",
76
+ "critical" => false }
92
77
  end
93
78
 
94
- it "should set the ttl of the certificate" do
95
- @factory.expects(:set_ttl)
96
- @factory.result
79
+ # See #2848 for why we are doing this: we need to make sure that
80
+ # subjectAltName is set if the CSR has it, but *not* if it is set when the
81
+ # certificate is built!
82
+ it "should not add subjectAltNames from dns_alt_names" do
83
+ Puppet[:dns_alt_names] = 'one, two'
84
+ # Verify the CSR still has no extReq, just in case...
85
+ csr.request_extensions.should == []
86
+ cert = subject.build(:server, csr, issuer, serial)
87
+
88
+ cert.extensions.find {|x| x.oid == 'subjectAltName' }.should be_nil
97
89
  end
98
- end
99
90
 
100
- describe "when building extensions" do
101
- it "should have tests"
102
- end
91
+ it "should add subjectAltName when the CSR requests them" do
92
+ Puppet[:dns_alt_names] = ''
93
+
94
+ expect = %w{one two} + [name]
95
+
96
+ csr = Puppet::SSL::CertificateRequest.new(name)
97
+ csr.generate(key, :dns_alt_names => expect.join(', '))
103
98
 
104
- describe "when setting the ttl" do
105
- it "should have tests"
99
+ csr.request_extensions.should_not be_nil
100
+ csr.subject_alt_names.should =~ expect.map{|x| "DNS:#{x}"}
101
+
102
+ cert = subject.build(:server, csr, issuer, serial)
103
+ san = cert.extensions.find {|x| x.oid == 'subjectAltName' }
104
+ san.should_not be_nil
105
+ expect.each do |name|
106
+ san.value.should =~ /DNS:#{name}\b/i
107
+ end
108
+ end
109
+
110
+ # Can't check the CA here, since that requires way more infrastructure
111
+ # that I want to build up at this time. We can verify the critical
112
+ # values, though, which are non-CA certs. --daniel 2011-10-11
113
+ { :ca => 'CA:TRUE',
114
+ :terminalsubca => ['CA:TRUE', 'pathlen:0'],
115
+ :server => 'CA:FALSE',
116
+ :ocsp => 'CA:FALSE',
117
+ :client => 'CA:FALSE',
118
+ }.each do |name, value|
119
+ it "should set basicConstraints for #{name} #{value.inspect}" do
120
+ cert = subject.build(name, csr, issuer, serial)
121
+ bc = cert.extensions.find {|x| x.oid == 'basicConstraints' }
122
+ bc.should be
123
+ bc.value.split(/\s*,\s*/).should =~ Array(value)
124
+ end
125
+ end
106
126
  end
107
127
  end
@@ -126,7 +126,7 @@ describe Puppet::SSL::CertificateRequest do
126
126
 
127
127
  it "should set the CN to the :ca_name setting when the CSR is for a CA" do
128
128
  subject = mock 'subject'
129
- Puppet.settings.expects(:value).with(:ca_name).returns "mycertname"
129
+ Puppet[:ca_name] = "mycertname"
130
130
  OpenSSL::X509::Name.expects(:new).with { |subject| subject[0][1] == "mycertname" }.returns(subject)
131
131
  @request.expects(:subject=).with(subject)
132
132
  Puppet::SSL::CertificateRequest.new(Puppet::SSL::CA_NAME).generate(@key)
@@ -145,6 +145,67 @@ describe Puppet::SSL::CertificateRequest do
145
145
  @instance.generate(@key)
146
146
  end
147
147
 
148
+ context "without subjectAltName / dns_alt_names" do
149
+ before :each do
150
+ Puppet[:dns_alt_names] = ""
151
+ end
152
+
153
+ ["extreq", "msExtReq"].each do |name|
154
+ it "should not add any #{name} attribute" do
155
+ @request.expects(:add_attribute).never
156
+ @request.expects(:attributes=).never
157
+ @instance.generate(@key)
158
+ end
159
+
160
+ it "should return no subjectAltNames" do
161
+ @instance.generate(@key)
162
+ @instance.subject_alt_names.should be_empty
163
+ end
164
+ end
165
+ end
166
+
167
+ context "with dns_alt_names" do
168
+ before :each do
169
+ Puppet[:dns_alt_names] = "one, two, three"
170
+ end
171
+
172
+ ["extreq", "msExtReq"].each do |name|
173
+ it "should not add any #{name} attribute" do
174
+ @request.expects(:add_attribute).never
175
+ @request.expects(:attributes=).never
176
+ @instance.generate(@key)
177
+ end
178
+
179
+ it "should return no subjectAltNames" do
180
+ @instance.generate(@key)
181
+ @instance.subject_alt_names.should be_empty
182
+ end
183
+ end
184
+ end
185
+
186
+ context "with subjectAltName to generate request" do
187
+ before :each do
188
+ Puppet[:dns_alt_names] = ""
189
+ end
190
+
191
+ it "should add an extreq attribute" do
192
+ @request.expects(:add_attribute).with do |arg|
193
+ arg.value.value.all? do |x|
194
+ x.value.all? do |y|
195
+ y.value[0].value == "subjectAltName"
196
+ end
197
+ end
198
+ end
199
+
200
+ @instance.generate(@key, :dns_alt_names => 'one, two')
201
+ end
202
+
203
+ it "should return the subjectAltName values" do
204
+ @instance.generate(@key, :dns_alt_names => 'one,two')
205
+ @instance.subject_alt_names.should =~ ["DNS:myname", "DNS:one", "DNS:two"]
206
+ end
207
+ end
208
+
148
209
  it "should sign the csr with the provided key and a digest" do
149
210
  digest = mock 'digest'
150
211
  OpenSSL::Digest::MD5.expects(:new).returns(digest)