chef 13.6.4 → 13.7.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +6 -6
  256. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  257. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
@@ -229,7 +229,7 @@ module ResourceActionSpec
229
229
  end
230
230
 
231
231
  context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do
232
- before(:context) do
232
+ before(:each) do
233
233
  class ActionJackgrandson < ActionJackson
234
234
  use_automatic_resource_name
235
235
  end
@@ -509,7 +509,7 @@ module ResourceActionSpec
509
509
  Chef::Config[:treat_deprecation_warnings_as_errors] = false
510
510
  expect_converge do
511
511
  has_property_named_template "hi"
512
- end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/)
512
+ end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/)
513
513
  end
514
514
  end
515
515
 
@@ -17,7 +17,7 @@ describe "Resource::ActionClass#converge_if_changed" do
17
17
  before { Namer.current_index += 1 }
18
18
  before { Namer.incrementing_value = 0 }
19
19
 
20
- context "when the resource has identity, state and control properties" do
20
+ context "when the resource has identity, state, control, and sensitive properties" do
21
21
  let(:resource_name) { :"converge_if_changed_dsl#{Namer.current_index}" }
22
22
  let(:resource_class) do
23
23
  result = Class.new(Chef::Resource) do
@@ -28,6 +28,7 @@ describe "Resource::ActionClass#converge_if_changed" do
28
28
  property :control1, desired_state: false, default: "default_control1"
29
29
  property :state1, default: "default_state1"
30
30
  property :state2, default: "default_state2"
31
+ property :sensitive1, default: "default_dontprintme", sensitive: true
31
32
  attr_accessor :converged
32
33
  def initialize(*args)
33
34
  super
@@ -54,6 +55,7 @@ describe "Resource::ActionClass#converge_if_changed" do
54
55
  resource_class.load_current_value do
55
56
  state1 "current_state1"
56
57
  state2 "current_state2"
58
+ sensitive1 "current_dontprintme"
57
59
  end
58
60
  end
59
61
 
@@ -134,6 +136,26 @@ EOM
134
136
  end
135
137
  end
136
138
 
139
+ context "and sensitive1 is set to a new value" do
140
+ let(:converge_recipe) do
141
+ <<-EOM
142
+ #{resource_name} 'blah' do
143
+ sensitive1 'new_dontprintme'
144
+ end
145
+ EOM
146
+ end
147
+
148
+ it "the resource updates sensitive1" do
149
+ expect(resource.converged).to eq 1
150
+ expect(resource.updated?).to be_truthy
151
+ expect(converged_recipe.stdout).to eq <<-EOM
152
+ * #{resource_name}[blah] action create
153
+ - update default_identity1
154
+ - set sensitive1 to (suppressed sensitive property)
155
+ EOM
156
+ end
157
+ end
158
+
137
159
  context "and state1 is set to its current value but state2 is set to a new value" do
138
160
  let(:converge_recipe) do
139
161
  <<-EOM
@@ -244,19 +266,21 @@ EOM
244
266
  expect(converged_recipe.stdout).to eq <<-EOM
245
267
  * #{resource_name}[blah] action create
246
268
  - create default_identity1
247
- - set identity1 to "default_identity1" (default value)
248
- - set state1 to "default_state1" (default value)
249
- - set state2 to "default_state2" (default value)
269
+ - set identity1 to "default_identity1" (default value)
270
+ - set state1 to "default_state1" (default value)
271
+ - set state2 to "default_state2" (default value)
272
+ - set sensitive1 to (suppressed sensitive property) (default value)
250
273
  EOM
251
274
  end
252
275
  end
253
276
 
254
- context "and state1 and state2 are set" do
277
+ context "and state1, state2, and sensitive1 are set" do
255
278
  let(:converge_recipe) do
256
279
  <<-EOM
257
280
  #{resource_name} 'blah' do
258
281
  state1 'new_state1'
259
282
  state2 'new_state2'
283
+ sensitive1 'new_dontprintme'
260
284
  end
261
285
  EOM
262
286
  end
@@ -267,9 +291,10 @@ EOM
267
291
  expect(converged_recipe.stdout).to eq <<-EOM
268
292
  * #{resource_name}[blah] action create
269
293
  - create default_identity1
