puppet 2.7.1 → 2.7.3

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 (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -0,0 +1,355 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:ca, '0.1.0'] do
6
+ include PuppetSpec::Files
7
+
8
+ before :each do
9
+ Puppet.run_mode.stubs(:master?).returns(true)
10
+ Puppet[:ca] = true
11
+ Puppet[:ssldir] = tmpdir("face-ca-ssldir")
12
+
13
+ Puppet::SSL::Host.ca_location = :only
14
+ Puppet[:certificate_revocation] = true
15
+
16
+ # This is way more intimate than I want to be with the implementation, but
17
+ # there doesn't seem any other way to test this. --daniel 2011-07-18
18
+ Puppet::SSL::CertificateAuthority.stubs(:instance).returns(
19
+ # ...and this actually does the directory creation, etc.
20
+ Puppet::SSL::CertificateAuthority.new
21
+ )
22
+ end
23
+
24
+ def make_certs(csr_names, crt_names)
25
+ Array(csr_names).map do |name|
26
+ Puppet::SSL::Host.new(name).generate_certificate_request
27
+ end
28
+
29
+ Array(crt_names).map do |name|
30
+ Puppet::SSL::Host.new(name).generate
31
+ end
32
+ end
33
+
34
+ context "#verify" do
35
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:verify) end
36
+
37
+ it "should not explode if there is no certificate" do
38
+ expect {
39
+ subject.verify('random-host').should == {
40
+ :host => 'random-host', :valid => false,
41
+ :error => 'Could not find a certificate for random-host'
42
+ }
43
+ }.should_not raise_error
44
+ end
45
+
46
+ it "should not explode if there is only a CSR" do
47
+ make_certs('random-host', [])
48
+ expect {
49
+ subject.verify('random-host').should == {
50
+ :host => 'random-host', :valid => false,
51
+ :error => 'Could not find a certificate for random-host'
52
+ }
53
+ }.should_not raise_error
54
+ end
55
+
56
+ it "should verify a signed certificate" do
57
+ make_certs([], 'random-host')
58
+ subject.verify('random-host').should == {
59
+ :host => 'random-host', :valid => true
60
+ }
61
+ end
62
+
63
+ it "should not verify a revoked certificate" do
64
+ make_certs([], 'random-host')
65
+ subject.revoke('random-host')
66
+
67
+ expect {
68
+ subject.verify('random-host').should == {
69
+ :host => 'random-host', :valid => false,
70
+ :error => 'certificate revoked'
71
+ }
72
+ }.should_not raise_error
73
+ end
74
+
75
+ it "should verify a revoked certificate if CRL use was turned off" do
76
+ make_certs([], 'random-host')
77
+ subject.revoke('random-host')
78
+
79
+ Puppet[:certificate_revocation] = false
80
+ subject.verify('random-host').should == {
81
+ :host => 'random-host', :valid => true
82
+ }
83
+ end
84
+ end
85
+
86
+ context "#fingerprint" do
87
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:fingerprint) end
88
+
89
+ it "should have a 'digest' option" do
90
+ action.should be_option :digest
91
+ end
92
+
93
+ it "should not explode if there is no certificate" do
94
+ expect {
95
+ subject.fingerprint('random-host').should be_nil
96
+ }.should_not raise_error
97
+ end
98
+
99
+ it "should fingerprint a CSR" do
100
+ make_certs('random-host', [])
101
+ expect {
102
+ subject.fingerprint('random-host').should =~ /^[0-9A-F:]+$/
103
+ }.should_not raise_error
104
+ end
105
+
106
+ it "should fingerprint a certificate" do
107
+ make_certs([], 'random-host')
108
+ subject.fingerprint('random-host').should =~ /^[0-9A-F:]+$/
109
+ end
110
+
111
+ %w{md5 MD5 sha1 ShA1 SHA1 RIPEMD160 sha256 sha512}.each do |digest|
112
+ it "should fingerprint with #{digest.inspect}" do
113
+ make_certs([], 'random-host')
114
+ subject.fingerprint('random-host', :digest => digest).should =~ /^[0-9A-F:]+$/
115
+ end
116
+
117
+ it "should fingerprint with #{digest.to_sym} as a symbol" do
118
+ make_certs([], 'random-host')
119
+ subject.fingerprint('random-host', :digest => digest.to_sym).
120
+ should =~ /^[0-9A-F:]+$/
121
+ end
122
+ end
123
+ end
124
+
125
+ context "#print" do
126
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:print) end
127
+
128
+ it "should not explode if there is no certificate" do
129
+ expect {
130
+ subject.print('random-host').should be_nil
131
+ }.should_not raise_error
132
+ end
133
+
134
+ it "should return nothing if there is only a CSR" do
135
+ make_certs('random-host', [])
136
+ expect {
137
+ subject.print('random-host').should be_nil
138
+ }.should_not raise_error
139
+ end
140
+
141
+ it "should return the certificate content if there is a cert" do
142
+ make_certs([], 'random-host')
143
+ text = subject.print('random-host')
144
+ text.should be_an_instance_of String
145
+ text.should =~ /^Certificate:/
146
+ text.should =~ /Issuer: CN=Puppet CA: /
147
+ text.should =~ /Subject: CN=random-host$/
148
+ end
149
+ end
150
+
151
+ context "#sign" do
152
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:sign) end
153
+
154
+ it "should not explode if there is no CSR" do
155
+ expect {
156
+ subject.sign('random-host').
157
+ should == 'Could not find certificate request for random-host'
158
+ }.should_not raise_error
159
+ end
160
+
161
+ it "should not explode if there is a signed cert" do
162
+ make_certs([], 'random-host')
163
+ expect {
164
+ subject.sign('random-host').
165
+ should == 'Could not find certificate request for random-host'
166
+ }.should_not raise_error
167
+ end
168
+
169
+ it "should sign a CSR if one exists" do
170
+ make_certs('random-host', [])
171
+ subject.sign('random-host').should be_an_instance_of Puppet::SSL::Certificate
172
+
173
+ list = subject.list(:signed => true)
174
+ list.length.should == 1
175
+ list.first.name.should == 'random-host'
176
+ end
177
+ end
178
+
179
+ context "#generate" do
180
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:generate) end
181
+
182
+ it "should generate a certificate if requested" do
183
+ subject.list(:all => true).should == []
184
+
185
+ subject.generate('random-host')
186
+
187
+ list = subject.list(:signed => true)
188
+ list.length.should == 1
189
+ list.first.name.should == 'random-host'
190
+ end
191
+
192
+ it "should not explode if a CSR with that name already exists" do
193
+ make_certs('random-host', [])
194
+ expect {
195
+ subject.generate('random-host').should =~ /already has a certificate request/
196
+ }.should_not raise_error
197
+ end
198
+
199
+ it "should not explode if the certificate with that name already exists" do
200
+ make_certs([], 'random-host')
201
+ expect {
202
+ subject.generate('random-host').should =~ /already has a certificate/
203
+ }.should_not raise_error
204
+ end
205
+ end
206
+
207
+ context "#revoke" do
208
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:revoke) end
209
+
210
+ it "should not explode when asked to revoke something that doesn't exist" do
211
+ expect { subject.revoke('nonesuch') }.should_not raise_error
212
+ end
213
+
214
+ it "should let the user know what went wrong" do
215
+ subject.revoke('nonesuch').should == 'Nothing was revoked'
216
+ end
217
+
218
+ it "should revoke a certificate" do
219
+ make_certs([], 'random-host')
220
+ found = subject.list(:all => true, :subject => 'random-host')
221
+ subject.get_action(:list).when_rendering(:console).call(found).
222
+ should =~ /^\+ random-host/
223
+
224
+ subject.revoke('random-host')
225
+
226
+ found = subject.list(:all => true, :subject => 'random-host')
227
+ subject.get_action(:list).when_rendering(:console).call(found).
228
+ should =~ /^- random-host \([:0-9A-F]+\) \(certificate revoked\)/
229
+ end
230
+ end
231
+
232
+ context "#destroy" do
233
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:destroy) end
234
+
235
+ it "should not explode when asked to delete something that doesn't exist" do
236
+ expect { subject.destroy('nonesuch') }.should_not raise_error
237
+ end
238
+
239
+ it "should let the user know if nothing was deleted" do
240
+ subject.destroy('nonesuch').should == "Nothing was deleted"
241
+ end
242
+
243
+ it "should destroy a CSR, if we have one" do
244
+ make_certs('random-host', [])
245
+ subject.list(:pending => true, :subject => 'random-host').should_not == []
246
+
247
+ subject.destroy('random-host')
248
+
249
+ subject.list(:pending => true, :subject => 'random-host').should == []
250
+ end
251
+
252
+ it "should destroy a certificate, if we have one" do
253
+ make_certs([], 'random-host')
254
+ subject.list(:signed => true, :subject => 'random-host').should_not == []
255
+
256
+ subject.destroy('random-host')
257
+
258
+ subject.list(:signed => true, :subject => 'random-host').should == []
259
+ end
260
+
261
+ it "should tell the user something was deleted" do
262
+ make_certs([], 'random-host')
263
+ subject.list(:signed => true, :subject => 'random-host').should_not == []
264
+ subject.destroy('random-host').
265
+ should == "Deleted for random-host: Puppet::SSL::Certificate, Puppet::SSL::Key"
266
+ end
267
+ end
268
+
269
+ context "#list" do
270
+ let :action do Puppet::Face[:ca, '0.1.0'].get_action(:list) end
271
+
272
+ context "options" do
273
+ subject { Puppet::Face[:ca, '0.1.0'].get_action(:list) }
274
+ it { should be_option :pending }
275
+ it { should be_option :signed }
276
+ it { should be_option :all }
277
+ it { should be_option :subject }
278
+ end
279
+
280
+ context "with no hosts in CA" do
281
+ [:pending, :signed, :all].each do |type|
282
+ it "should return nothing for #{type}" do
283
+ subject.list(type => true).should == []
284
+ end
285
+
286
+ it "should not fail when a matcher is passed" do
287
+ expect {
288
+ subject.list(type => true, :subject => '.').should == []
289
+ }.should_not raise_error
290
+ end
291
+ end
292
+ end
293
+
294
+ context "with some hosts" do
295
+ csr_names = (1..3).map {|n| "csr-#{n}" }
296
+ crt_names = (1..3).map {|n| "crt-#{n}" }
297
+ all_names = csr_names + crt_names
298
+
299
+ {
300
+ {} => csr_names,
301
+ { :pending => true } => csr_names,
302
+
303
+ { :signed => true } => crt_names,
304
+
305
+ { :all => true } => all_names,
306
+ { :pending => true, :signed => true } => all_names,
307
+ }.each do |input, expect|
308
+ it "should map #{input.inspect} to #{expect.inspect}" do
309
+ make_certs(csr_names, crt_names)
310
+ subject.list(input).map(&:name).should =~ expect
311
+ end
312
+
313
+ ['', '.', '2', 'none'].each do |pattern|
314
+ filtered = expect.select {|x| Regexp.new(pattern).match(x) }
315
+
316
+ it "should filter all hosts matching #{pattern.inspect} to #{filtered.inspect}" do
317
+ make_certs(csr_names, crt_names)
318
+ subject.list(input.merge :subject => pattern).map(&:name).should =~ filtered
319
+ end
320
+ end
321
+ end
322
+
323
+ context "when_rendering :console" do
324
+ { [["csr1.local"], []] => '^ csr1.local ',
325
+ [[], ["crt1.local"]] => '^\+ crt1.local ',
326
+ [["csr2"], ["crt2"]] => ['^ csr2 ', '^\+ crt2 ']
327
+ }.each do |input, pattern|
328
+ it "should render #{input.inspect} to match #{pattern.inspect}" do
329
+ make_certs(*input)
330
+ text = action.when_rendering(:console).call(subject.list(:all => true))
331
+ Array(pattern).each do |item|
332
+ text.should =~ Regexp.new(item)
333
+ end
334
+ end
335
+ end
336
+ end
337
+ end
338
+ end
339
+
340
+ actions = %w{destroy list revoke generate sign print verify fingerprint}
341
+ actions.each do |action|
342
+ it { should be_action action }
343
+ it "should fail #{action} when not a CA" do
344
+ Puppet[:ca] = false
345
+ expect {
346
+ case subject.method(action).arity
347
+ when -1 then subject.send(action)
348
+ when -2 then subject.send(action, 'dummy')
349
+ else
350
+ raise "#{action} has arity #{subject.method(action).arity}"
351
+ end
352
+ }.should raise_error(/Not a CA/)
353
+ end
354
+ end
355
+ end
@@ -10,14 +10,26 @@ describe Puppet::Face[:certificate, '0.0.1'] do
10
10
  end
