chef 16.6.14 → 16.7.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -11
  3. data/Rakefile +21 -14
  4. data/chef-universal-mingw32.gemspec +1 -1
  5. data/lib/chef/application/knife.rb +1 -1
  6. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  7. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  8. data/lib/chef/client.rb +1 -1
  9. data/lib/chef/cookbook_manifest.rb +1 -1
  10. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  11. data/lib/chef/cookbook_version.rb +2 -5
  12. data/lib/chef/environment.rb +1 -1
  13. data/lib/chef/exceptions.rb +1 -1
  14. data/lib/chef/file_access_control/windows.rb +1 -4
  15. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  16. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +4 -4
  17. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +28 -39
  18. data/lib/chef/http.rb +2 -12
  19. data/lib/chef/http/basic_client.rb +1 -1
  20. data/lib/chef/http/http_request.rb +1 -1
  21. data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
  22. data/lib/chef/json_compat.rb +2 -7
  23. data/lib/chef/key.rb +1 -1
  24. data/lib/chef/knife/bootstrap.rb +2 -1
  25. data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +2 -2
  26. data/lib/chef/knife/config_show.rb +1 -1
  27. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  28. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  29. data/lib/chef/knife/core/windows_bootstrap_context.rb +7 -4
  30. data/lib/chef/mixin/convert_to_class_name.rb +0 -56
  31. data/lib/chef/mixin/openssl_helper.rb +1 -1
  32. data/lib/chef/mixin/properties.rb +2 -0
  33. data/lib/chef/mixin/unformatter.rb +1 -1
  34. data/lib/chef/node/attribute_collections.rb +2 -6
  35. data/lib/chef/powershell.rb +5 -2
  36. data/lib/chef/property.rb +1 -1
  37. data/lib/chef/provider/cron.rb +2 -13
  38. data/lib/chef/provider/group.rb +14 -6
  39. data/lib/chef/provider/group/windows.rb +12 -1
  40. data/lib/chef/provider/ifconfig.rb +7 -7
  41. data/lib/chef/provider/ifconfig/debian.rb +5 -7
  42. data/lib/chef/provider/ifconfig/redhat.rb +3 -1
  43. data/lib/chef/provider/launchd.rb +1 -11
  44. data/lib/chef/provider/mount.rb +18 -1
  45. data/lib/chef/provider/mount/linux.rb +4 -0
  46. data/lib/chef/provider/mount/mount.rb +41 -43
  47. data/lib/chef/provider/package.rb +3 -0
  48. data/lib/chef/provider/package/apt.rb +1 -1
  49. data/lib/chef/provider/package/chocolatey.rb +6 -6
  50. data/lib/chef/provider/package/freebsd/base.rb +3 -2
  51. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
  52. data/lib/chef/provider/package/ips.rb +1 -1
  53. data/lib/chef/provider/package/powershell.rb +2 -3
  54. data/lib/chef/provider/package/rubygems.rb +1 -1
  55. data/lib/chef/provider/package/snap.rb +1 -3
  56. data/lib/chef/provider/package/solaris.rb +0 -2
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +1 -1
  58. data/lib/chef/provider/package/zypper.rb +98 -71
  59. data/lib/chef/provider/registry_key.rb +4 -3
  60. data/lib/chef/provider/route.rb +2 -2
  61. data/lib/chef/provider/service/debian.rb +2 -1
  62. data/lib/chef/provider/user.rb +17 -9
  63. data/lib/chef/provider/user/aix.rb +1 -1
  64. data/lib/chef/provider/user/mac.rb +12 -4
  65. data/lib/chef/provider/user/solaris.rb +1 -1
  66. data/lib/chef/provider/user/windows.rb +10 -3
  67. data/lib/chef/providers.rb +0 -3
  68. data/lib/chef/pwsh.rb +7 -0
  69. data/lib/chef/resource/bash.rb +119 -1
  70. data/lib/chef/resource/batch.rb +1 -1
  71. data/lib/chef/resource/breakpoint.rb +3 -1
  72. data/lib/chef/resource/build_essential.rb +5 -8
  73. data/lib/chef/resource/csh.rb +2 -2
  74. data/lib/chef/resource/execute.rb +6 -4
  75. data/lib/chef/resource/file.rb +1 -1
  76. data/lib/chef/resource/homebrew_update.rb +4 -1
  77. data/lib/chef/resource/hostname.rb +2 -2
  78. data/lib/chef/resource/ifconfig.rb +52 -5
  79. data/lib/chef/resource/ksh.rb +3 -3
  80. data/lib/chef/resource/lwrp_base.rb +3 -5
  81. data/lib/chef/resource/mount.rb +7 -1
  82. data/lib/chef/resource/perl.rb +2 -2
  83. data/lib/chef/resource/plist.rb +2 -6
  84. data/lib/chef/resource/powershell_package_source.rb +19 -18
  85. data/lib/chef/resource/powershell_script.rb +7 -10
  86. data/lib/chef/resource/python.rb +2 -2
  87. data/lib/chef/resource/registry_key.rb +93 -2
  88. data/lib/chef/resource/route.rb +1 -1
  89. data/lib/chef/resource/ruby.rb +2 -2
  90. data/lib/chef/resource/scm/_scm.rb +2 -1
  91. data/lib/chef/resource/scm/git.rb +82 -1
  92. data/lib/chef/resource/scm/subversion.rb +12 -0
  93. data/lib/chef/resource/script.rb +2 -2
  94. data/lib/chef/resource/solaris_package.rb +0 -2
  95. data/lib/chef/resource/sudo.rb +1 -1
  96. data/lib/chef/resource/support/client.erb +4 -5
  97. data/lib/chef/resource/systemd_unit.rb +42 -1
  98. data/lib/chef/resource/windows_ad_join.rb +9 -9
  99. data/lib/chef/resource/windows_certificate.rb +6 -6
  100. data/lib/chef/resource/windows_dfs_server.rb +7 -4
  101. data/lib/chef/resource/windows_env.rb +173 -0
  102. data/lib/chef/resource/windows_feature.rb +2 -0
  103. data/lib/chef/resource/windows_firewall_profile.rb +7 -12
  104. data/lib/chef/resource/windows_firewall_rule.rb +9 -11
  105. data/lib/chef/resource/windows_font.rb +1 -1
  106. data/lib/chef/resource/windows_package.rb +1 -0
  107. data/lib/chef/resource/windows_path.rb +38 -0
  108. data/lib/chef/resource/windows_security_policy.rb +5 -5
  109. data/lib/chef/resource/windows_service.rb +108 -0
  110. data/lib/chef/resource/windows_share.rb +18 -18
  111. data/lib/chef/resource/windows_task.rb +629 -28
  112. data/lib/chef/resource/windows_workgroup.rb +6 -4
  113. data/lib/chef/resource/yum_repository.rb +1 -1
  114. data/lib/chef/resource_collection/resource_set.rb +1 -5
  115. data/lib/chef/resource_inspector.rb +77 -75
  116. data/lib/chef/run_lock.rb +1 -1
  117. data/lib/chef/server_api.rb +0 -4
  118. data/lib/chef/shell/ext.rb +1 -1
  119. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -3
  120. data/lib/chef/util/dsc/local_configuration_manager.rb +1 -1
  121. data/lib/chef/util/powershell/cmdlet.rb +3 -9
  122. data/lib/chef/version.rb +1 -1
  123. data/lib/chef/win32/security/sid.rb +1 -1
  124. data/spec/functional/mixin/powershell_out_spec.rb +4 -4
  125. data/spec/functional/resource/apt_package_spec.rb +4 -6
  126. data/spec/functional/resource/chocolatey_package_spec.rb +3 -3
  127. data/spec/functional/resource/cron_spec.rb +3 -3
  128. data/spec/functional/resource/dsc_script_spec.rb +3 -3
  129. data/spec/functional/resource/mount_spec.rb +10 -2
  130. data/spec/functional/resource/powershell_package_source_spec.rb +107 -0
  131. data/spec/functional/resource/windows_certificate_spec.rb +10 -6
  132. data/spec/functional/resource/windows_firewall_rule_spec.rb +93 -0
  133. data/spec/functional/resource/windows_package_spec.rb +36 -10
  134. data/spec/functional/resource/windows_share_spec.rb +103 -0
  135. data/spec/functional/resource/windows_task_spec.rb +2 -3
  136. data/spec/functional/resource/zypper_package_spec.rb +11 -0
  137. data/spec/integration/knife/client_key_create_spec.rb +1 -1
  138. data/spec/integration/knife/node_create_spec.rb +1 -1
  139. data/spec/integration/knife/node_environment_set_spec.rb +1 -1
  140. data/spec/integration/knife/node_run_list_add_spec.rb +4 -4
  141. data/spec/integration/knife/node_run_list_remove_spec.rb +1 -1
  142. data/spec/integration/knife/node_run_list_set_spec.rb +1 -1
  143. data/spec/integration/knife/node_show_spec.rb +1 -1
  144. data/spec/integration/recipes/notifies_spec.rb +1 -1
  145. data/spec/integration/recipes/provider_choice.rb +2 -2
  146. data/spec/support/lib/chef/resource/cat.rb +1 -1
  147. data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -1
  148. data/spec/support/mock/platform.rb +24 -16
  149. data/spec/support/platform_helpers.rb +6 -4
  150. data/spec/support/shared/unit/knife_shared.rb +1 -1
  151. data/spec/support/shared/unit/script_resource.rb +4 -4
  152. data/spec/support/shared/unit/windows_script_resource.rb +1 -1
  153. data/spec/unit/client_spec.rb +16 -0
  154. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +11 -11
  155. data/spec/unit/knife/client_create_spec.rb +2 -2
  156. data/spec/unit/knife/configure_client_spec.rb +5 -5
  157. data/spec/unit/knife/configure_spec.rb +3 -3
  158. data/spec/unit/knife/cookbook_delete_spec.rb +2 -2
  159. data/spec/unit/knife/cookbook_download_spec.rb +2 -2
  160. data/spec/unit/knife/cookbook_list_spec.rb +2 -2
  161. data/spec/unit/knife/cookbook_metadata_spec.rb +3 -3
  162. data/spec/unit/knife/environment_compare_spec.rb +3 -3
  163. data/spec/unit/knife/supermarket_download_spec.rb +8 -8
  164. data/spec/unit/knife/supermarket_list_spec.rb +3 -3
  165. data/spec/unit/knife/supermarket_search_spec.rb +1 -1
  166. data/spec/unit/knife/tag_create_spec.rb +1 -1
  167. data/spec/unit/knife/tag_delete_spec.rb +1 -1
  168. data/spec/unit/knife/user_create_spec.rb +1 -1
  169. data/spec/unit/mixin/which.rb +1 -1
  170. data/spec/unit/provider/group/windows_spec.rb +6 -0
  171. data/spec/unit/provider/group_spec.rb +1 -1
  172. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  173. data/spec/unit/provider/mount/mount_spec.rb +21 -10
  174. data/spec/unit/provider/mount/solaris_spec.rb +1 -1
  175. data/spec/unit/provider/mount_spec.rb +31 -0
  176. data/spec/unit/provider/package/chocolatey_spec.rb +1 -2
  177. data/spec/unit/provider/package/powershell_spec.rb +87 -95
  178. data/spec/unit/provider/package/zypper_spec.rb +0 -25
  179. data/spec/unit/provider/package_spec.rb +2 -2
  180. data/spec/unit/provider/subversion_spec.rb +0 -3
  181. data/spec/unit/provider/user_spec.rb +7 -1
  182. data/spec/unit/provider/windows_env_spec.rb +18 -34
  183. data/spec/unit/provider/windows_path_spec.rb +6 -11
  184. data/spec/unit/provider/windows_task_spec.rb +7 -6
  185. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  186. data/spec/unit/resource/build_essential_spec.rb +0 -12
  187. data/spec/unit/resource/ifconfig_spec.rb +2 -10
  188. data/spec/unit/resource/mount_spec.rb +18 -5
  189. data/spec/unit/resource/powershell_package_source_spec.rb +20 -20
  190. data/spec/unit/resource/powershell_script_spec.rb +4 -74
  191. data/spec/unit/resource/service_spec.rb +2 -2
  192. data/spec/unit/resource/solaris_package_spec.rb +8 -10
  193. data/spec/unit/resource_inspector_spec.rb +3 -3
  194. data/spec/unit/shell_spec.rb +2 -2
  195. data/tasks/rspec.rb +1 -1
  196. metadata +9 -15
  197. data/lib/chef/monkey_patches/net_http.rb +0 -22
  198. data/lib/chef/provider/windows_env.rb +0 -210
  199. data/lib/chef/provider/windows_path.rb +0 -61
  200. data/lib/chef/provider/windows_task.rb +0 -631
  201. data/spec/support/mock/constant.rb +0 -52
  202. data/spec/unit/monkey_patches/uri_spec.rb +0 -34
  203. data/spec/unit/provider_resolver_spec.rb +0 -885
  204. data/spec/unit/resource/data/InstallHistory_with_CLT.plist +0 -92
  205. data/spec/unit/resource/data/InstallHistory_without_CLT.plist +0 -38