270
- - set identity1 to "default_identity1" (default value)
271
- - set state1 to "new_state1"
272
- - set state2 to "new_state2"
294
+ - set identity1 to "default_identity1" (default value)
295
+ - set state1 to "new_state1"
296
+ - set state2 to "new_state2"
297
+ - set sensitive1 to (suppressed sensitive property)
273
298
  EOM
274
299
  end
275
300
  end
@@ -291,9 +316,10 @@ EOM
291
316
  expect(converged_recipe.stdout).to eq <<-EOM
292
317
  * #{resource_name}[blah] action create
293
318
  - create default_identity1
294
- - set identity1 to (suppressed sensitive property) (default value)
295
- - set state1 to (suppressed sensitive property)
296
- - set state2 to (suppressed sensitive property)
319
+ - set identity1 to (suppressed sensitive property) (default value)
320
+ - set state1 to (suppressed sensitive property)
321
+ - set state2 to (suppressed sensitive property)
322
+ - set sensitive1 to (suppressed sensitive property) (default value)
297
323
  EOM
298
324
  end
299
325
  end
@@ -309,6 +335,9 @@ EOM
309
335
  converge_if_changed :state2 do
310
336
  new_resource.converged += 1
311
337
  end
338
+ converge_if_changed :sensitive1 do
339
+ new_resource.converged += 1
340
+ end
312
341
  end
313
342
  end
314
343
 
@@ -412,6 +441,26 @@ EOM
412
441
  expect(resource.updated?).to be_falsey
413
442
  expect(converged_recipe.stdout).to eq <<-EOM
414
443
  * #{resource_name}[blah] action create (up to date)
444
+ EOM
445
+ end
446
+ end
447
+
448
+ context "and sensitive1 is set to a new value" do
449
+ let(:converge_recipe) do
450
+ <<-EOM
451
+ #{resource_name} 'blah' do
452
+ sensitive1 'new_dontprintme'
453
+ end
454
+ EOM
455
+ end
456
+
457
+ it "the resource updates sensitive1" do
458
+ expect(resource.converged).to eq 1
459
+ expect(resource.updated?).to be_truthy
460
+ expect(converged_recipe.stdout).to eq <<-EOM
461
+ * #{resource_name}[blah] action create
462
+ - update default_identity1
463
+ - set sensitive1 to (suppressed sensitive property)
415
464
  EOM
416
465
  end
417
466
  end
@@ -430,7 +479,7 @@ EOM
430
479
  end
431
480
 
432
481
  it "the resource is created" do
433
- expect(resource.converged).to eq 2
482
+ expect(resource.converged).to eq 3
434
483
  expect(resource.updated?).to be_truthy
435
484
  expect(converged_recipe.stdout).to eq <<-EOM
436
485
  * #{resource_name}[blah] action create
@@ -438,22 +487,25 @@ EOM
438
487
  - set state1 to "default_state1" (default value)
439
488
  - create default_identity1
440
489
  - set state2 to "default_state2" (default value)
490
+ - create default_identity1
491
+ - set sensitive1 to (suppressed sensitive property) (default value)
441
492
  EOM
442
493
  end
443
494
  end
444
495
 
445
- context "and state1 and state2 are set to new values" do
496
+ context "and state1, state2, and sensitive1 are set to new values" do
446
497
  let(:converge_recipe) do
447
498
  <<-EOM
448
499
  #{resource_name} 'blah' do
449
500
  state1 'new_state1'
450
501
  state2 'new_state2'
502
+ sensitive1 'new_dontprintme'
451
503
  end
452
504
  EOM
453
505
  end
454
506
 
455
507
  it "the resource is created" do
456
- expect(resource.converged).to eq 2
508
+ expect(resource.converged).to eq 3
457
509
  expect(resource.updated?).to be_truthy
458
510
  expect(converged_recipe.stdout).to eq <<-EOM
459
511
  * #{resource_name}[blah] action create
@@ -461,6 +513,8 @@ EOM
461
513
  - set state1 to "new_state1"
462
514
  - create default_identity1
463
515
  - set state2 to "new_state2"
516
+ - create default_identity1
517
+ - set sensitive1 to (suppressed sensitive property)
464
518
  EOM
465
519
  end