11
11
 
12
12
  it "should set the ca location when invoked" do
13
- Puppet::SSL::Host.expects(:ca_location=).with(:foo)
13
+ Puppet::SSL::Host.expects(:ca_location=).with(:local)
14
14
  Puppet::SSL::Host.indirection.expects(:save)
15
- subject.sign "hello, friend", :ca_location => :foo
15
+ subject.sign "hello, friend", :ca_location => :local
16
16
  end
17
17
 
18
18
  it "(#7059) should set the ca location when an inherited action is invoked" do
19
- Puppet::SSL::Host.expects(:ca_location=).with(:foo)
19
+ Puppet::SSL::Host.expects(:ca_location=).with(:local)
20
20
  subject.indirection.expects(:find)
21
- subject.find "hello, friend", :ca_location => :foo
21
+ subject.find "hello, friend", :ca_location => :local
22
+ end
23
+
24
+ it "should validate the option as required" do
25
+ expect do
26
+ subject.find 'hello, friend'
27
+ end.to raise_exception ArgumentError, /required/i
28
+ end
29
+
30
+ it "should validate the option as a supported value" do
31
+ expect do
32
+ subject.find 'hello, friend', :ca_location => :foo
33
+ end.to raise_exception ArgumentError, /valid values/i
22
34
  end