@@ -129,8 +129,9 @@ describe Chef::Resource::Mount, :requires_root, external: include_flag do
129
129
  end
130
130
 
131
131
  # Actual tests begin here.
132
- before(:all) do
132
+ before do |test|
133
133
  @device, @fstype = setup_device_for_mount
134
+ @device = "/" if test.metadata[:skip_before]
134
135
 
135
136
  @mount_point = Dir.mktmpdir("testmount")
136
137
 
@@ -145,13 +146,20 @@ describe Chef::Resource::Mount, :requires_root, external: include_flag do
145
146
  end
146
147
 
147
148
  after(:all) do
148
- Dir.rmdir(@mount_point)
149
+ Dir.rmdir(@mount_point) if @mount_point
149
150
  end
150
151
 
151
152
  after(:each) do
152
153
  cleanup_mount(new_resource.mount_point)
153
154
  end
154
155
 
156
+ describe "when device is '/'" do
157
+ it "should mount the filesystem if device is '/'", :skip_before do
158
+ new_resource.run_action(:mount)
159
+ mount_should_exist(new_resource.mount_point, new_resource.device)
160
+ end
161
+ end
162
+
155
163
  describe "when the target state is a mounted filesystem" do
156
164
  it "should mount the filesystem if it isn't mounted" do
