chef 12.18.31-universal-mingw32 → 12.19.33-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -4
  3. data/README.md +12 -13
  4. data/VERSION +1 -1
  5. data/acceptance/Gemfile +4 -4
  6. data/acceptance/Gemfile.lock +70 -69
  7. data/chef-universal-mingw32.gemspec +2 -3
  8. data/chef.gemspec +6 -6
  9. data/lib/chef/api_client.rb +8 -10
  10. data/lib/chef/api_client_v1.rb +9 -11
  11. data/lib/chef/application/apply.rb +8 -10
  12. data/lib/chef/application/client.rb +1 -1
  13. data/lib/chef/application/exit_code.rb +3 -5
  14. data/lib/chef/application/knife.rb +2 -2
  15. data/lib/chef/application/windows_service.rb +29 -30
  16. data/lib/chef/application/windows_service_manager.rb +1 -1
  17. data/lib/chef/audit/audit_event_proxy.rb +2 -2
  18. data/lib/chef/audit/control_group_data.rb +1 -1
  19. data/lib/chef/chef_class.rb +1 -0
  20. data/lib/chef/chef_fs/chef_fs_data_store.rb +5 -7
  21. data/lib/chef/chef_fs/command_line.rb +15 -16
  22. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  23. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  24. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  25. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  26. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  27. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  28. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  29. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
  30. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  31. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
  32. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  33. data/lib/chef/chef_fs/file_system.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +5 -6
  35. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
  36. data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
  37. data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
  38. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
  39. data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
  40. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
  41. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +18 -24
  42. data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
  43. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
  44. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +10 -12
  45. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
  46. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
  47. data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
  48. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
  49. data/lib/chef/chef_fs/parallelizer.rb +9 -11
  50. data/lib/chef/cookbook/cookbook_version_loader.rb +25 -31
  51. data/lib/chef/cookbook/metadata.rb +26 -26
  52. data/lib/chef/cookbook/syntax_check.rb +1 -1
  53. data/lib/chef/cookbook_version.rb +3 -3
  54. data/lib/chef/data_bag.rb +1 -1
  55. data/lib/chef/data_bag_item.rb +3 -3
  56. data/lib/chef/data_collector.rb +3 -4
  57. data/lib/chef/decorator.rb +1 -1
  58. data/lib/chef/deprecated.rb +30 -0
  59. data/lib/chef/dsl/audit.rb +2 -2
  60. data/lib/chef/dsl/declare_resource.rb +1 -1
  61. data/lib/chef/dsl/platform_introspection.rb +29 -31
  62. data/lib/chef/dsl/reboot_pending.rb +1 -1
  63. data/lib/chef/dsl/resources.rb +6 -8
  64. data/lib/chef/encrypted_data_bag_item.rb +2 -2
  65. data/lib/chef/environment.rb +9 -11
  66. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  67. data/lib/chef/exceptions.rb +4 -1
  68. data/lib/chef/file_access_control/unix.rb +14 -14
  69. data/lib/chef/file_access_control/windows.rb +1 -1
  70. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
  71. data/lib/chef/formatters/error_mapper.rb +6 -6
  72. data/lib/chef/http/api_versions.rb +50 -0
  73. data/lib/chef/http/validate_content_length.rb +2 -2
  74. data/lib/chef/json_compat.rb +6 -10
  75. data/lib/chef/key.rb +5 -5
  76. data/lib/chef/knife.rb +4 -4
  77. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  78. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
  79. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  80. data/lib/chef/knife/core/status_presenter.rb +1 -1
  81. data/lib/chef/knife/core/ui.rb +19 -25
  82. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  83. data/lib/chef/knife/deps.rb +32 -34
  84. data/lib/chef/knife/help.rb +1 -1
  85. data/lib/chef/knife/list.rb +1 -1
  86. data/lib/chef/knife/search.rb +2 -2
  87. data/lib/chef/knife/ssh.rb +37 -27
  88. data/lib/chef/knife/ssl_check.rb +1 -1
  89. data/lib/chef/knife/user_delete.rb +1 -1
  90. data/lib/chef/mash.rb +1 -1
  91. data/lib/chef/mixin/command.rb +2 -2
  92. data/lib/chef/mixin/create_path.rb +3 -5
  93. data/lib/chef/mixin/from_file.rb +2 -2
  94. data/lib/chef/mixin/get_source_from_package.rb +2 -2
  95. data/lib/chef/mixin/notifying_block.rb +7 -9
  96. data/lib/chef/mixin/params_validate.rb +3 -3
  97. data/lib/chef/mixin/securable.rb +1 -1
  98. data/lib/chef/mixin/shell_out.rb +23 -3
  99. data/lib/chef/mixin/unformatter.rb +2 -2
  100. data/lib/chef/mixin/uris.rb +4 -6
  101. data/lib/chef/mixin/versioned_api.rb +69 -0
  102. data/lib/chef/mixin/which.rb +25 -8
  103. data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
  104. data/lib/chef/mixin/xml_escape.rb +3 -5
  105. data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
  106. data/lib/chef/node.rb +8 -8
  107. data/lib/chef/node/attribute.rb +4 -4
  108. data/lib/chef/node/common_api.rb +5 -7
  109. data/lib/chef/org.rb +10 -12
  110. data/lib/chef/platform/provider_mapping.rb +7 -7
  111. data/lib/chef/platform/query_helpers.rb +1 -1
  112. data/lib/chef/policy_builder/policyfile.rb +1 -0
  113. data/lib/chef/property.rb +31 -0
  114. data/lib/chef/provider/batch.rb +1 -1
  115. data/lib/chef/provider/breakpoint.rb +1 -1
  116. data/lib/chef/provider/cookbook_file.rb +3 -3
  117. data/lib/chef/provider/cron.rb +38 -38
  118. data/lib/chef/provider/deploy.rb +81 -81
  119. data/lib/chef/provider/deploy/revision.rb +3 -5
  120. data/lib/chef/provider/directory.rb +32 -32
  121. data/lib/chef/provider/dsc_resource.rb +22 -6
  122. data/lib/chef/provider/env.rb +28 -28
  123. data/lib/chef/provider/env/windows.rb +1 -1
  124. data/lib/chef/provider/erl_call.rb +13 -13
  125. data/lib/chef/provider/execute.rb +5 -2
  126. data/lib/chef/provider/file.rb +49 -51
  127. data/lib/chef/provider/git.rb +55 -55
  128. data/lib/chef/provider/http_request.rb +36 -36
  129. data/lib/chef/provider/launchd.rb +2 -2
  130. data/lib/chef/provider/link.rb +50 -50
  131. data/lib/chef/provider/log.rb +2 -2
  132. data/lib/chef/provider/mdadm.rb +25 -25
  133. data/lib/chef/provider/mount/aix.rb +2 -2
  134. data/lib/chef/provider/mount/mount.rb +2 -2
  135. data/lib/chef/provider/ohai.rb +1 -1
  136. data/lib/chef/provider/osx_profile.rb +23 -23
  137. data/lib/chef/provider/package.rb +74 -56
  138. data/lib/chef/provider/package/aix.rb +55 -52
  139. data/lib/chef/provider/package/apt.rb +15 -13
  140. data/lib/chef/provider/package/cab.rb +49 -20
  141. data/lib/chef/provider/package/chocolatey.rb +9 -10
  142. data/lib/chef/provider/package/dnf.rb +20 -18
  143. data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
  144. data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
  145. data/lib/chef/provider/package/dnf/version.rb +1 -1
  146. data/lib/chef/provider/package/dpkg.rb +8 -9
  147. data/lib/chef/provider/package/easy_install.rb +22 -22
  148. data/lib/chef/provider/package/freebsd/base.rb +10 -10
  149. data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
  150. data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
  151. data/lib/chef/provider/package/freebsd/port.rb +7 -7
  152. data/lib/chef/provider/package/homebrew.rb +11 -10
  153. data/lib/chef/provider/package/ips.rb +18 -23
  154. data/lib/chef/provider/package/macports.rb +23 -23
  155. data/lib/chef/provider/package/msu.rb +11 -11
  156. data/lib/chef/provider/package/openbsd.rb +25 -22
  157. data/lib/chef/provider/package/pacman.rb +16 -16
  158. data/lib/chef/provider/package/paludis.rb +26 -27
  159. data/lib/chef/provider/package/portage.rb +22 -22
  160. data/lib/chef/provider/package/powershell.rb +17 -17
  161. data/lib/chef/provider/package/rpm.rb +25 -25
  162. data/lib/chef/provider/package/rubygems.rb +60 -60
  163. data/lib/chef/provider/package/smartos.rb +16 -16
  164. data/lib/chef/provider/package/solaris.rb +44 -44
  165. data/lib/chef/provider/package/windows.rb +3 -3
  166. data/lib/chef/provider/package/windows/exe.rb +6 -6
  167. data/lib/chef/provider/package/windows/msi.rb +6 -6
  168. data/lib/chef/provider/package/yum.rb +318 -268
  169. data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
  170. data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
  171. data/lib/chef/provider/package/zypper.rb +11 -11
  172. data/lib/chef/provider/powershell_script.rb +15 -7
  173. data/lib/chef/provider/reboot.rb +10 -10
  174. data/lib/chef/provider/registry_key.rb +39 -39
  175. data/lib/chef/provider/remote_directory.rb +3 -3
  176. data/lib/chef/provider/remote_file.rb +3 -3
  177. data/lib/chef/provider/route.rb +1 -1
  178. data/lib/chef/provider/ruby_block.rb +3 -3
  179. data/lib/chef/provider/script.rb +42 -6
  180. data/lib/chef/provider/service.rb +49 -49
  181. data/lib/chef/provider/service/solaris.rb +1 -1
  182. data/lib/chef/provider/service/systemd.rb +1 -1
  183. data/lib/chef/provider/subversion.rb +39 -39
  184. data/lib/chef/provider/systemd_unit.rb +2 -0
  185. data/lib/chef/provider/template.rb +3 -3
  186. data/lib/chef/provider/user.rb +42 -42
  187. data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
  188. data/lib/chef/resource.rb +27 -16
  189. data/lib/chef/resource/apt_repository.rb +0 -1
  190. data/lib/chef/resource/chef_gem.rb +1 -1
  191. data/lib/chef/resource/dnf_package.rb +6 -3
  192. data/lib/chef/resource/dsc_resource.rb +9 -1
  193. data/lib/chef/resource/execute.rb +70 -6
  194. data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
  195. data/lib/chef/resource/freebsd_package.rb +1 -1
  196. data/lib/chef/resource/gem_package.rb +1 -1
  197. data/lib/chef/resource/launchd.rb +13 -1
  198. data/lib/chef/resource/package.rb +2 -2
  199. data/lib/chef/resource/registry_key.rb +1 -1
  200. data/lib/chef/resource/yum_package.rb +12 -3
  201. data/lib/chef/resource/yum_repository.rb +0 -1
  202. data/lib/chef/resource_collection/resource_collection_serialization.rb +3 -3
  203. data/lib/chef/resource_collection/resource_set.rb +2 -2
  204. data/lib/chef/resource_reporter.rb +1 -1
  205. data/lib/chef/run_context.rb +3 -3
  206. data/lib/chef/run_list/run_list_item.rb +1 -1
  207. data/lib/chef/run_list/versioned_recipe_list.rb +6 -6
  208. data/lib/chef/server_api.rb +2 -0
  209. data/lib/chef/server_api_versions.rb +40 -0
  210. data/lib/chef/shell.rb +1 -1
  211. data/lib/chef/shell/ext.rb +3 -3
  212. data/lib/chef/shell/shell_session.rb +1 -1
  213. data/lib/chef/user.rb +9 -11
  214. data/lib/chef/user_v1.rb +9 -11
  215. data/lib/chef/util/diff.rb +1 -1
  216. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
  217. data/lib/chef/util/selinux.rb +1 -1
  218. data/lib/chef/util/windows/net_group.rb +18 -30
  219. data/lib/chef/util/windows/net_use.rb +7 -11
  220. data/lib/chef/util/windows/net_user.rb +11 -17
  221. data/lib/chef/util/windows/volume.rb +9 -15
  222. data/lib/chef/version.rb +1 -1
  223. data/lib/chef/version_class.rb +1 -1
  224. data/lib/chef/win32/api.rb +4 -6
  225. data/lib/chef/win32/api/file.rb +25 -31
  226. data/lib/chef/win32/api/installer.rb +2 -2
  227. data/lib/chef/win32/file.rb +4 -6
  228. data/lib/chef/win32/registry.rb +9 -9
  229. data/lib/chef/win32/security.rb +2 -2
  230. data/lib/chef/win32/security/acl.rb +2 -2
  231. data/lib/chef/win32/unicode.rb +2 -2
  232. data/lib/chef/win32/version.rb +1 -1
  233. data/spec/data/prefer_metadata_json/metadata.json +51 -0
  234. data/spec/data/prefer_metadata_json/metadata.rb +6 -0
  235. data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
  236. data/spec/functional/knife/ssh_spec.rb +5 -5
  237. data/spec/functional/resource/batch_spec.rb +5 -1
  238. data/spec/functional/resource/dsc_script_spec.rb +2 -4
  239. data/spec/functional/resource/execute_spec.rb +17 -0
  240. data/spec/functional/resource/user/dscl_spec.rb +2 -4
  241. data/spec/integration/client/client_spec.rb +33 -0
  242. data/spec/integration/recipes/recipe_dsl_spec.rb +58 -58
  243. data/spec/spec_helper.rb +4 -0
  244. data/spec/support/chef_helpers.rb +5 -7
  245. data/spec/support/platform_helpers.rb +6 -0
  246. data/spec/support/platforms/prof/gc.rb +4 -6
  247. data/spec/support/shared/context/client.rb +1 -1
  248. data/spec/support/shared/functional/execute_resource.rb +150 -0
  249. data/spec/support/shared/functional/windows_script.rb +74 -4
  250. data/spec/support/shared/unit/execute_resource.rb +37 -0
  251. data/spec/support/shared/unit/provider/file.rb +10 -0
  252. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +9 -0
  253. data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
  254. data/spec/unit/http/api_versions_spec.rb +69 -0
  255. data/spec/unit/knife/ssh_spec.rb +34 -36
  256. data/spec/unit/mixin/versioned_api_spec.rb +107 -0
  257. data/spec/unit/mixin/which.rb +160 -0
  258. data/spec/unit/platform_spec.rb +28 -1
  259. data/spec/unit/provider/deploy_spec.rb +1 -1
  260. data/spec/unit/provider/directory_spec.rb +10 -0
  261. data/spec/unit/provider/dsc_resource_spec.rb +175 -0
  262. data/spec/unit/provider/execute_spec.rb +0 -1
  263. data/spec/unit/provider/launchd_spec.rb +2 -2
  264. data/spec/unit/provider/package/aix_spec.rb +22 -22
  265. data/spec/unit/provider/package/apt_spec.rb +27 -27
  266. data/spec/unit/provider/package/cab_spec.rb +59 -5
  267. data/spec/unit/provider/package/dnf/python_helper_spec.rb +29 -0
  268. data/spec/unit/provider/package/dpkg_spec.rb +16 -16
  269. data/spec/unit/provider/package/easy_install_spec.rb +18 -18
  270. data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
  271. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  272. data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
  273. data/spec/unit/provider/package/homebrew_spec.rb +9 -9
  274. data/spec/unit/provider/package/ips_spec.rb +37 -31
  275. data/spec/unit/provider/package/macports_spec.rb +10 -10
  276. data/spec/unit/provider/package/openbsd_spec.rb +10 -10
  277. data/spec/unit/provider/package/pacman_spec.rb +6 -6
  278. data/spec/unit/provider/package/paludis_spec.rb +7 -7
  279. data/spec/unit/provider/package/portage_spec.rb +6 -7
  280. data/spec/unit/provider/package/rpm_spec.rb +23 -23
  281. data/spec/unit/provider/package/rubygems_spec.rb +38 -38
  282. data/spec/unit/provider/package/solaris_spec.rb +15 -15
  283. data/spec/unit/provider/package/windows_spec.rb +2 -1
  284. data/spec/unit/provider/package/yum_spec.rb +51 -43
  285. data/spec/unit/provider/package/zypper_spec.rb +34 -34
  286. data/spec/unit/provider/package_spec.rb +8 -0
  287. data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
  288. data/spec/unit/provider/route_spec.rb +7 -1
  289. data/spec/unit/provider/script_spec.rb +49 -6
  290. data/spec/unit/resource/dsc_resource_spec.rb +6 -0
  291. data/spec/unit/resource/execute_spec.rb +214 -0
  292. data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
  293. data/spec/unit/resource/freebsd_package_spec.rb +2 -2
  294. data/spec/unit/resource/package_spec.rb +5 -0
  295. data/spec/unit/resource/yum_package_spec.rb +42 -1
  296. data/spec/unit/resource_reporter_spec.rb +1 -1
  297. data/spec/unit/resource_spec.rb +18 -0
  298. data/spec/unit/server_api_versions_spec.rb +44 -0
  299. data/spec/unit/util/selinux_spec.rb +3 -14
  300. data/spec/unit/win32/error_spec.rb +67 -0
  301. data/spec/unit/win32/security_spec.rb +66 -0
  302. data/tasks/changelog.rb +1 -1
  303. data/tasks/dependencies.rb +20 -4
  304. metadata +39 -18
  305. data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