23
35
  end
@@ -3,5 +3,265 @@ require 'spec_helper'
3
3
  require 'puppet/face'
4
4
 
5
5
  describe Puppet::Face[:node, '0.0.1'] do
6
- it "REVISIT: really should have some tests"
6
+ describe '#cleanup' do
7
+ it "should clean everything" do
8
+ {
9
+ "cert" => ['hostname'],
10
+ "cached_facts" => ['hostname'],
11
+ "cached_node" => ['hostname'],
12
+ "reports" => ['hostname'],
13
+
14
+ # Support for cleaning storeconfigs has been temporarily suspended.
15
+ # "storeconfigs" => ['hostname', :unexport]
16
+ }.each { |k, v| subject.expects("clean_#{k}".to_sym).with(*v) }
17
+ subject.cleanup('hostname', :unexport)
18
+ end
19
+ end
20
+
21
+ describe 'when running #clean' do
22
+ before :each do
23
+ Puppet::Node::Facts.indirection.stubs(:terminus_class=)
24
+ Puppet::Node::Facts.indirection.stubs(:cache_class=)
25
+ Puppet::Node.stubs(:terminus_class=)
26
+ Puppet::Node.stubs(:cache_class=)
27
+ end
28
+
29
+ it 'should invoke #cleanup' do
30
+ subject.expects(:cleanup).with('hostname', nil)
31
+ subject.clean('hostname')
32
+ end
33
+ end
34
+
35
+ describe "clean action" do
36
+ before :each do
37
+ Puppet::Node::Facts.indirection.stubs(:terminus_class=)
38
+ Puppet::Node::Facts.indirection.stubs(:cache_class=)
39
+ Puppet::Node.stubs(:terminus_class=)
40
+ Puppet::Node.stubs(:cache_class=)
41
+ subject.stubs(:cleanup)
42
+ end
43
+
44
+ it "should have a clean action" do
45
+ subject.should be_action :clean
46
+ end
47
+
48
+ it "should not accept a call with no arguments" do
49
+ expect { subject.clean() }.should raise_error
50
+ end
51
+
52
+ it "should accept a node name" do
53
+ expect { subject.clean('hostname') }.should_not raise_error
54
+ end
55
+
56
+ it "should accept more than one node name" do
57
+ expect do
58
+ subject.clean('hostname', 'hostname2', {})
59
+ end.should_not raise_error
60
+
61
+ expect do
62
+ subject.clean('hostname', 'hostname2', 'hostname3', { :unexport => true })
63
+ end.should_not raise_error
64
+ end
65
+
66
+ it "should accept the option --unexport" do
67
+ expect { subject.help('hostname', :unexport => true) }.
68
+ should_not raise_error ArgumentError
69
+ end
70
+
71
+ context "clean action" do
72
+ subject { Puppet::Face[:node, :current] }
73
+ before :each do
74
+ Puppet::Util::Log.stubs(:newdestination)
75
+ Puppet::Util::Log.stubs(:level=)
76
+ end
77
+
78
+ describe "during setup" do
79
+ it "should set facts terminus and cache class to yaml" do
80
+ Puppet::Node::Facts.indirection.expects(:terminus_class=).with(:yaml)
81
+ Puppet::Node::Facts.indirection.expects(:cache_class=).with(:yaml)
82
+
83
+ subject.clean('hostname')
84
+ end
85
+
86
+ it "should run in master mode" do
87
+ subject.clean('hostname')
88
+ $puppet_application_mode.name.should == :master
89
+ end
90
+
91
+ it "should set node cache as yaml" do
92
+ Puppet::Node.indirection.expects(:terminus_class=).with(:yaml)
93
+ Puppet::Node.indirection.expects(:cache_class=).with(:yaml)
94
+
95
+ subject.clean('hostname')
96
+ end
97
+
98
+ it "should manage the certs if the host is a CA" do
99
+ Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
100
+ Puppet::SSL::Host.expects(:ca_location=).with(:local)
101
+ subject.clean('hostname')
102
+ end
103
+
104
+ it "should not manage the certs if the host is not a CA" do
105
+ Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
106
+ Puppet::SSL::Host.expects(:ca_location=).with(:none)
107
+ subject.clean('hostname')
108
+ end
109
+ end
110
+
111
+ describe "when cleaning certificate" do
112
+ before :each do
113
+ Puppet::SSL::Host.stubs(:destroy)
114
+ @ca = mock()
115
+ Puppet::SSL::CertificateAuthority.stubs(:instance).returns(@ca)
116
+ end
117
+
118
+ it "should send the :destroy order to the ca if we are a CA" do
119
+ Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
120
+ @ca.expects(:revoke).with(@host)
121
+ @ca.expects(:destroy).with(@host)
122
+ subject.clean_cert(@host)
123
+ end
124
+
125
+ it "should not destroy the certs if we are not a CA" do
126
+ Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
127
+ @ca.expects(:revoke).never
128
+ @ca.expects(:destroy).never
129
+ subject.clean_cert(@host)
130
+ end
131
+ end
132
+
133
+ describe "when cleaning cached facts" do
134
+ it "should destroy facts" do
135
+ @host = 'node'
136
+ Puppet::Node::Facts.indirection.expects(:destroy).with(@host)
137
+
138
+ subject.clean_cached_facts(@host)
139
+ end
140
+ end
141
+
142
+ describe "when cleaning cached node" do
143
+ it "should destroy the cached node" do
144
+ Puppet::Node::Yaml.any_instance.expects(:destroy)
145
+ subject.clean_cached_node(@host)
146
+ end
147
+ end
148
+
149
+ describe "when cleaning archived reports" do
150
+ it "should tell the reports to remove themselves" do
151
+ Puppet::Transaction::Report.indirection.stubs(:destroy).with(@host)
152
+
153
+ subject.clean_reports(@host)
154
+ end
155
+ end
156
+
157
+ # describe "when cleaning storeconfigs entries for host", :if => Puppet.features.rails? do
158
+ # before :each do
159
+ # # Stub this so we don't need access to the DB
160
+ # require 'puppet/rails/host'
161
+ #
162
+ # Puppet.stubs(:[]).with(:storeconfigs).returns(true)
163
+ #
164
+ # Puppet::Rails.stubs(:connect)
165
+ # @rails_node = stub_everything 'rails_node'
166
+ # Puppet::Rails::Host.stubs(:find_by_name).returns(@rails_node)
167
+ # end
168
+ #
169
+ # it "should connect to the database" do
170
+ # Puppet::Rails.expects(:connect)
171
+ # subject.clean_storeconfigs(@host, false)
172
+ # end
173
+ #
174
+ # it "should find the right host entry" do
175
+ # Puppet::Rails::Host.expects(:find_by_name).with(@host).returns(@rails_node)
176
+ # subject.clean_storeconfigs(@host, false)
177
+ # end
178
+ #
179
+ # describe "without unexport" do
180
+ # it "should remove the host and it's content" do
181
+ # @rails_node.expects(:destroy)
182
+ # subject.clean_storeconfigs(@host, false)
183
+ # end
184
+ # end
185
+ #
186
+ # describe "with unexport" do
187
+ # before :each do
188
+ # @rails_node.stubs(:id).returns(1234)
189
+ #
190
+ # @type = stub_everything 'type'
191
+ # @type.stubs(:validattr?).with(:ensure).returns(true)
192
+ #
193
+ # @ensure_name = stub_everything 'ensure_name', :id => 23453
194
+ # Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(@ensure_name)
195
+ #
196
+ # @param_values = stub_everything 'param_values'
197
+ # @resource = stub_everything 'resource', :param_values => @param_values, :restype => "File"
198
+ # Puppet::Rails::Resource.stubs(:find).returns([@resource])
199
+ # end
200
+ #
201
+ # it "should find all resources" do
202
+ # Puppet::Rails::Resource.expects(:find).with(:all, {:include => {:param_values => :param_name}, :conditions => ["exported=? AND host_id=?", true, 1234]}).returns([])
203
+ #
204
+ # subject.clean_storeconfigs(@host, true)
205
+ # end
206
+ #
207
+ # describe "with an exported native type" do
208
+ # before :each do
209
+ # Puppet::Type.stubs(:type).returns(@type)
210
+ # @type.expects(:validattr?).with(:ensure).returns(true)
211
+ # end
212
+ #
213
+ # it "should test a native type for ensure as an attribute" do
214
+ # subject.clean_storeconfigs(@host, true)
215
+ # end
216
+ #
217
+ # it "should delete the old ensure parameter" do
218
+ # ensure_param = stub 'ensure_param', :id => 12345, :line => 12
219
+ # @param_values.stubs(:find).returns(ensure_param)
220
+ # Puppet::Rails::ParamValue.expects(:delete).with(12345);
221
+ # subject.clean_storeconfigs(@host, true)
222
+ # end
223
+ #
224
+ # it "should add an ensure => absent parameter" do
225
+ # @param_values.expects(:create).with(:value => "absent",
226
+ # :line => 0,
227
+ # :param_name => @ensure_name)
228
+ # subject.clean_storeconfigs(@host, true)
229
+ # end
230
+ # end
231
+ #
232
+ # describe "with an exported definition" do
233
+ # it "should try to lookup a definition and test it for the ensure argument" do
234
+ # Puppet::Type.stubs(:type).returns(nil)
235
+ # definition = stub_everything 'definition', :arguments => { 'ensure' => 'present' }
236
+ # Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(definition)
237
+ # subject.clean_storeconfigs(@host, true)
238
+ # end
239
+ # end
240
+ #
241
+ # it "should not unexport the resource of an unknown type" do
242
+ # Puppet::Type.stubs(:type).returns(nil)
243
+ # Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(nil)
244
+ # Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
245
+ # subject.clean_storeconfigs(@host)
246
+ # end
247
+ #
248
+ # it "should not unexport the resource of a not ensurable native type" do
249
+ # Puppet::Type.stubs(:type).returns(@type)
250
+ # @type.expects(:validattr?).with(:ensure).returns(false)
251
+ # Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(nil)
252
+ # Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
253
+ # subject.clean_storeconfigs(@host, true)
254
+ # end
255
+ #
256
+ # it "should not unexport the resource of a not ensurable definition" do
257
+ # Puppet::Type.stubs(:type).returns(nil)
258
+ # definition = stub_everything 'definition', :arguments => { 'foobar' => 'someValue' }
259
+ # Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(definition)
260
+ # Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
261
+ # subject.clean_storeconfigs(@host, true)
262
+ # end
263
+ # end
264
+ # end
265
+ end
266
+ end
7
267
  end