466
520
  end
@@ -477,7 +531,7 @@ EOM
477
531
  end
478
532
 
479
533
  it "the resource is created" do
480
- expect(resource.converged).to eq 2
534
+ expect(resource.converged).to eq 3
481
535
  expect(resource.updated?).to be_truthy
482
536
  expect(converged_recipe.stdout).to eq <<-EOM
483
537
  * #{resource_name}[blah] action create
@@ -485,6 +539,8 @@ EOM
485
539
  - set state1 to (suppressed sensitive property)
486
540
  - create default_identity1
487
541
  - set state2 to (suppressed sensitive property)
542
+ - create default_identity1
543
+ - set sensitive1 to (suppressed sensitive property) (default value)
488
544
  EOM
489
545
  end
490
546
  end
@@ -111,6 +111,11 @@ TEST_PLATFORM = TEST_NODE["platform"]
111
111
  TEST_PLATFORM_VERSION = TEST_NODE["platform_version"]
112
112
  TEST_PLATFORM_FAMILY = TEST_NODE["platform_family"]
113
113
 
114
+ provider_priority_map ||= nil
115
+ resource_priority_map ||= nil
116
+ provider_handler_map ||= nil
117
+ resource_handler_map ||= nil
118
+
114
119
  RSpec.configure do |config|
115
120
  config.include(Matchers)
116
121
  config.include(MockShellout::RSpec)
@@ -233,6 +238,20 @@ RSpec.configure do |config|
233
238
 
234
239
  # Set environment variable so the setting persists in child processes
235
240
  ENV["CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS"] = "1"
241
+
242
+ # we don't perfectly reset the priority/handler maps here, but by dup'ing the top level hash we
243
+ # throw away all the garbage resources and providers that we setup. if we mutate something like
244
+ # :package then that'll carry over from test-to-test, but the solution would be to deep-dup on every
245
+ # single test we run which is much more expensive. by throwing away the garbage top level keys we
246
+ # significantly speed up test runs.
247
+ provider_handler_map ||= Chef.provider_handler_map.send(:map).dup
248
+ resource_handler_map ||= Chef.resource_handler_map.send(:map).dup
249
+ provider_priority_map ||= Chef.provider_priority_map.send(:map).dup
250
+ resource_priority_map ||= Chef.resource_priority_map.send(:map).dup
251
+ Chef.provider_handler_map.instance_variable_set(:@map, provider_handler_map.dup)
252
+ Chef.resource_handler_map.instance_variable_set(:@map, resource_handler_map.dup)
253
+ Chef.provider_priority_map.instance_variable_set(:@map, provider_priority_map.dup)
254
+ Chef.resource_priority_map.instance_variable_set(:@map, resource_priority_map.dup)
236
255
  end
237
256
 
238
257
  # raise if anyone commits any test to CI with :focus set on it
@@ -63,7 +63,7 @@ shared_context "a command that can be executed as an alternate user" do
63
63
 
64
64
  after do
65
65
  File.delete(script_output_path) if File.exists?(script_output_path)
66
- Dir.rmdir(script_output_dir) if Dir.exists?(script_output_dir)
66
+ Dir.rmdir(script_output_dir) if Dir.exist?(script_output_dir)
67
67
  end
68
68
  end
69
69
 
@@ -38,9 +38,11 @@ shared_examples_for "an application that loads a dot d" do
38
38
  it "loads the configuration in order" do
39
39
  expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
40
40
  expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