@@ -517,6 +517,10 @@ describe "Subclass with use_multipackage_api" do
517
517
  end
518
518
 
519
519
  context "#a_to_s utility for subclasses" do
520
+ before(:each) do
521
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
522
+ end
523
+
520
524
  it "converts varargs of strings to a single string" do
521
525
  expect(provider.send(:a_to_s, "a", nil, "b", "", "c", " ", "d e", "f-g")).to eq("a b c d e f-g")
522
526
  end
@@ -906,6 +910,10 @@ describe "Chef::Provider::Package - Multi" do
906
910
  end
907
911
 
908
912
  describe "shell_out helpers" do
913
+ before(:each) do
914
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
915
+ end
916
+
909
917
  [ :shell_out_with_timeout, :shell_out_with_timeout! ].each do |method|
910
918
  stubbed_method = method == :shell_out_with_timeout! ? :shell_out! : :shell_out
911
919
  [ %w{command arg1 arg2}, "command arg1 arg2" ].each do |command|
@@ -117,7 +117,7 @@ describe Chef::Provider::RemoteFile::SFTP do
117
117
  end
118
118
 
119
119
  context "and the URI specifies an alternate port" do
120
- let(:uri) { URI.parse("ftp://conan:cthu1hu@opscode.com:8021/seattle.txt") }
120
+ let(:uri) { URI.parse("sftp://conan:cthu1hu@opscode.com:8021/seattle.txt") }
121
121
 