157
165
  expect(current_resource.enabled).to be_falsey
@@ -0,0 +1,107 @@
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) 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
+ require "spec_helper"
19
+ require "chef/mixin/powershell_exec"
20
+
21
+ describe Chef::Resource::PowershellPackageSource, :windows_gte_10 do
22
+ include Chef::Mixin::PowershellExec
23
+
24
+ let(:source_name) { "fake" }
25
+ let(:url) { "https://www.nuget.org/api/v2" }
26
+ let(:trusted) { true }
27
+
28
+ let(:run_context) do
29
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
30
+ end
31
+
32
+ subject do
33
+ new_resource = Chef::Resource::PowershellPackageSource.new("test powershell package source", run_context)
34
+ new_resource.source_name source_name
35
+ new_resource.url url
36
+ new_resource.trusted trusted
37
+ new_resource.provider_name provider_name
38
+ new_resource
39
+ end
40
+
41
+ let(:provider) do
42
+ provider = subject.provider_for_action(subject.action)
43
+ provider
44
+ end
45
+
46
+ shared_examples "package_source" do
47
+ context "register a package source" do
48
+ after { remove_package_source }
49
+
50
+ it "registers the package source" do
51
+ subject.run_action(:register)
52
+ expect(get_installed_package_source_name).to eq(source_name)
53
+ end
54
+
55
+ it "does not register the package source if already installed" do
56
+ subject.run_action(:register)
57
+ subject.run_action(:register)
58
+ expect(subject).not_to be_updated_by_last_action
59
+ end
60
+
61
+ it "updates an existing package source if changed" do
62
+ subject.run_action(:register)
63
+ subject.trusted !trusted
64
+ subject.run_action(:register)
65
+ expect(subject).to be_updated_by_last_action
66
+ end
67
+ end
68
+
69
+ context "unregister a package source" do
70
+ it "unregisters the package source" do
71
+ subject.run_action(:register)
72
+ subject.run_action(:unregister)
73
+ expect(get_installed_package_source_name).to be_empty
74
+ end
75
+
76
+ it "does not unregister the package source if not already installed" do
77
+ subject.run_action(:unregister)
78
+ expect(subject).not_to be_updated_by_last_action
79
+ end
80
+ end
81
+ end
82
+
83
+ context "with NuGet provider" do
84
+ let(:provider_name) { "NuGet" }
85
+
86
+ before(:all) do
87
+ powershell_exec!("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;Install-PackageProvider -Name NuGet -Force")
88
+ end
89
+
90
+ it_behaves_like "package_source"
91
+ end
92
+
93
+ context "with PowerShellGet provider" do
94
+ let(:provider_name) { "PowerShellGet" }
95
+
96
+ it_behaves_like "package_source"
97
+ end
98
+
99
+ def get_installed_package_source_name
100
+ powershell_exec!("(Get-PackageSource -Name #{source_name} -ErrorAction SilentlyContinue).Name").result
101
+ end
102
+
103
+ def remove_package_source
104
+ pkg_to_remove = Chef::Resource::PowershellPackageSource.new(source_name, run_context)
105
+ pkg_to_remove.run_action(:unregister)
106
+ end
107
+ end
@@ -16,18 +16,18 @@
16
16
  #
