puppet 2.7.5 → 2.7.6

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 (140) hide show
  1. data/CHANGELOG +121 -0
  2. data/conf/redhat/puppet.spec +16 -7
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application/cert.rb +17 -3
  5. data/lib/puppet/application/device.rb +1 -0
  6. data/lib/puppet/application/kick.rb +0 -2
  7. data/lib/puppet/application/resource.rb +73 -66
  8. data/lib/puppet/configurer/plugin_handler.rb +6 -2
  9. data/lib/puppet/defaults.rb +60 -5
  10. data/lib/puppet/face/ca.rb +11 -2
  11. data/lib/puppet/face/certificate.rb +33 -4
  12. data/lib/puppet/file_serving/fileset.rb +1 -1
  13. data/lib/puppet/file_serving/indirection_hooks.rb +2 -2
  14. data/lib/puppet/file_serving/metadata.rb +43 -4
  15. data/lib/puppet/indirector.rb +0 -1
  16. data/lib/puppet/indirector/request.rb +3 -4
  17. data/lib/puppet/indirector/resource/active_record.rb +3 -10
  18. data/lib/puppet/indirector/resource/ral.rb +2 -2
  19. data/lib/puppet/indirector/rest.rb +1 -1
  20. data/lib/puppet/network/handler/ca.rb +16 -106
  21. data/lib/puppet/network/handler/master.rb +0 -3
  22. data/lib/puppet/network/handler/runner.rb +1 -0
  23. data/lib/puppet/parser/scope.rb +10 -0
  24. data/lib/puppet/provider/file/posix.rb +72 -34
  25. data/lib/puppet/provider/file/windows.rb +100 -0
  26. data/lib/puppet/provider/group/windows_adsi.rb +2 -2
  27. data/lib/puppet/provider/user/windows_adsi.rb +19 -4
  28. data/lib/puppet/resource.rb +16 -0
  29. data/lib/puppet/resource/catalog.rb +1 -1
  30. data/lib/puppet/ssl/certificate.rb +2 -2
  31. data/lib/puppet/ssl/certificate_authority.rb +86 -10
  32. data/lib/puppet/ssl/certificate_authority/interface.rb +64 -19
  33. data/lib/puppet/ssl/certificate_factory.rb +112 -91
  34. data/lib/puppet/ssl/certificate_request.rb +88 -1
  35. data/lib/puppet/ssl/host.rb +20 -3
  36. data/lib/puppet/type/file.rb +15 -34
  37. data/lib/puppet/type/file/group.rb +11 -91
  38. data/lib/puppet/type/file/mode.rb +11 -41
  39. data/lib/puppet/type/file/owner.rb +18 -34
  40. data/lib/puppet/type/file/source.rb +22 -7
  41. data/lib/puppet/type/group.rb +4 -3
  42. data/lib/puppet/type/user.rb +4 -1
  43. data/lib/puppet/util.rb +59 -6
  44. data/lib/puppet/util/adsi.rb +11 -0
  45. data/lib/puppet/util/log.rb +4 -0
  46. data/lib/puppet/util/log/destinations.rb +7 -1
  47. data/lib/puppet/util/monkey_patches.rb +19 -0
  48. data/lib/puppet/util/network_device/config.rb +4 -5
  49. data/lib/puppet/util/settings.rb +5 -0
  50. data/lib/puppet/util/suidmanager.rb +0 -1
  51. data/lib/puppet/util/windows.rb +4 -0
  52. data/lib/puppet/util/windows/error.rb +16 -0
  53. data/lib/puppet/util/windows/security.rb +593 -0
  54. data/spec/integration/defaults_spec.rb +27 -0
  55. data/spec/integration/network/handler_spec.rb +1 -1
  56. data/spec/integration/type/file_spec.rb +382 -145
  57. data/spec/integration/util/windows/security_spec.rb +468 -0
  58. data/spec/shared_behaviours/file_serving.rb +4 -3
  59. data/spec/unit/application/agent_spec.rb +1 -0
  60. data/spec/unit/application/device_spec.rb +5 -0
  61. data/spec/unit/application/resource_spec.rb +62 -101
  62. data/spec/unit/configurer/downloader_spec.rb +2 -2
  63. data/spec/unit/configurer/plugin_handler_spec.rb +15 -8
  64. data/spec/unit/configurer_spec.rb +2 -2
  65. data/spec/unit/face/ca_spec.rb +34 -0
  66. data/spec/unit/face/certificate_spec.rb +168 -1
  67. data/spec/unit/file_serving/fileset_spec.rb +1 -1
  68. data/spec/unit/file_serving/indirection_hooks_spec.rb +1 -1
  69. data/spec/unit/file_serving/metadata_spec.rb +151 -107
  70. data/spec/unit/indirector/certificate_request/ca_spec.rb +0 -3
  71. data/spec/unit/indirector/direct_file_server_spec.rb +10 -9
  72. data/spec/unit/indirector/file_metadata/file_spec.rb +6 -4
  73. data/spec/unit/indirector/request_spec.rb +13 -3
  74. data/spec/unit/indirector/resource/active_record_spec.rb +4 -10
  75. data/spec/unit/indirector/resource/ral_spec.rb +6 -4
  76. data/spec/unit/indirector/rest_spec.rb +5 -6
  77. data/spec/unit/network/handler/ca_spec.rb +86 -0
  78. data/spec/unit/parser/collector_spec.rb +7 -7
  79. data/spec/unit/parser/scope_spec.rb +20 -0
  80. data/spec/unit/provider/file/posix_spec.rb +226 -0
  81. data/spec/unit/provider/file/windows_spec.rb +136 -0
  82. data/spec/unit/provider/group/windows_adsi_spec.rb +7 -2
  83. data/spec/unit/provider/user/windows_adsi_spec.rb +36 -3
  84. data/spec/unit/resource/catalog_spec.rb +20 -10
  85. data/spec/unit/resource_spec.rb +55 -8
  86. data/spec/unit/ssl/certificate_authority/interface_spec.rb +97 -54
  87. data/spec/unit/ssl/certificate_authority_spec.rb +133 -23
  88. data/spec/unit/ssl/certificate_factory_spec.rb +90 -70
  89. data/spec/unit/ssl/certificate_request_spec.rb +62 -1
  90. data/spec/unit/ssl/certificate_spec.rb +20 -14
  91. data/spec/unit/ssl/host_spec.rb +52 -6
  92. data/spec/unit/type/file/content_spec.rb +4 -4
  93. data/spec/unit/type/file/group_spec.rb +34 -96
  94. data/spec/unit/type/file/mode_spec.rb +88 -0
  95. data/spec/unit/type/file/owner_spec.rb +32 -123
  96. data/spec/unit/type/file/source_spec.rb +120 -41
  97. data/spec/unit/type/file_spec.rb +1033 -753
  98. data/spec/unit/type_spec.rb +19 -1
  99. data/spec/unit/util/adsi_spec.rb +19 -0
  100. data/spec/unit/util/log/destinations_spec.rb +75 -0
  101. data/spec/unit/util/log_spec.rb +15 -0
  102. data/spec/unit/util/network_device/config_spec.rb +7 -0
  103. data/spec/unit/util/settings_spec.rb +10 -0
  104. data/spec/unit/util_spec.rb +126 -13
  105. data/test/language/functions.rb +0 -1
  106. data/test/language/snippets.rb +0 -9
  107. data/test/lib/puppettest/exetest.rb +1 -1
  108. data/test/lib/puppettest/servertest.rb +0 -1
  109. data/test/rails/rails.rb +0 -1
  110. data/test/ral/type/filesources.rb +0 -60
  111. metadata +13 -33
  112. data/lib/puppet/network/client.rb +0 -174
  113. data/lib/puppet/network/client/ca.rb +0 -56
  114. data/lib/puppet/network/client/file.rb +0 -6
  115. data/lib/puppet/network/client/proxy.rb +0 -27
  116. data/lib/puppet/network/client/report.rb +0 -26
  117. data/lib/puppet/network/client/runner.rb +0 -10
  118. data/lib/puppet/network/client/status.rb +0 -4
  119. data/lib/puppet/network/http_server.rb +0 -3
  120. data/lib/puppet/network/http_server/mongrel.rb +0 -130
  121. data/lib/puppet/network/http_server/webrick.rb +0 -155
  122. data/lib/puppet/network/xmlrpc/client.rb +0 -211
  123. data/lib/puppet/provider/file/win32.rb +0 -72
  124. data/lib/puppet/sslcertificates.rb +0 -146
  125. data/lib/puppet/sslcertificates/ca.rb +0 -375
  126. data/lib/puppet/sslcertificates/certificate.rb +0 -255
  127. data/lib/puppet/sslcertificates/inventory.rb +0 -38
  128. data/lib/puppet/sslcertificates/support.rb +0 -146
  129. data/spec/integration/network/client_spec.rb +0 -18
  130. data/spec/unit/network/xmlrpc/client_spec.rb +0 -172
  131. data/spec/unit/sslcertificates/ca_spec.rb +0 -106
  132. data/test/certmgr/certmgr.rb +0 -308
  133. data/test/certmgr/inventory.rb +0 -69
  134. data/test/certmgr/support.rb +0 -105
  135. data/test/network/client/ca.rb +0 -69
  136. data/test/network/client/dipper.rb +0 -34
  137. data/test/network/handler/ca.rb +0 -273
  138. data/test/network/server/mongrel_test.rb +0 -99
  139. data/test/network/server/webrick.rb +0 -111
  140. data/test/network/xmlrpc/client.rb +0 -45
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
4
-
5
- require 'puppet'
6
- require 'puppettest/certificates'
7
- require 'puppet/sslcertificates/inventory.rb'
8
- require 'mocha'
9
-
10
- class TestCertInventory < Test::Unit::TestCase
11
- include PuppetTest::Certificates
12
-
13
- Inventory = Puppet::SSLCertificates::Inventory
14
-
15
- def setup
16
- super
17
- Puppet::Util::SUIDManager.stubs(:asuser).yields
18
- end
19
-
20
- def test_format
21
- cert = mksignedcert
22
-
23
- format = nil
24
- assert_nothing_raised do
25
- format = Inventory.format(cert)
26
- end
27
-
28
-
29
- assert(
30
- format =~ /^0x0001 \S+ \S+ #{cert.subject}/,
31
-
32
- "Did not create correct format")
33
- end
34
-
35
- def test_init
36
- # First create a couple of certificates
37
- ca = mkCA
38
-
39
- cert1 = mksignedcert(ca, "host1.madstop.com")
40
- cert2 = mksignedcert(ca, "host2.madstop.com")
41
-
42
- init = nil
43
- assert_nothing_raised do
44
- init = Inventory.init
45
- end
46
-
47
- [cert1, cert2].each do |cert|
48
- assert(init.include?(cert.subject.to_s), "Did not catch #{cert.subject}")
49
- end
50
- end
51
-
52
- def test_add
53
- ca = mkCA
54
- cert = mksignedcert(ca, "host.domain.com")
55
-
56
- assert_nothing_raised do
57
- file = mock
58
- file.expects(:puts).with do |written|
59
- written.include? cert.subject.to_s
60
- end
61
- Puppet::Util::Settings.any_instance.stubs(:write)
62
- Puppet::Util::Settings.any_instance.expects(:write).
63
- with(:cert_inventory, 'a').yields(file)
64
-
65
- Puppet::SSLCertificates::Inventory.add(cert)
66
- end
67
- end
68
- end
69
-
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
4
-
5
- require 'puppettest'
6
- require 'puppet/sslcertificates/support'
7
- require 'mocha'
8
-
9
- class TestCertSupport < Test::Unit::TestCase
10
- include PuppetTest
11
- MissingCertificate = Puppet::SSLCertificates::Support::MissingCertificate
12
-
13
- class CertUser
14
- include Puppet::SSLCertificates::Support
15
- end
16
-
17
- def setup
18
- super
19
- Puppet::Util::SUIDManager.stubs(:asuser).yields
20
- @user = CertUser.new
21
- @ca = Puppet::SSLCertificates::CA.new
22
- @client = Puppet::Network::Client.ca.new(:CA => @ca)
23
- end
24
-
25
- # Yay, metaprogramming
26
- def test_keytype
27
- [:key, :csr, :cert, :ca_cert].each do |name|
28
- assert(Puppet::SSLCertificates::Support.method_defined?(name), "No retrieval method for #{name}")
29
- maker = "mk_#{name}"
30
- assert(Puppet::SSLCertificates::Support.method_defined?(maker), "No maker method for #{name}")
31
- end
32
- end
33
-
34
- def test_keys
35
- keys = [:hostprivkey, :hostpubkey].each { |n| Puppet[n] = tempfile }
36
-
37
- key = nil
38
- assert_nothing_raised do
39
- key = @user.key
40
- end
41
-
42
- assert_logged(:info, /Creating a new SSL/, "Did not log about new key")
43
- keys.each do |file|
44
-
45
- assert(
46
- FileTest.exists?(Puppet[file]),
47
-
48
- "Did not create #{file} key file")
49
- end
50
-
51
- # Make sure it's a valid key
52
- assert_nothing_raised("Created key is invalid") do
53
- OpenSSL::PKey::RSA.new(File.read(Puppet[:hostprivkey]))
54
- end
55
-
56
- # now make sure we can read it in
57
- other = CertUser.new
58
- assert_nothing_raised("Could not read key in") do
59
- other.key
60
- end
61
-
62
- assert_equal(@user.key.to_s, other.key.to_s, "Keys are not equal")
63
- end
64
-
65
- def test_csr
66
- csr = nil
67
- assert_nothing_raised("Could not create csr") do
68
- csr = @user.csr
69
- end
70
-
71
- assert(FileTest.exists?(Puppet[:hostcsr]), "did not create csr file")
72
- assert_instance_of(OpenSSL::X509::Request, csr)
73
- end
74
-
75
- def test_cacert
76
- @user = CertUser.new
77
-
78
- assert_raise(MissingCertificate, "Did not fail when missing cacert") do
79
- @user.ca_cert
80
- end
81
- end
82
-
83
- # Fixing #1382. This test will always fail on Darwin, because its
84
- # FS is case-insensitive.
85
- unless Facter.value(:operatingsystem) == "Darwin"
86
- def test_uppercase_files_are_renamed_and_read
87
- # Write a key out to disk in a file containing upper-case.
88
- key = OpenSSL::PKey::RSA.new(32)
89
- should_path = Puppet[:hostprivkey]
90
-
91
- dir, file = File.split(should_path)
92
- newfile = file.sub(/^([-a-z.0-9]+)\./) { $1.upcase + "."}
93
- upper_path = File.join(dir, newfile)
94
- p upper_path
95
- File.open(upper_path, "w") { |f| f.print key.to_s }
96
-
97
- user = CertUser.new
98
-
99
- assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk")
100
- assert(! FileTest.exist?(upper_path), "Upper case file was not removed")
101
- assert(FileTest.exist?(should_path), "File was not renamed to lower-case file")
102
- assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk")
103
- end
104
- end
105
- end
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
4
-
5
- require 'mocha'
6
- require 'puppettest'
7
- require 'puppet/network/client/ca'
8
- require 'puppet/sslcertificates/support'
9
-
10
- class TestClientCA < Test::Unit::TestCase
11
- include PuppetTest::ServerTest
12
-
13
- def setup
14
- Puppet::Util::SUIDManager.stubs(:asuser).yields
15
- super
16
- @ca = Puppet::Network::Handler.ca.new
17
- @client = Puppet::Network::Client.ca.new :CA => @ca
18
- end
19
-
20
- def test_request_cert
21
- assert_nothing_raised("Could not request cert") do
22
- @client.request_cert
23
- end
24
-
25
- [:hostprivkey, :hostcert, :localcacert].each do |name|
26
- assert(FileTest.exists?(Puppet.settings[name]), "Did not create cert #{name}")
27
- end
28
- end
29
-
30
- # Make sure the ca defaults to specific ports and names
31
- def test_ca_server
32
- Puppet.settings.stubs(:value).returns "eh"
33
- Puppet.settings.expects(:value).with(:ca_server).returns("myca")
34
- Puppet.settings.expects(:value).with(:ca_port).returns(321)
35
- Puppet.settings.stubs(:value).with(:http_proxy_host).returns(nil)
36
- Puppet.settings.stubs(:value).with(:http_proxy_port).returns(nil)
37
- Puppet.settings.stubs(:value).with(:http_keepalive).returns(false)
38
- Puppet.settings.stubs(:value).with(:configtimeout).returns(180)
39
-
40
- # Just throw an error; the important thing is the values, not what happens next.
41
- Net::HTTP.stubs(:new).with("myca", 321, nil, nil).raises(ArgumentError)
42
- assert_raise(ArgumentError) { Puppet::Network::Client.ca.new }
43
- end
44
-
45
- # #578
46
- def test_invalid_certs_are_not_written
47
- # Run the get once, which should be valid
48
-
49
- assert_nothing_raised("Could not get a certificate") do
50
- @client.request_cert
51
- end
52
-
53
- # Now remove the cert and keys, so we get a broken cert
54
- File.unlink(Puppet[:hostcert])
55
- File.unlink(Puppet[:localcacert])
56
- File.unlink(Puppet[:hostprivkey])
57
-
58
- @client = Puppet::Network::Client.ca.new :CA => @ca
59
- @ca.expects(:getcert).returns("yay") # not a valid cert
60
- # Now make sure it fails, since we'll get the old cert but have new keys
61
- assert_raise(Puppet::Network::Client::CA::InvalidCertificate, "Did not fail on invalid cert") do
62
- @client.request_cert
63
- end
64
-
65
- # And then make sure the cert isn't written to disk
66
- assert(! FileTest.exists?(Puppet[:hostcert]), "Invalid cert got written to disk")
67
- end
68
- end
69
-
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
4
-
5
- require 'puppettest'
6
- require 'puppet/file_bucket/dipper'
7
-
8
- class TestDipperClient < Test::Unit::TestCase
9
- include PuppetTest::ServerTest
10
-
11
- def setup
12
- super
13
- @dipper = Puppet::FileBucket::Dipper.new(:Path => tempfile)
14
- end
15
-
16
- # Make sure we can create a new file with 'restore'.
17
- def test_restore_to_new_file
18
- file = tempfile
19
- text = "asdf;lkajseofiqwekj"
20
- File.open(file, "w") { |f| f.puts text }
21
- md5 = nil
22
- assert_nothing_raised("Could not send file") do
23
- md5 = @dipper.backup(file)
24
- end
25
-
26
- newfile = tempfile
27
- assert_nothing_raised("could not restore to new path") do
28
- @dipper.restore(newfile, md5)
29
- end
30
-
31
- assert_equal(File.read(file), File.read(newfile), "did not restore correctly")
32
- end
33
- end
34
-
@@ -1,273 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
4
-
5
- require 'puppettest'
6
- require 'puppet/network/handler/ca'
7
- require 'mocha'
8
-
9
- $short = (ARGV.length > 0 and ARGV[0] == "short")
10
-
11
- class TestCA < Test::Unit::TestCase
12
- include PuppetTest::ServerTest
13
-
14
- def setup
15
- Puppet::Util::SUIDManager.stubs(:asuser).yields
16
- super
17
- end
18
-
19
- # Verify that we're autosigning. We have to autosign a "different" machine,
20
- # since we always autosign the CA server's certificate.
21
- def test_autocertgeneration
22
- ca = nil
23
-
24
- # create our ca
25
- assert_nothing_raised {
26
- ca = Puppet::Network::Handler.ca.new(:autosign => true)
27
- }
28
-
29
- # create a cert with a fake name
30
- key = nil
31
- csr = nil
32
- cert = nil
33
- hostname = "test.domain.com"
34
- assert_nothing_raised {
35
- cert = Puppet::SSLCertificates::Certificate.new(
36
- :name => "test.domain.com"
37
- )
38
- }
39
-
40
- # make the request
41
- assert_nothing_raised {
42
- cert.mkcsr
43
- }
44
-
45
- # and get it signed
46
- certtext = nil
47
- cacerttext = nil
48
- assert_nothing_raised {
49
- certtext, cacerttext = ca.getcert(cert.csr.to_s)
50
- }
51
-
52
- # they should both be strings
53
- assert_instance_of(String, certtext)
54
- assert_instance_of(String, cacerttext)
55
-
56
- # and they should both be valid certs
57
- assert_nothing_raised {
58
- OpenSSL::X509::Certificate.new(certtext)
59
- }
60
- assert_nothing_raised {
61
- OpenSSL::X509::Certificate.new(cacerttext)
62
- }
63
-
64
- # and pull it again, just to make sure we're getting the same thing
65
- newtext = nil
66
- assert_nothing_raised {
67
- newtext, cacerttext = ca.getcert(
68
- cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
69
- )
70
- }
71
-
72
- assert_equal(certtext,newtext)
73
- end
74
-
75
- # this time don't use autosign
76
- def test_storeAndSign
77
- ca = nil
78
- caserv = nil
79
-
80
- # make our CA server
81
- assert_nothing_raised {
82
- caserv = Puppet::Network::Handler.ca.new(:autosign => false)
83
- }
84
-
85
- # retrieve the actual ca object
86
- assert_nothing_raised {
87
- ca = caserv.ca
88
- }
89
-
90
- # make our test cert again
91
- key = nil
92
- csr = nil
93
- cert = nil
94
- hostname = "test.domain.com"
95
- assert_nothing_raised {
96
- cert = Puppet::SSLCertificates::Certificate.new(
97
- :name => "anothertest.domain.com"
98
- )
99
- }
100
- # and the CSR
101
- assert_nothing_raised {
102
- cert.mkcsr
103
- }
104
-
105
- # retrieve them
106
- certtext = nil
107
- assert_nothing_raised {
108
- certtext, cacerttext = caserv.getcert(
109
- cert.csr.to_s, "test.reductivelabs.com", "127.0.0.1"
110
- )
111
- }
112
-
113
- # verify we got nothing back, since autosign is off
114
- assert_equal("", certtext)
115
-
116
- # now sign it manually, with the CA object
117
- x509 = nil
118
- assert_nothing_raised {
119
- x509, cacert = ca.sign(cert.csr)
120
- }
121
-
122
- # and write it out
123
- cert.cert = x509
124
- assert_nothing_raised {
125
- cert.write
126
- }
127
-
128
- assert(File.exists?(cert.certfile))
129
-
130
- # now get them again, and verify that we actually get them
131
- newtext = nil
132
- assert_nothing_raised {
133
- newtext, cacerttext = caserv.getcert(cert.csr.to_s)
134
- }
135
-
136
- assert(newtext)
137
- assert_nothing_raised {
138
- OpenSSL::X509::Certificate.new(newtext)
139
- }
140
-
141
- # Now verify that we can clean a given host's certs
142
- assert_nothing_raised {
143
- ca.clean("anothertest.domain.com")
144
- }
145
-
146
- assert(!File.exists?(cert.certfile), "Cert still exists after clean")
147
- end
148
-
149
- # and now test the autosign file
150
- def test_autosign
151
- autosign = File.join(tmpdir, "autosigntesting")
152
- @@tmpfiles << autosign
153
- File.open(autosign, "w") { |f|
154
- f.puts "hostmatch.domain.com"
155
- f.puts "*.other.com"
156
- }
157
-
158
- caserv = nil
159
- assert_nothing_raised {
160
- caserv = Puppet::Network::Handler.ca.new(:autosign => autosign)
161
- }
162
-
163
- # make sure we know what's going on
164
- assert(caserv.autosign?("hostmatch.domain.com"))
165
- assert(caserv.autosign?("fakehost.other.com"))
166
- assert(!caserv.autosign?("kirby.reductivelabs.com"))
167
- assert(!caserv.autosign?("culain.domain.com"))
168
- end
169
-
170
- # verify that things aren't autosigned by default
171
- def test_nodefaultautosign
172
- caserv = nil
173
- assert_nothing_raised {
174
- caserv = Puppet::Network::Handler.ca.new
175
- }
176
-
177
- # make sure we know what's going on
178
- assert(!caserv.autosign?("hostmatch.domain.com"))
179
- assert(!caserv.autosign?("fakehost.other.com"))
180
- assert(!caserv.autosign?("kirby.reductivelabs.com"))
181
- assert(!caserv.autosign?("culain.domain.com"))
182
- end
183
-
184
- # We want the CA to autosign its own certificate, because otherwise
185
- # the puppetmasterd CA does not autostart.
186
- def test_caautosign
187
- server = nil
188
- Puppet.stubs(:master?).returns true
189
- assert_nothing_raised {
190
-
191
- server = Puppet::Network::HTTPServer::WEBrick.new(
192
-
193
- :Port => @@port,
194
-
195
- :Handlers => {
196
- :CA => {}, # so that certs autogenerate
197
- :Status => nil
198
- }
199
- )
200
- }
201
- end
202
-
203
- # Make sure true/false causes the file to be ignored.
204
- def test_autosign_true_beats_file
205
- caserv = nil
206
- assert_nothing_raised {
207
- caserv = Puppet::Network::Handler.ca.new
208
- }
209
-
210
- host = "hostname.domain.com"
211
-
212
- # Create an autosign file
213
- file = tempfile
214
- Puppet[:autosign] = file
215
-
216
- File.open(file, "w") { |f|
217
- f.puts host
218
- }
219
-
220
- # Start with "false"
221
- Puppet[:autosign] = false
222
-
223
- assert(! caserv.autosign?(host), "Host was incorrectly autosigned")
224
-
225
- # Then set it to true
226
- Puppet[:autosign] = true
227
- assert(caserv.autosign?(host), "Host was not autosigned")
228
- # And try a different host
229
- assert(caserv.autosign?("other.yay.com"), "Host was not autosigned")
230
-
231
- # And lastly the file
232
- Puppet[:autosign] = file
233
- assert(caserv.autosign?(host), "Host was not autosigned")
234
-
235
- # And try a different host
236
- assert(! caserv.autosign?("other.yay.com"), "Host was autosigned")
237
- end
238
-
239
- # Make sure that a CSR created with keys that don't match the existing
240
- # cert throws an exception on the server.
241
- def test_mismatched_public_keys_throws_exception
242
- ca = Puppet::Network::Handler.ca.new
243
-
244
- # First initialize the server
245
- client = Puppet::Network::Client.ca.new :CA => ca
246
- client.request_cert
247
- File.unlink(Puppet[:hostcsr])
248
-
249
- # Now use a different cert name
250
- Puppet[:certname] = "my.host.com"
251
- client = Puppet::Network::Client.ca.new :CA => ca
252
- firstcsr = client.csr
253
- File.unlink(Puppet[:hostcsr]) if FileTest.exists?(Puppet[:hostcsr])
254
-
255
- assert_nothing_raised("Could not get cert") do
256
- ca.getcert(firstcsr.to_s)
257
- end
258
-
259
- # Now get rid of the public key, forcing a new csr
260
- File.unlink(Puppet[:hostprivkey])
261
-
262
- client = Puppet::Network::Client.ca.new :CA => ca
263
-
264
- second_csr = client.csr
265
-
266
- assert(firstcsr.to_s != second_csr.to_s, "CSR did not change")
267
-
268
- assert_raise(Puppet::Error, "CA allowed mismatched keys") do
269
- ca.getcert(second_csr.to_s)
270
- end
271
- end
272
- end
273
-