122
122
  it "should connect on an alternate port when one is provided" do
123
123
  expect(Net::SFTP).to receive(:start).with("opscode.com:8021", "conan", :password => "cthu1hu")
@@ -127,10 +127,10 @@ describe Chef::Provider::RemoteFile::SFTP do
127
127
  end
128
128
 
129
129
  context "and the uri specifies a nested path" do
130
- let(:uri) { URI.parse("ftp://conan:cthu1hu@opscode.com/the/whole/path/seattle.txt") }
130
+ let(:uri) { URI.parse("sftp://conan:cthu1hu@opscode.com/the/whole/path/seattle.txt") }
131
131
 
132
132
  it "should fetch the file from the correct path" do
133
- expect(sftp).to receive(:download!).with("the/whole/path/seattle.txt", "/tmp/somedir/remote-file-sftp-backend-spec-test")
133
+ expect(sftp).to receive(:download!).with("/the/whole/path/seattle.txt", "/tmp/somedir/remote-file-sftp-backend-spec-test")
134
134
  fetcher.fetch
135
135
  end
136
136
  end
@@ -230,13 +230,19 @@ describe Chef::Provider::Route do
230
230
  @run_context.resource_collection << Chef::Resource::Route.new("192.168.1.0/24 via 192.168.0.1")