17
17
 
18
18
  require "spec_helper"
19
- require "chef/mixin/powershell_out"
19
+ require "chef/mixin/powershell_exec"
20
20
  require "chef/resource/windows_certificate"
21
21
 
22
22
  module WindowsCertificateHelper
23
- include Chef::Mixin::PowershellOut
23
+ include Chef::Mixin::PowershellExec
24
24
 
25
25
  def create_store(store)
26
26
  path = "Cert:\\LocalMachine\\" + store
27
27
  command = <<~EOC
28
28
  New-Item -Path #{path}
29
29
  EOC
30
- powershell_out(command)
30
+ powershell_exec(command)
31
31
  end
32
32
 
33
33
  def cleanup(store)
@@ -35,15 +35,19 @@ module WindowsCertificateHelper
35
35
  command = <<~EOC
36
36
  Remove-Item -Path #{path} -Recurse
37
37
  EOC
38
- powershell_out(command)
38
+ powershell_exec(command)
39
39
  end
40
40
 
41
41
  def no_of_certificates
42
42
  path = "Cert:\\LocalMachine\\" + store
43
+ # Seems weird that we have to call dir twice right?
44
+ # The powershell pki module cache the last dir in module session state
45
+ # Issuing dir with a different arg (-Force) seems to refresh that state.
43
46
  command = <<~EOC