41
+ expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_return("strings 0")
41
42
  allow(app).to receive(:apply_config).with(anything(), Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_call_original.ordered
42
43
  expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
43
44
  expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
45
+ expect(app).to receive(:apply_config).with("strings 0", Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_call_original.ordered
44
46
  app.reconfigure
45
47
  end
46
48
  end
@@ -139,7 +139,14 @@ shared_examples_for "an execute resource" do
139
139
  it "should be true if the password is non-nil but the value is explicitly set to false" do
140
140
  @resource.password("we.funk!")
141
141
  @resource.sensitive false
142
- expect(@resource.sensitive).to eq(true)
142
+ expect(@resource.sensitive).to eq(false)
143
+ end
144
+
145
+ # added this test to ensure setting of password property after or before sensitive does not matter
146
+ it "should be false if the sensitive is set before password property" do
147
+ @resource.sensitive false
148
+ @resource.password("we.funk!")
149
+ expect(@resource.sensitive).to eq(false)
143
150
  end
144
151
 
145
152
  end
@@ -476,7 +476,15 @@ shared_examples_for Chef::Provider::File do
476
476
  allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false)
477
477
  provider.new_resource.verify windows? ? "REM" : "true"
478
478
  provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false"
479
- expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed)
479
+ expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}")
480
+ end
481
+
482
+ it "does not show verification for sensitive resources" do
483
+ allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false)
484
+ provider.new_resource.verify windows? ? "REM" : "true"
485
+ provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false"
486
+ provider.new_resource.sensitive true
487
+ expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification [sensitive]")
480
488
  end
481
489
  end
482
490
  end
@@ -66,14 +66,17 @@ describe Chef::ChefFS::DataHandler::DataBagItemDataHandler do
66
66
  end
67
67
  end
68
68
 
69
- context "valid data" do
70
- let(:entry) { TestDataBagItem.new("luggage", "bag") }
71
- let(:object) do
72
- { "raw_data" => { "id" => "bag" } }
73
- end
74
- it "validates the data bag item" do
75
- expect(handler.verify_integrity(object, entry)).to be_nil
69
+ context "using a reserved word as part of the data bag name" do
70
+ %w{xnode rolex xenvironmentx xclientx}.each do |bag_name|
71
+ let(:entry) { TestDataBagItem.new("#{bag_name}", "bag") }
72
+ let(:object) do
73
+ { "raw_data" => { "id" => "bag" } }
74
+ end
75
+ it "allows the data bag name '#{bag_name}'" do
76
+ expect(handler.verify_integrity(object, entry)).to be_nil
77
+ end
76
78
  end
77
79
  end
80
+
78
81
  end
79
82
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Thom May (<thom@chef.io>)
3
- # Copyright:: Copyright 2012-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2012-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -152,7 +152,7 @@ describe Chef::ChefFS::FileSystem::Repository::Directory do
152
152
  end
153
153
 
154
154
  after do
155
- FileUtils.rmdir(tmp_dir)
155
+ FileUtils.rm_rf(tmp_dir)
156
156
  end
157
157
  end
158
158
 
@@ -38,7 +38,7 @@ describe Chef::Client do
38
38
  end
39
39
 
40
40
  it "runs ohai with only the minimum required plugins" do
41
- expected_filter = %w{fqdn machinename hostname platform platform_version os os_version}
41
+ expected_filter = %w{fqdn machinename hostname platform platform_version ohai_time os os_version}
42
42
  expect(ohai_system).to receive(:all_plugins).with(expected_filter)
43
43
  client.run_ohai
44
44
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
2
+ # Copyright:: Copyright 2013-2018, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@ describe Chef::Deprecated do
29
29
 
30
30
  context "loading a deprecation class" do
31
31
  it "loads the correct class" do
32
- expect(Chef::Deprecated.create(:test_deprecation)).to be_an_instance_of(Chef::Deprecated::TestDeprecation)
32
+ expect(Chef::Deprecated.create(:test_deprecation)).to be_an_instance_of(TestDeprecation)
33
33
  end
34
34
 
35
35
  it "optionally sets a message" do
@@ -49,11 +49,11 @@ describe Chef::Deprecated do
49
49
  let(:location) { "the location" }
50
50
 
51
51
  it "displays the full URL" do
52
- expect(Chef::Deprecated::TestDeprecation.new().url).to eql("#{base_url}test.html")
52
+ expect(TestDeprecation.new().url).to eql("#{base_url}test.html")
53
53
  end
54
54
 
55
55
  it "formats a complete deprecation message" do
56
- expect(Chef::Deprecated::TestDeprecation.new(message, location).inspect).to eql("#{message} (CHEF-999)#{location}.\nhttps://docs.chef.io/deprecations_test.html")
56
+ expect(TestDeprecation.new(message, location).inspect).to eql("#{message} (CHEF-999)#{location}.\nhttps://docs.chef.io/deprecations_test.html")
57
57
  end
58
58
  end
59
59
  end