231
231
  @run_context.resource_collection << Chef::Resource::Route.new("192.168.2.0/24 via 192.168.0.1")
232
232
  @run_context.resource_collection << Chef::Resource::Route.new("192.168.3.0/24 via 192.168.0.1")
233
+ @run_context.resource_collection << Chef::Resource::Route.new("Complex Route").tap do |r|
234
+ r.target "192.168.4.0"
235
+ r.gateway "192.168.0.1"
236
+ r.netmask "255.255.255.0"
237
+ end
233
238
 
234
239
  @provider.action = :add
235
240
  @provider.generate_config
236
- expect(route_file.string.split("\n").size).to eq(3)
241
+ expect(route_file.string.split("\n").size).to eq(4)
237
242
  expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/)
238
243
  expect(route_file.string).to match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/)
239
244
  expect(route_file.string).to match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/)
245
+ expect(route_file.string).to match(/^192\.168\.4\.0\/24 via 192\.168\.0\.1$/)
240
246
  end
241
247
  end
242
248
  end
@@ -56,12 +56,55 @@ describe Chef::Provider::Script, "action_run" do
56
56
  end
57
57
  end
58
58
 
59
- context "#set_owner_and_group" do
60
- it "sets the owner and group for the script file" do
61
- new_resource.user "toor"
62
- new_resource.group "wheel"
63
- expect(FileUtils).to receive(:chown).with("toor", "wheel", tempfile.path)
64
- provider.set_owner_and_group
59
+ context "when configuring the script file's security" do
60
+ context "when not running on Windows" do
61
+ before do
62
+ allow(::Chef::Platform).to receive(:windows?).and_return(false)
63
+ end
64
+ context "#set_owner_and_group" do
65
+ it "sets the owner and group for the script file" do
66
+ new_resource.user "toor"
67
+ new_resource.group "wheel"
68
+ expect(FileUtils).to receive(:chown).with("toor", "wheel", tempfile.path)
69
+ provider.set_owner_and_group
70
+ end
71
+ end
72
+ end
73
+
74
+ context "when running on Windows" do
75
+ before do
76
+ allow(::Chef::Platform).to receive(:windows?).and_return(true)
77
+ expect(new_resource.user).to eq(nil)
78
+ stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_READ", 1)
79
+ stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE", 4)
80
+ stub_const("Chef::ReservedNames::Win32::Security", Class.new)
81
+ stub_const("Chef::ReservedNames::Win32::Security::SecurableObject", Class.new)
82
+ stub_const("Chef::ReservedNames::Win32::Security::SID", Class.new)
83
+ stub_const("Chef::ReservedNames::Win32::Security::ACE", Class.new)
84
+ stub_const("Chef::ReservedNames::Win32::Security::ACL", Class.new)
85
+ end
86
+
87
+ context "when an alternate user is not specified" do
88
+ it "does not attempt to set the script file's security descriptor" do
89
+ expect(provider).to receive(:grant_alternate_user_read_access)
90
+ expect(Chef::ReservedNames::Win32::Security::SecurableObject).not_to receive(:new)
91
+ provider.set_owner_and_group
92
+ end
93
+ end
94
+
95
+ context "when an alternate user is specified" do
96
+ let(:security_descriptor) { instance_double("Chef::ReservedNames::Win32::Security::SecurityDescriptor", :dacl => []) }
97
+ let(:securable_object) { instance_double("Chef::ReservedNames::Win32::Security::SecurableObject", :security_descriptor => security_descriptor, :dacl= => nil) }
98
+ it "sets the script file's security descriptor" do
99
+ new_resource.user("toor")
100
+ expect(Chef::ReservedNames::Win32::Security::SecurableObject).to receive(:new).and_return(securable_object)
101
+ expect(Chef::ReservedNames::Win32::Security::SID).to receive(:from_account).and_return(nil)
102
+ expect(Chef::ReservedNames::Win32::Security::ACE).to receive(:access_allowed).and_return(nil)
103
+ expect(Chef::ReservedNames::Win32::Security::ACL).to receive(:create).and_return(nil)
104
+ expect(securable_object).to receive(:dacl=)
105
+ provider.set_owner_and_group
106
+ end
107
+ end
65
108
  end