44
- Write-Host (dir #{path} | measure).Count;
47
+ dir #{path} -Force | Out-Null
48
+ (dir #{path} | measure).Count
45
49
  EOC
46
- powershell_out(command).stdout.to_i
50
+ powershell_exec(command).result.to_i
47
51
  end
48
52
  end
49
53
 
@@ -0,0 +1,93 @@
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) 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
+ require "spec_helper"
19
+ require "chef/mixin/powershell_exec"
20
+
21
+ describe Chef::Resource::WindowsFirewallRule, :windows_only do
22
+ include Chef::Mixin::PowershellExec
23
+
24
+ let(:rule_name) { "fake_rule" }
25
+ let(:remote_port) { "5555" }
26
+ let(:enabled) { false }
27
+
28
+ let(:run_context) do
29
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
30
+ end
31
+
32
+ subject do
33
+ new_resource = Chef::Resource::WindowsFirewallRule.new("test firewall rule", run_context)
34
+ new_resource.rule_name rule_name
35
+ new_resource.remote_port remote_port
36
+ new_resource.enabled enabled
37
+ new_resource
38
+ end
39
+
40
+ let(:provider) do
41
+ provider = subject.provider_for_action(subject.action)
42
+ provider
43
+ end
44
+
45
+ context "create a new rule" do
46
+ after { delete_rule }
47
+
48
+ it "creates the rule" do
49
+ subject.run_action(:create)
50
+ expect(get_installed_rule_name).to eq(rule_name)
51
+ expect(get_installed_rule_remote_port).to eq(remote_port)
52
+ end
53
+
54
+ it "does not create rule if it already exists" do
55
+ subject.run_action(:create)
56
+ subject.run_action(:create)
57
+ expect(subject).not_to be_updated_by_last_action
58
+ end
59
+
60
+ it "updates the rule if it changed" do
61
+ subject.run_action(:create)
62
+ subject.remote_port = "7777"
63
+ subject.run_action(:create)
64
+ expect(get_installed_rule_remote_port).to eq("7777")
65
+ end
66
+ end
67
+
68
+ context "delete a rule" do
69
+ it "deletes an existing rule" do
70
+ subject.run_action(:create)
71
+ subject.run_action(:delete)
72
+ expect(get_installed_rule_name).to be_empty
73
+ end
74
+
75
+ it "does not delete rule if it does not exist" do
76
+ subject.run_action(:delete)
77
+ expect(subject).not_to be_updated_by_last_action
78
+ end
79
+ end
80
+
81
+ def get_installed_rule_name
82
+ powershell_exec!("(Get-NetFirewallRule -Name #{rule_name} -ErrorAction SilentlyContinue).Name").result
83
+ end
84
+
85
+ def get_installed_rule_remote_port
86
+ powershell_exec!("((Get-NetFirewallRule -Name #{rule_name} -ErrorAction SilentlyContinue) | Get-NetFirewallPortFilter).RemotePort").result
87
+ end
88
+
89
+ def delete_rule
90
+ rule_to_remove = Chef::Resource::WindowsFirewallRule.new(rule_name, run_context)
91
+ rule_to_remove.run_action(:delete)
92
+ end
93
+ end
@@ -25,6 +25,10 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
25
25
  let(:pkg_version) { nil }
26
26
  let(:pkg_type) { nil }
27
27
  let(:pkg_options) { nil }
28
+ let(:remote_file_attributes) { nil }
29
+ let(:run_context) do
30
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
31
+ end
28
32
 
29
33
  subject do
30
34
  new_resource = Chef::Resource::WindowsPackage.new(pkg_name, run_context)
@@ -33,13 +37,14 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
33
37
  new_resource.installer_type pkg_type
34
38
  new_resource.options pkg_options
35
39
  new_resource.checksum pkg_checksum
40
+ new_resource.remote_file_attributes
36
41
  new_resource
37
42
  end
38
43
 
39
44
  describe "install package" do
40
45
  let(:pkg_name) { "Microsoft Visual C++ 2005 Redistributable" }
41
- let(:pkg_checksum) { "d6832398e3bc9156a660745f427dc1c2392ce4e9a872e04f41f62d0c6bae07a8" }
42
- let(:pkg_path) { "https://download.microsoft.com/download/6/B/B/6BB661D6-A8AE-4819-B79F-236472F6070C/vcredist_x86.exe" }
46
+ let(:pkg_checksum) { "4ee4da0fe62d5fa1b5e80c6e6d88a4a2f8b3b140c35da51053d0d7b72a381d29" }
47
+ let(:pkg_path) { "https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE" }
43
48
  let(:pkg_checksum) { nil }
44
49
  let(:pkg_type) { :custom }
45
50
  let(:pkg_options) { "/Q" }
@@ -55,9 +60,9 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
55
60
  end
56
61
 
57
62
  context "installing additional version" do
58
- let(:pkg_path) { "https://download.microsoft.com/download/e/1/c/e1c773de-73ba-494a-a5ba-f24906ecf088/vcredist_x86.exe" }
59
- let(:pkg_checksum) { "eb00f891919d4f894ab725b158459db8834470c382dc60cd3c3ee2c6de6da92c" }
60
- let(:pkg_version) { "8.0.56336" }
63
+ let(:pkg_path) { "https://download.microsoft.com/download/6/B/B/6BB661D6-A8AE-4819-B79F-236472F6070C/vcredist_x86.exe" }
64
+ let(:pkg_checksum) { "d6832398e3bc9156a660745f427dc1c2392ce4e9a872e04f41f62d0c6bae07a8" }
65
+ let(:pkg_version) { "8.0.59193" }
61
66
 
62
67
  it "installs older version" do
63
68
  subject.run_action(:install)
@@ -69,14 +74,14 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
69
74
  subject { Chef::Resource::WindowsPackage.new(pkg_name, run_context) }
70
75
 
71
76
  context "multiple versions and a version given to remove" do
72
- before { subject.version("8.0.56336") }
77
+ before { subject.version("8.0.59193") }
73
78
 
74
79
  it "removes specified version" do
75
80
  subject.run_action(:remove)
76
81
  expect(subject).to be_updated_by_last_action
77
82
  prov = subject.provider_for_action(:remove)
78
83
  prov.load_current_resource
79
- expect(prov.current_version_array).to eq([["8.0.59193"]])
84
+ expect(prov.current_version_array).to eq([["8.0.61001"]])
80
85
  end
81
86
  end
82
87
 
@@ -101,8 +106,8 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
101
106
  install1.run_action(:install)
102
107
 
103
108
  install2 = Chef::Resource::WindowsPackage.new(pkg_name, run_context)
104
- install2.source "https://download.microsoft.com/download/e/1/c/e1c773de-73ba-494a-a5ba-f24906ecf088/vcredist_x86.exe"
105
- install2.version "8.0.56336"
109
+ install2.source "https://download.microsoft.com/download/6/B/B/6BB661D6-A8AE-4819-B79F-236472F6070C/vcredist_x86.exe"
110
+ install2.version "8.0.59193"
106
111
  install2.installer_type pkg_type
107
112
  install2.options pkg_options
108
113
  install2.run_action(:install)
@@ -135,7 +140,7 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
135
140
 
136
141
  context "inno" do
137
142
  let(:pkg_name) { "Mercurial 3.6.1 (64-bit)" }
138
- let(:pkg_path) { "http://mercurial.selenic.com/release/windows/Mercurial-3.6.1-x64.exe" }
143
+ let(:pkg_path) { "https://www.mercurial-scm.org/release/windows/Mercurial-3.6.1-x64.exe" }
139
144
  let(:pkg_checksum) { "febd29578cb6736163d232708b834a2ddd119aa40abc536b2c313fc5e1b5831d" }
140
145
 
141
146
  it "finds the correct installer type" do
@@ -164,4 +169,25 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
164
169
  expect(subject).to be_updated_by_last_action
165
170
  end
166
171
  end
172
+
173
+ describe "install package with remote_file_attributes" do
174
+ let(:pkg_name) { "7zip" }
175
+ let(:pkg_path) { "http://www.7-zip.org/a/7z938-x64.msi" }
176
+ let(:remote_file_attributes) {
177
+ {
178
+ path: ::File.join(Chef::Config[:file_cache_path], "7zip.msi"),
179
+ checksum: "7c8e873991c82ad9cfcdbdf45254ea6101e9a645e12977dcd518979e50fdedf3",
180
+ }
181
+ }
182
+
183
+ it "installs the package" do
184
+ subject.run_action(:install)
185
+ expect(subject).to be_updated_by_last_action
186
+ end
187
+
188
+ it "uninstalls the package" do
189
+ subject.run_action(:remove)
190
+ expect(subject).to be_updated_by_last_action
191
+ end
192
+ end
167
193
  end
@@ -0,0 +1,103 @@
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) 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
+ require "spec_helper"
19
+ require "chef/mixin/powershell_exec"
20
+
21
+ describe Chef::Resource::WindowsShare, :windows_only do
22
+ include Chef::Mixin::PowershellExec
23
+
24
+ let(:share_name) { "fake_share" }
25
+ let(:path) { ENV["temp"] }
26
+ let(:concurrent_user_limit) { 7 }
27
+ let(:full_users) { ["#{ENV["USERNAME"]}"] }
28
+
29
+ let(:run_context) do
30
+ node = Chef::Node.new
31
+ node.default["hostname"] = ENV["COMPUTERNAME"]
32
+ Chef::RunContext.new(node, {}, Chef::EventDispatch::Dispatcher.new)
33
+ end
34
+
35
+ subject do
36
+ new_resource = Chef::Resource::WindowsShare.new("test windows share", run_context)
37
+ new_resource.share_name share_name
38
+ new_resource.path path
39
+ new_resource.concurrent_user_limit concurrent_user_limit
40
+ new_resource.full_users full_users
41
+ new_resource
42
+ end
43
+
44
+ let(:provider) do
45
+ provider = subject.provider_for_action(subject.action)
46
+ provider
47
+ end
48
+
49
+ context "create a new share" do
50
+ after { delete_share }
51
+
52
+ it "creates the share" do
53
+ subject.run_action(:create)
54
+ share = get_installed_share
55
+ expect(share["Name"]).to eq(share_name)
56
+ expect(share["Path"]).to eq(path)
57
+ expect(get_installed_share_access["AccountName"]).to eq("#{ENV["COMPUTERNAME"]}\\#{full_users[0]}")
58
+ end
59
+
60
+ it "does not create share if it already exists" do
61
+ subject.run_action(:create)
62
+ subject.run_action(:create)
63
+ expect(subject).not_to be_updated_by_last_action
64
+ end
65
+
66
+ it "updates the share if it changed" do
67
+ subject.run_action(:create)
68
+ subject.concurrent_user_limit 8
69
+ subject.full_users ["BUILTIN\\Administrators"]
70
+ subject.run_action(:create)
71
+ share = get_installed_share
72
+ expect(share["ConcurrentUserLimit"]).to eq(8)
73
+ expect(get_installed_share_access["AccountName"]).to eq("BUILTIN\\Administrators")
74
+ end
75
+
76
+ end
77
+
78
+ context "delete a share" do
79
+ it "deletes an existing share" do
80
+ subject.run_action(:create)
81
+ subject.run_action(:delete)
82
+ expect(get_installed_share).to be_empty
83
+ end
84
+
85
+ it "does not delete share if it does not exist" do
86
+ subject.run_action(:delete)
87
+ expect(subject).not_to be_updated_by_last_action
88
+ end
89
+ end
90
+
91
+ def get_installed_share
92
+ powershell_exec!("Get-SmbShare -Name #{share_name} -ErrorAction SilentlyContinue").result
93
+ end
94
+
95
+ def get_installed_share_access
96
+ powershell_exec!("Get-SmbShareAccess -Name #{share_name} -ErrorAction SilentlyContinue").result
97
+ end
98
+
99
+ def delete_share
100
+ rule_to_remove = Chef::Resource::WindowsShare.new(share_name, run_context)
101
+ rule_to_remove.run_action(:delete)
102
+ end
103
+ end