@@ -93,6 +93,15 @@ describe Chef::HTTP do
93
93
  expect { http.send(:stream_to_tempfile, uri, resp) }.to raise_error("TestError")
94
94
  end
95
95
 
96
+ it "accepts a tempfile" do
97
+ resp = Net::HTTPOK.new("1.1", 200, "OK")
98
+ http = Chef::HTTP.new(uri)
99
+ tempfile = Tempfile.open("tempy-mctempfile")
100
+ expect(Tempfile).not_to receive(:open)
101
+ expect(resp).to receive(:read_body).and_yield("conty-mccontent")
102
+ http.send(:stream_to_tempfile, uri, resp, tempfile)
103
+ expect(IO.read(tempfile.path)).to eql("conty-mccontent")
104
+ end
96
105
  end
97
106
 
98
107
  describe "head" do
@@ -516,6 +516,11 @@ describe Chef::Knife::Bootstrap do
516
516
  end
517
517
 
518
518
  context "a flat directory structure" do
519
+ it "escapes single-quotes" do
520
+ expect(rendered_template).to match("cat > /etc/chef/client.d/02-strings.rb <<'EOP'")
521
+ expect(rendered_template).to match("something '\\\\''/foo/bar'\\\\''")
522
+ end
523
+
519
524
  it "creates a file 00-foo.rb" do
520
525
  expect(rendered_template).to match("cat > /etc/chef/client.d/00-foo.rb <<'EOP'")
521
526
  expect(rendered_template).to match("d6f9b976-289c-4149-baf7-81e6ffecf228")
@@ -124,55 +124,12 @@ describe Chef::Knife::Configure do
124
124
  end
125
125
  end
126
126
 
127
- it "asks the user for the location of a chef repo" do
128
- @knife.ask_user_for_config
129
- expect(@out.string).to match(Regexp.escape("Please enter the path to a chef repository (or leave blank):"))
130
- expect(@knife.chef_repo).to eq("")
131
- end
132
-
133
- it "asks the users for the name of the validation client" do
134
- @knife.ask_user_for_config
135
- expect(@out.string).to match(Regexp.escape("Please enter the validation clientname: [chef-validator]"))
136
- expect(@knife.validation_client_name).to eq("chef-validator")
137
- end
138
-
139
- it "should not ask the users for the name of the validation client if --validation_client_name is specified" do
140
- @knife.config[:validation_client_name] = "my-validator"
141
- @knife.ask_user_for_config
142
- expect(@out.string).not_to match(Regexp.escape("Please enter the validation clientname:"))
143
- expect(@knife.validation_client_name).to eq("my-validator")
144
- end
145
-
146
- it "asks the users for the location of the validation key" do
147
- @knife.ask_user_for_config
148
- expect(@out.string).to match(Regexp.escape("Please enter the location of the validation key: [#{default_validator_key}]"))
149
- if windows?
150
- expect(@knife.validation_key.capitalize).to eq(default_validator_key_win32.capitalize)
151
- else
152
- expect(@knife.validation_key).to eq(default_validator_key)
153
- end
154
- end
155
-
156
- it "should not ask the users for the location of the validation key if --validation_key is specified" do
157
- @knife.config[:validation_key] = "/home/you/.chef/my-validation.pem"
158
- @knife.ask_user_for_config
159
- expect(@out.string).not_to match(Regexp.escape("Please enter the location of the validation key:"))
160
- if windows?
161
- expect(@knife.validation_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$}
162
- else
163
- expect(@knife.validation_key).to eq("/home/you/.chef/my-validation.pem")
164
- end
165
- end
166
-
167
127
  it "should not ask the user for anything if -i and all other properties are specified" do
168
128
  @knife.config[:initial] = true
169
129
  @knife.config[:chef_server_url] = "http://localhost:5000"
170
130
  @knife.config[:node_name] = "testnode"
171
131
  @knife.config[:admin_client_name] = "my-webui"
172
132
  @knife.config[:admin_client_key] = "/home/you/.chef/my-webui.pem"
173
- @knife.config[:validation_client_name] = "my-validator"
174
- @knife.config[:validation_key] = "/home/you/.chef/my-validation.pem"
175
- @knife.config[:repository] = ""
176
133
  @knife.config[:client_key] = "/home/you/a-new-user.pem"