66
109
  end
67
110
 
@@ -18,6 +18,7 @@
18
18
  require "spec_helper"
19
19
  describe Chef::Resource::DscResource do
20
20
  let(:dsc_test_resource_name) { "DSCTest" }
21
+ let(:dsc_test_resource_module_version) { "2.7.2" }
21
22
  let(:dsc_test_property_name) { :DSCTestProperty }
22
23
  let(:dsc_test_property_value) { "DSCTestValue" }
23
24
  let(:dsc_test_reboot_action) { :reboot_now }
@@ -53,6 +54,11 @@ describe Chef::Resource::DscResource do
53
54
  expect(dsc_test_resource.module_name).to eq(dsc_test_resource_name)
54
55
  end
55
56
 
57
+ it "allows the module_version attribute to be set" do
58
+ dsc_test_resource.module_version(dsc_test_resource_module_version)
59
+ expect(dsc_test_resource.module_version).to eq(dsc_test_resource_module_version)
60
+ end
61
+
56
62
  it "allows the reboot_action attribute to be set" do
57
63
  dsc_test_resource.reboot_action(dsc_test_reboot_action)
58
64
  expect(dsc_test_resource.reboot_action).to eq(dsc_test_reboot_action)
@@ -32,4 +32,218 @@ describe Chef::Resource::Execute do
32
32
  expect(execute_resource.is_guard_interpreter).to eq(false)
33
33
  end
34
34
 
35
+ describe "#qualify_user" do
36
+ let(:password) { "password" }
37
+ let(:domain) { nil }
38
+
39
+ context "when username is passed as user@domain" do
40
+ let(:username) { "user@domain" }
41
+
42
+ it "correctly parses the user and domain" do
43
+ identity = execute_resource.qualify_user(username, password, domain)
44
+ expect(identity[:domain]).to eq("domain")
45
+ expect(identity[:user]).to eq("user")
46
+ end
47
+ end
48
+
49
+ context "when username is passed as domain\\user" do
50
+ let(:username) { "domain\\user" }
51
+
52
+ it "correctly parses the user and domain" do
53
+ identity = execute_resource.qualify_user(username, password, domain)
54
+ expect(identity[:domain]).to eq("domain")
55
+ expect(identity[:user]).to eq("user")
56
+ end
57
+ end
58
+ end
59
+
60
+ shared_examples_for "it received valid credentials" do
61
+ describe "the validation method" do
62
+ it "should not raise an error" do
63
+ expect { execute_resource.validate_identity_platform(username, password, domain) }.not_to raise_error
64
+ end
65
+ end
66
+
67
+ describe "the name qualification method" do
68
+ it "should correctly translate the user and domain" do
69
+ identity = nil
70
+ expect { identity = execute_resource.qualify_user(username, password, domain) }.not_to raise_error
71
+ expect(identity[:domain]).to eq(domain)
72
+ expect(identity[:user]).to eq(username)
73
+ end
74
+ end
75
+ end
76
+
77
+ shared_examples_for "it received invalid credentials" do
78
+ describe "the validation method" do
79
+ it "should raise an error" do
80
+ expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(ArgumentError)
81
+ end
82
+ end
83
+ end
84
+
85
+ shared_examples_for "it received invalid username and domain" do
86
+ describe "the validation method" do
87
+ it "should raise an error" do
88
+ expect { execute_resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError)
89
+ end
90
+ end
91
+ end
92
+
93
+ shared_examples_for "it received credentials that are not valid on the platform" do
94
+ describe "the validation method" do
95
+ it "should raise an error" do
96
+ expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
97
+ end
98
+ end
99
+ end
100
+
101
+ shared_examples_for "a consumer of the Execute resource" do
102
+ context "when running on Windows" do
103
+ before do
104
+ allow(execute_resource).to receive(:node).and_return({ :platform_family => "windows" })
105
+ end
106
+
107
+ context "when no user, domain, or password is specified" do
108
+ let(:username) { nil }
109
+ let(:domain) { nil }
110
+ let(:password) { nil }
111
+ it_behaves_like "it received valid credentials"
112
+ end
113
+
114
+ context "when a valid username is specified" do
115
+ let(:username) { "starchild" }
116
+ context "when a valid domain is specified" do
117
+ let(:domain) { "mothership" }
118
+
119
+ context "when the password is not specified" do
120
+ let(:password) { nil }
121
+ it_behaves_like "it received invalid credentials"
122
+ end
123
+
124
+ context "when the password is specified" do
125
+ let(:password) { "we.funk!" }
126
+ it_behaves_like "it received valid credentials"
127
+ end
128
+ end
129
+
130
+ context "when the domain is not specified" do
131
+ let(:domain) { nil }
132
+
133
+ context "when the password is not specified" do
134
+ let(:password) { nil }
135
+ it_behaves_like "it received invalid credentials"
136
+ end
137
+
138
+ context "when the password is specified" do
139
+ let(:password) { "we.funk!" }
140
+ it_behaves_like "it received valid credentials"
141
+ end
142
+ end
143
+
144
+ context "when username is not specified" do
145
+ let(:username) { nil }
146
+
147
+ context "when domain is specified" do
148
+ let(:domain) { "mothership" }
149
+ let(:password) { nil }
150
+ it_behaves_like "it received invalid username and domain"
151
+ end
152
+
153
+ context "when password is specified" do
154
+ let(:domain) { nil }
155
+ let(:password) { "we.funk!" }
156
+ it_behaves_like "it received invalid username and domain"
157
+ end
158
+ end
159
+ end
160
+
161
+ context "when invalid username is specified" do
162
+ let(:username) { "user@domain@domain" }
163
+ let(:domain) { nil }
164
+ let(:password) { "we.funk!" }
165
+ it_behaves_like "it received invalid username and domain"
166
+ end
167
+
168
+ context "when the domain is provided in both username and domain" do
169
+ let(:domain) { "some_domain" }
170
+ let(:password) { "we.funk!" }
171
+
172
+ context "when username is in the form domain\\user" do
173
+ let(:username) { "mothership\\starchild" }
174
+ it_behaves_like "it received invalid username and domain"
175
+ end
176
+
177
+ context "when username is in the form user@domain" do
178
+ let(:username) { "starchild@mothership" }
179
+ it_behaves_like "it received invalid username and domain"
180
+ end
181
+ end
182
+ end
183
+
184
+ context "when not running on Windows" do
185
+ before do
186
+ allow(execute_resource).to receive(:node).and_return({ :platform_family => "ubuntu" })
187
+ end
188
+
189
+ context "when no user, domain, or password is specified" do
190
+ let(:username) { nil }
191
+ let(:domain) { nil }
192
+ let(:password) { nil }
193
+ it_behaves_like "it received valid credentials"
194
+ end
195
+
196
+ context "when the user is specified and the domain and password are not" do
197
+ let(:username) { "starchild" }
198
+ let(:domain) { nil }
199
+ let(:password) { nil }
200
+ it_behaves_like "it received valid credentials"
201
+
202
+ context "when the password is specified and the domain is not" do
203
+ let(:password) { "we.funk!" }
204
+ let(:domain) { nil }
205
+ it_behaves_like "it received credentials that are not valid on the platform"
206
+ end
207
+
208
+ context "when the domain is specified and the password is not" do
209
+ let(:domain) { "mothership" }
210
+ let(:password) { nil }
211
+ it_behaves_like "it received credentials that are not valid on the platform"
212
+ end
213
+
214
+ context "when the domain and password are specified" do
215
+ let(:domain) { "mothership" }
216
+ let(:password) { "we.funk!" }
217
+ it_behaves_like "it received credentials that are not valid on the platform"
218
+ end
219
+ end
220
+
221
+ context "when the user is not specified" do
222
+ let(:username) { nil }
223
+ context "when the domain is specified" do
224
+ let(:domain) { "mothership" }
225
+ context "when the password is specified" do
226
+ let(:password) { "we.funk!" }
227
+ it_behaves_like "it received credentials that are not valid on the platform"
228
+ end
229
+
230
+ context "when password is not specified" do
231
+ let(:password) { nil }
232
+ it_behaves_like "it received credentials that are not valid on the platform"
233
+ end
234
+ end
235
+
236
+ context "when the domain is not specified" do
237
+ let(:domain) { nil }
238
+ context "when the password is specified" do
239
+ let(:password) { "we.funk!" }
240
+ it_behaves_like "it received credentials that are not valid on the platform"
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
246
+
247
+ it_behaves_like "a consumer of the Execute resource"
248
+
35
249
  end