177
134
  allow(Etc).to receive(:getlogin).and_return("a-new-user")
178
135
 
@@ -184,40 +141,33 @@ describe Chef::Knife::Configure do
184
141
  expect(@knife.admin_client_name).to eq("my-webui")
185
142
  if windows?
186
143
  expect(@knife.admin_client_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$}
187
- expect(@knife.validation_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$}
188
144
  expect(@knife.new_client_key).to match %r{^[A-Za-z]:/home/you/a-new-user\.pem$}
189
145
  else
190
146
  expect(@knife.admin_client_key).to eq("/home/you/.chef/my-webui.pem")
191
- expect(@knife.validation_key).to eq("/home/you/.chef/my-validation.pem")
192
147
  expect(@knife.new_client_key).to eq("/home/you/a-new-user.pem")
193
148
  end
194
- expect(@knife.validation_client_name).to eq("my-validator")
195
- expect(@knife.chef_repo).to eq("")
196
149
  end
197
150
 
198
151
  it "writes the new data to a config file" do
199
- allow(File).to receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
152
+ allow(Chef::Util::PathHelper).to receive(:home).with(".chef").and_return("/home/you/.chef")
153
+ allow(File).to receive(:expand_path).with("/home/you/.chef/credentials").and_return("/home/you/.chef/credentials")
200
154
  allow(File).to receive(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem")
201
- allow(File).to receive(:expand_path).with(default_validator_key).and_return(default_validator_key)
202
155
  allow(File).to receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
203
156
  expect(FileUtils).to receive(:mkdir_p).with("/home/you/.chef")
204
157
  config_file = StringIO.new
205
- expect(::File).to receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file
158
+ expect(::File).to receive(:open).with("/home/you/.chef/credentials", "w").and_yield config_file
206
159
  @knife.config[:repository] = "/home/you/chef-repo"
207
160
  @knife.run
208
- expect(config_file.string).to match(/^node_name[\s]+'#{Etc.getlogin}'$/)
209
- expect(config_file.string).to match(%r{^client_key[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$})
210
- expect(config_file.string).to match(/^validation_client_name\s+'chef-validator'$/)
211
- expect(config_file.string).to match(%r{^validation_key\s+'#{default_validator_key}'$})
212
- expect(config_file.string).to match(%r{^chef_server_url\s+'#{default_server_url}'$})
213
- expect(config_file.string).to match(%r{cookbook_path\s+\[ '/home/you/chef-repo/cookbooks' \]})
161
+ expect(config_file.string).to match(/^client_name[\s]+=[\s]+'#{Etc.getlogin}'$/)
162
+ expect(config_file.string).to match(%r{^client_key[\s]+=[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$})
163
+ expect(config_file.string).to match(%r{^chef_server_url\s+=[\s]+'#{default_server_url}'$})
214
164
  end
215
165
 
216
166
  it "creates a new client when given the --initial option" do
217
- expect(File).to receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
167
+ allow(Chef::Util::PathHelper).to receive(:home).with(".chef").and_return("/home/you/.chef")
168
+ expect(File).to receive(:expand_path).with("/home/you/.chef/credentials").and_return("/home/you/.chef/credentials")
218
169
  expect(File).to receive(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
219
- expect(File).to receive(:expand_path).with(default_validator_key).and_return(default_validator_key)
220
- expect(File).to receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
170
+ allow(File).to receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
221
171
  Chef::Config[:node_name] = "webmonkey.example.com"
222
172
 
223
173
  user_command = Chef::Knife::UserCreate.new
@@ -227,7 +177,7 @@ describe Chef::Knife::Configure do
227
177
 
228
178
  allow(Chef::Knife::UserCreate).to receive(:new).and_return(user_command)
229
179
  expect(FileUtils).to receive(:mkdir_p).with("/home/you/.chef")
230
- expect(::File).to receive(:open).with("/home/you/.chef/knife.rb", "w")
180
+ expect(::File).to receive(:open).with("/home/you/.chef/credentials", "w")
231
181
  @knife.config[:initial] = true
232
182
  @knife.config[:user_password] = "blah"
233
183
  @knife.run