@@ -0,0 +1,103 @@
1
+ #
2
+ # Author:: Mal Graty (<mal.graty@googlemail.com>)
3
+ # Copyright:: Copyright 2014-2017, Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "spec_helper"
20
+
21
+ describe Chef::Resource::File::Verification::SystemdUnit do
22
+ let(:command) { "#{systemd_analyze_path} verify %{path}" }
23
+ let(:opts) { { :future => true } }
24
+ let(:parent_resource) { Chef::Resource.new("llama") }
25
+ let(:systemd_analyze_path) { "/usr/bin/systemd-analyze" }
26
+ let(:systemd_dir) { "/etc/systemd/system" }
27
+ let(:temp_path) { "/tmp" }
28
+ let(:unit_name) { "sysstat-collect.timer" }
29
+ let(:unit_path) { "#{systemd_dir}/#{unit_name}" }
30
+ let(:unit_temp_path) { "#{systemd_dir}/.chef-#{unit_name}" }
31
+ let(:unit_test_path) { "#{temp_path}/#{unit_name}" }
32
+
33
+ describe "verification registration" do
34
+ it "registers itself for later use" do
35
+ expect(Chef::Resource::File::Verification.lookup(:systemd_unit)).to eq(Chef::Resource::File::Verification::SystemdUnit)
36
+ end
37
+ end
38
+
39
+ describe "#initialize" do
40
+ before(:each) do
41
+ allow_any_instance_of(Chef::Resource::File::Verification::SystemdUnit).to receive(:which)
42
+ .with("systemd-analyze")
43
+ .and_return(systemd_analyze_path)
44
+ end
45
+
46
+ it "overwrites the @command variable with the verification command" do
47
+ v = Chef::Resource::File::Verification::SystemdUnit.new(parent_resource, :systemd_unit, {})
48
+ expect(v.instance_variable_get(:@command)).to eql(command)
49
+ end
50
+ end
51
+
52
+ describe "#verify" do
53
+ context "with the systemd-analyze binary available" do
54
+ before(:each) do
55
+ allow_any_instance_of(Chef::Resource::File::Verification::SystemdUnit).to receive(:which)
56
+ .with("systemd-analyze")
57
+ .and_return(systemd_analyze_path)
58
+
59
+ allow(parent_resource).to receive(:path)
60
+ .and_return(unit_path)
61
+ allow(Dir).to receive(:mktmpdir)
62
+ .with("chef-systemd-unit") { |&b| b.call temp_path }
63
+ allow(FileUtils).to receive(:cp)
64
+ .with(unit_temp_path, unit_test_path)
65
+ end
66
+
67
+ it "copies the temp file to secondary location under correct name" do
68
+ v = Chef::Resource::File::Verification::SystemdUnit.new(parent_resource, :systemd_unit, {})
69
+
70
+ expect(FileUtils).to receive(:cp).with(unit_temp_path, unit_test_path)
71
+ expect(v).to receive(:verify_command).with(unit_test_path, opts)
72
+
73
+ v.verify(unit_temp_path, opts)
74
+ end
75
+
76
+ it "returns the value given by #verify_command" do
77
+ v = Chef::Resource::File::Verification::SystemdUnit.new(parent_resource, :systemd_unit, {})
78
+
79
+ expect(v).to receive(:verify_command)
80
+ .with(unit_test_path, opts)
81
+ .and_return("foo")
82
+
83
+ expect(v.verify(unit_temp_path, opts)).to eql("foo")
84
+ end
85
+ end
86
+
87
+ context "with the systemd-analyze binary unavailable" do
88
+ before(:each) do
89
+ allow_any_instance_of(Chef::Resource::File::Verification::SystemdUnit).to receive(:which)
90
+ .with("systemd-analyze")
91
+ .and_return(false)
92
+ end
93
+
94
+ it "skips verification" do
95
+ v = Chef::Resource::File::Verification::SystemdUnit.new(parent_resource, :systemd_unit, {})
96
+
97
+ expect(v).to_not receive(:verify_command)
98
+
99
+ expect(v.verify(unit_temp_path)).to eq(true)
100
+ end
101
+ end
102
+ end
103
+ end