chef 17.6.15 → 17.8.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -0
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/application/base.rb +1 -1
  5. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  6. data/lib/chef/chef_fs/path_utils.rb +1 -1
  7. data/lib/chef/compliance/default_attributes.rb +12 -2
  8. data/lib/chef/compliance/runner.rb +51 -5
  9. data/lib/chef/data_collector/run_end_message.rb +1 -1
  10. data/lib/chef/dsl/reboot_pending.rb +1 -1
  11. data/lib/chef/exceptions.rb +10 -0
  12. data/lib/chef/mixin/powershell_exec.rb +6 -5
  13. data/lib/chef/mixin/why_run.rb +8 -2
  14. data/lib/chef/powershell.rb +8 -6
  15. data/lib/chef/provider/cron.rb +4 -1
  16. data/lib/chef/provider/git.rb +1 -1
  17. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  18. data/lib/chef/provider/mount/linux.rb +16 -2
  19. data/lib/chef/provider/mount/mount.rb +1 -1
  20. data/lib/chef/provider/package/dnf.rb +1 -1
  21. data/lib/chef/provider/package/habitat.rb +1 -1
  22. data/lib/chef/provider/package/powershell.rb +13 -10
  23. data/lib/chef/provider/package/zypper.rb +2 -0
  24. data/lib/chef/provider/package.rb +58 -23
  25. data/lib/chef/provider/subversion.rb +5 -5
  26. data/lib/chef/provider.rb +1 -1
  27. data/lib/chef/pwsh.rb +3 -2
  28. data/lib/chef/resource/chef_client_config.rb +22 -1
  29. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  30. data/lib/chef/resource/chef_client_trusted_certificate.rb +1 -0
  31. data/lib/chef/resource/chocolatey_config.rb +1 -1
  32. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  33. data/lib/chef/resource/chocolatey_source.rb +24 -2
  34. data/lib/chef/resource/directory.rb +1 -1
  35. data/lib/chef/resource/dnf_package.rb +4 -6
  36. data/lib/chef/resource/dpkg_package.rb +5 -0
  37. data/lib/chef/resource/execute.rb +1 -4
  38. data/lib/chef/resource/habitat_install.rb +5 -5
  39. data/lib/chef/resource/inspec_waiver.rb +1 -1
  40. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  41. data/lib/chef/resource/kernel_module.rb +27 -2
  42. data/lib/chef/resource/launchd.rb +0 -3
  43. data/lib/chef/resource/macos_userdefaults.rb +41 -131
  44. data/lib/chef/resource/rhsm_register.rb +31 -0
  45. data/lib/chef/resource/support/client.erb +7 -0
  46. data/lib/chef/resource/windows_auto_run.rb +1 -1
  47. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  48. data/lib/chef/resource/windows_feature_powershell.rb +7 -7
  49. data/lib/chef/resource/windows_update_settings.rb +3 -3
  50. data/lib/chef/resource.rb +2 -2
  51. data/lib/chef/resource_reporter.rb +1 -1
  52. data/lib/chef/secret_fetcher/azure_key_vault.rb +62 -8
  53. data/lib/chef/secret_fetcher.rb +0 -1
  54. data/lib/chef/version.rb +1 -1
  55. data/spec/functional/dsl/reboot_pending_spec.rb +3 -3
  56. data/spec/functional/dsl/registry_helper_spec.rb +1 -1
  57. data/spec/functional/resource/dnf_package_spec.rb +34 -20
  58. data/spec/functional/resource/dpkg_package_spec.rb +16 -0
  59. data/spec/functional/resource/dsc_script_spec.rb +2 -2
  60. data/spec/functional/resource/macos_userdefaults_spec.rb +139 -0
  61. data/spec/functional/resource/registry_spec.rb +81 -81
  62. data/spec/functional/resource/zypper_package_spec.rb +7 -0
  63. data/spec/functional/win32/registry_spec.rb +8 -8
  64. data/spec/integration/client/client_spec.rb +31 -0
  65. data/spec/unit/application/base_spec.rb +40 -0
  66. data/spec/unit/compliance/runner_spec.rb +62 -1
  67. data/spec/unit/data_collector_spec.rb +24 -1
  68. data/spec/unit/dsl/reboot_pending_spec.rb +1 -1
  69. data/spec/unit/file_access_control_spec.rb +1 -1
  70. data/spec/unit/mixin/default_paths_spec.rb +1 -1
  71. data/spec/unit/mixin/securable_spec.rb +3 -3
  72. data/spec/unit/mixin/why_run_spec.rb +53 -0
  73. data/spec/unit/provider/cron_spec.rb +45 -0
  74. data/spec/unit/provider/group/groupadd_spec.rb +1 -0
  75. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  76. data/spec/unit/provider/ifconfig_spec.rb +2 -0
  77. data/spec/unit/provider/mount/linux_spec.rb +16 -3
  78. data/spec/unit/provider/package/bff_spec.rb +1 -0
  79. data/spec/unit/provider/package/powershell_spec.rb +114 -114
  80. data/spec/unit/provider/package/rubygems_spec.rb +8 -5
  81. data/spec/unit/provider/package/solaris_spec.rb +1 -0
  82. data/spec/unit/provider/package/windows_spec.rb +1 -1
  83. data/spec/unit/provider/registry_key_spec.rb +4 -4
  84. data/spec/unit/provider/service/arch_service_spec.rb +2 -2
  85. data/spec/unit/provider/service/debian_service_spec.rb +1 -0
  86. data/spec/unit/provider/service/gentoo_service_spec.rb +1 -0
  87. data/spec/unit/provider/service/macosx_spec.rb +1 -0
  88. data/spec/unit/provider/service/redhat_spec.rb +4 -1
  89. data/spec/unit/provider/service/simple_service_spec.rb +6 -4
  90. data/spec/unit/provider/service/windows_spec.rb +5 -5
  91. data/spec/unit/provider/subversion_spec.rb +4 -4
  92. data/spec/unit/provider/user_spec.rb +2 -0
  93. data/spec/unit/provider/windows_env_spec.rb +1 -1
  94. data/spec/unit/provider/zypper_repository_spec.rb +1 -1
  95. data/spec/unit/resource/chef_client_trusted_certificate_spec.rb +14 -0
  96. data/spec/unit/resource/chocolatey_config_spec.rb +1 -1
  97. data/spec/unit/resource/chocolatey_feature_spec.rb +1 -1
  98. data/spec/unit/resource/chocolatey_source_spec.rb +1 -1
  99. data/spec/unit/resource/dpkg_package_spec.rb +12 -0
  100. data/spec/unit/resource/kernel_module_spec.rb +2 -1
  101. data/spec/unit/resource/macos_user_defaults_spec.rb +36 -96
  102. data/spec/unit/resource/registry_key_spec.rb +10 -10
  103. data/spec/unit/resource/rhsm_register_spec.rb +42 -0
  104. data/spec/unit/resource/windows_auto_run_spec.rb +1 -1
  105. data/spec/unit/resource/windows_feature_powershell_spec.rb +1 -1
  106. data/spec/unit/resource/windows_firewall_rule_spec.rb +2 -2
  107. data/spec/unit/resource/windows_task_spec.rb +3 -3
  108. data/spec/unit/resource_reporter_spec.rb +2 -2
  109. data/spec/unit/resource_spec.rb +5 -0
  110. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +99 -20
  111. data/spec/unit/util/backup_spec.rb +1 -1
  112. data/spec/unit/win32/registry_spec.rb +3 -3
  113. metadata +24 -7
@@ -95,15 +95,15 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
95
95
 
96
96
  it "should raise error if the node has a nil ps property and no other means to get status" do
97
97
  @node.automatic_attrs[:command] = { ps: nil }
98
- @provider.define_resource_requirements
99
98
  @provider.action = :start
99
+ @provider.define_resource_requirements
100
100
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
101
101
  end
102
102
 
103
103
  it "should raise error if the node has an empty ps property and no other means to get status" do
104
104
  @node.automatic_attrs[:command] = { ps: "" }
105
- @provider.define_resource_requirements
106
105
  @provider.action = :start
106
+ @provider.define_resource_requirements
107
107
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
108
108
  end
109
109
 
@@ -50,6 +50,7 @@ describe Chef::Provider::Service::Debian do
50
50
  it "ensures /usr/sbin/update-rc.d is available" do
51
51
  expect(File).to receive(:exist?).with("/usr/sbin/update-rc.d").and_return(false)
52
52
 
53
+ @provider.action = :start
53
54
  @provider.define_resource_requirements
54
55
  expect do
55
56
  @provider.process_resource_requirements
@@ -42,6 +42,7 @@ describe Chef::Provider::Service::Gentoo do
42
42
  describe "load_current_resource" do
43
43
  it "should raise Chef::Exceptions::Service if /sbin/rc-update does not exist" do
44
44
  expect(File).to receive(:exist?).with("/sbin/rc-update").and_return(false)
45
+ @provider.action = :start
45
46
  @provider.define_resource_requirements
46
47
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
47
48
  end
@@ -237,6 +237,7 @@ describe Chef::Provider::Service::Macosx do
237
237
  allow(Dir).to receive(:glob).and_return([(plist).to_s,
238
238
  "/Users/wtf/something.plist"])
239
239
  provider.load_current_resource
240
+ provider.action = :enable
240
241
  provider.define_resource_requirements
241
242
  expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
242
243
  end
@@ -34,6 +34,7 @@ shared_examples_for "define_resource_requirements_common" do
34
34
  expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
35
35
  chkconfig = double("Chkconfig", exitstatus: 0, stdout: "", stderr: "service chef supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add chef')")
36
36
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", returns: [0, 1]).and_return(chkconfig)
37
+ @provider.action = :start
37
38
  @provider.load_current_resource
38
39
  @provider.define_resource_requirements
39
40
  expect { @provider.process_resource_requirements }.not_to raise_error
@@ -147,12 +148,12 @@ describe "Chef::Provider::Service::Redhat" do
147
148
  chkconfig = double("Chkconfig", existatus: 1, stdout: "", stderr: "error reading information on service chef: No such file or directory")
148
149
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", returns: [0, 1]).and_return(chkconfig)
149
150
  @provider.load_current_resource
150
- @provider.define_resource_requirements
151
151
  end
152
152
 
153
153
  %w{start reload restart enable}.each do |action|
154
154
  it "should raise an error when the action is #{action}" do
155
155
  @provider.action = action
156
+ @provider.define_resource_requirements
156
157
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
157
158
  end
158
159
  end
@@ -161,12 +162,14 @@ describe "Chef::Provider::Service::Redhat" do
161
162
  it "should not raise an error when the action is #{action} and init_command is set" do
162
163
  @new_resource.init_command("/etc/init.d/chef")
163
164
  @provider.action = action
165
+ @provider.define_resource_requirements
164
166
  expect { @provider.process_resource_requirements }.not_to raise_error
165
167
  end
166
168
 
167
169
  it "should not raise an error when the action is #{action} and #{action}_command is set" do
168
170
  @new_resource.send("#{action}_command", "/etc/init.d/chef #{action}")
169
171
  @provider.action = action
172
+ @provider.define_resource_requirements
170
173
  expect { @provider.process_resource_requirements }.not_to raise_error
171
174
  end
172
175
  end
@@ -52,12 +52,14 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
52
52
 
53
53
  it "should raise error if the node has a nil ps property and no other means to get status" do
54
54
  @node.automatic_attrs[:command] = { ps: nil }
55
+ @provider.action = :start
55
56
  @provider.define_resource_requirements
56
57
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
57
58
  end
58
59
 
59
60
  it "should raise error if the node has an empty ps property and no other means to get status" do
60
61
  @node.automatic_attrs[:command] = { ps: "" }
62
+ @provider.action = :start
61
63
  @provider.define_resource_requirements
62
64
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
63
65
  end
@@ -112,8 +114,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
112
114
  end
113
115
 
114
116
  it "should raise an exception if no start command is specified" do
115
- @provider.define_resource_requirements
116
117
  @provider.action = :start
118
+ @provider.define_resource_requirements
117
119
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
118
120
  end
119
121
  end
@@ -126,8 +128,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
126
128
  end
127
129
 
128
130
  it "should raise an exception if no stop command is specified" do
129
- @provider.define_resource_requirements
130
131
  @provider.action = :stop
132
+ @provider.define_resource_requirements
131
133
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
132
134
  end
133
135
  end
@@ -140,8 +142,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
140
142
  end
141
143
 
142
144
  it "should raise an exception if the resource doesn't support restart, no restart command is provided, and no stop command is provided" do
143
- @provider.define_resource_requirements
144
145
  @provider.action = :restart
146
+ @provider.define_resource_requirements
145
147
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
146
148
  end
147
149
 
@@ -155,8 +157,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
155
157
 
156
158
  describe Chef::Provider::Service::Simple, "reload_service" do
157
159
  it "should raise an exception if reload is requested but no command is specified" do
158
- @provider.define_resource_requirements
159
160
  @provider.action = :reload
161
+ @provider.define_resource_requirements
160
162
  expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::UnsupportedAction)
161
163
  end
162
164
 
@@ -33,7 +33,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
33
33
 
34
34
  # Actual response from Win32::Service.config_info('chef-client')
35
35
  let(:chef_service_binary_path_name) do
36
- 'C:\\opscode\\chef\\embedded\\bin\\ruby.exe C:\\opscode\\chef\\bin\\chef-windows-service'
36
+ "C:\\opscode\\chef\\embedded\\bin\\ruby.exe C:\\opscode\\chef\\bin\\chef-windows-service"
37
37
  end
38
38
  let(:chef_service_config_info) do
39
39
  double("Struct::ServiceConfigInfo",
@@ -153,11 +153,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
153
153
  service_type: "share process",
154
154
  start_type: "demand start",
155
155
  error_control: "normal",
156
- binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted',
156
+ binary_path_name: "C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted",
157
157
  load_order_group: "TDI",
158
158
  tag_id: 0,
159
159
  dependencies: %w{NSI Tdx Afd},
160
- service_start_name: 'NT Authority\\LocalService',
160
+ service_start_name: "NT Authority\\LocalService",
161
161
  display_name: "DHCP Client")
162
162
  )
163
163
  end
@@ -169,11 +169,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
169
169
  service_type: "share process",
170
170
  start_type: "demand start",
171
171
  error_control: "normal",
172
- binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted',
172
+ binary_path_name: "C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted",
173
173
  load_order_group: "TDI",
174
174
  tag_id: 0,
175
175
  dependencies: %w{NSI Tdx Afd},
176
- service_start_name: 'NT Authority\\LocalService',
176
+ service_start_name: "NT Authority\\LocalService",
177
177
  display_name: "DHCP Client")
178
178
  )
179
179
  end
@@ -190,7 +190,7 @@ describe Chef::Provider::Subversion do
190
190
  it "runs an export with the --force option" do
191
191
  allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
192
192
  expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
193
- expect(@provider).to receive(:shell_out!).with(expected_cmd, {})
193
+ expect(@provider).to receive(:shell_out!).with(expected_cmd)
194
194
  @provider.run_action(:force_export)
195
195
  expect(@resource).to be_updated
196
196
  end
@@ -198,7 +198,7 @@ describe Chef::Provider::Subversion do
198
198
  it "runs the checkout command for action_checkout" do
199
199
  allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
200
200
  expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
201
- expect(@provider).to receive(:shell_out!).with(expected_cmd, {})
201
+ expect(@provider).to receive(:shell_out!).with(expected_cmd)
202
202
  @provider.run_action(:checkout)
203
203
  expect(@resource).to be_updated
204
204
  end
@@ -248,7 +248,7 @@ describe Chef::Provider::Subversion do
248
248
  allow(@provider).to receive(:find_current_revision).and_return("11410")
249
249
  allow(@provider).to receive(:current_revision_matches_target_revision?).and_return(false)
250
250
  expected_cmd = "svn update -q -r12345 /my/deploy/dir"
251
- expect(@provider).to receive(:shell_out!).with(expected_cmd, {})
251
+ expect(@provider).to receive(:shell_out!).with(expected_cmd)
252
252
  @provider.run_action(:sync)
253
253
  expect(@resource).to be_updated
254
254
  end
@@ -265,7 +265,7 @@ describe Chef::Provider::Subversion do
265
265
  it "runs the export_command on action_export" do
266
266
  allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
267
267
  expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
268
- expect(@provider).to receive(:shell_out!).with(expected_cmd, {})
268
+ expect(@provider).to receive(:shell_out!).with(expected_cmd)
269
269
  @provider.run_action(:export)
270
270
  expect(@resource).to be_updated
271
271
  end
@@ -170,6 +170,7 @@ describe Chef::Provider::User do
170
170
  sp_warn: 7, sp_inact: -1, sp_expire: -1, sp_flag: -1)
171
171
  expect(Shadow::Passwd).to receive(:getspnam).with("notarealuser").and_return(passwd_info)
172
172
  @provider.load_current_resource
173
+ @provider.action = :create
173
174
  @provider.define_resource_requirements
174
175
  @provider.process_resource_requirements
175
176
  end
@@ -180,6 +181,7 @@ describe Chef::Provider::User do
180
181
  it "should fail assertions when ruby-shadow cannot be loaded" do
181
182
  expect(@provider).to receive(:require).with("shadow") { raise LoadError }
182
183
  @provider.load_current_resource
184
+ @provider.action = :create
183
185
  @provider.define_resource_requirements
184
186
  expect { @provider.process_resource_requirements }.to raise_error Chef::Exceptions::MissingLibrary
185
187
  end
@@ -358,7 +358,7 @@ describe "windows_env provider", :windows_only do
358
358
  context "when environment is PATH" do
359
359
  describe "for PATH" do
360
360
  let(:system_root) { "%SystemRoot%" }
361
- let(:system_root_value) { 'D:\Windows' }
361
+ let(:system_root_value) { "D:\\Windows" }
362
362
  let(:new_resource) do
363
363
  new_resource = Chef::Resource::WindowsEnv.new("PATH", run_context)
364
364
  new_resource.value(system_root)
@@ -103,7 +103,7 @@ describe Chef::Provider::ZypperRepository do
103
103
 
104
104
  describe "#escaped_repo_name" do
105
105
  it "returns an escaped repo name" do
106
- expect(provider.escaped_repo_name).to eq('Nginx\\ Repository')
106
+ expect(provider.escaped_repo_name).to eq("Nginx\\ Repository")
107
107
  end
108
108
  end
109
109
 
@@ -51,4 +51,18 @@ describe Chef::Resource::ChefClientTrustedCertificate do
51
51
  expect(provider.cert_path).to match(%r{trusted_certs/something.pem$})
52
52
  end
53
53
  end
54
+
55
+ describe "sensitive attribute" do
56
+ context "should be insensitive by default" do
57
+ it { expect(resource.sensitive).to(be_falsey) }
58
+ end
59
+
60
+ context "when set" do
61
+ before { resource.sensitive(true) }
62
+
63
+ it "should be set on the resource" do
64
+ expect(resource.sensitive).to(be_truthy)
65
+ end
66
+ end
67
+ end
54
68
  end
@@ -41,7 +41,7 @@ describe Chef::Resource::ChocolateyConfig do
41
41
  # we save off the ENV and set ALLUSERSPROFILE so these specs will work on *nix and non-C drive Windows installs
42
42
  before(:each) do
43
43
  @original_env = ENV.to_hash
44
- ENV["ALLUSERSPROFILE"] = 'C:\ProgramData'
44
+ ENV["ALLUSERSPROFILE"] = "C:\\ProgramData"
45
45
  end
46
46
 
47
47
  after(:each) do
@@ -41,7 +41,7 @@ describe Chef::Resource::ChocolateyFeature do
41
41
  # we save off the ENV and set ALLUSERSPROFILE so these specs will work on *nix and non-C drive Windows installs
42
42
  before(:each) do
43
43
  @original_env = ENV.to_hash
44
- ENV["ALLUSERSPROFILE"] = 'C:\ProgramData'
44
+ ENV["ALLUSERSPROFILE"] = "C:\\ProgramData"
45
45
  end
46
46
 
47
47
  after(:each) do
@@ -54,7 +54,7 @@ describe Chef::Resource::ChocolateySource do
54
54
  allow(resource).to receive(:provider_for_action).and_return(enable_provider)
55
55
  allow(resource.class).to receive(:new).and_return(current_resource)
56
56
  @original_env = ENV.to_hash
57
- ENV["ALLUSERSPROFILE"] = 'C:\ProgramData'
57
+ ENV["ALLUSERSPROFILE"] = "C:\\ProgramData"
58
58
  end
59
59
 
60
60
  after(:each) do
@@ -57,4 +57,16 @@ describe Chef::Resource::DpkgPackage, "initialize" do
57
57
  end
58
58
  end
59
59
 
60
+ describe Chef::Resource::DpkgPackage, "allow_downgrade" do
61
+ before(:each) do
62
+ @resource = Chef::Resource::DpkgPackage.new("fakey_fakerton")
63
+ end
64
+
65
+ it "should allow you to specify whether allow_downgrade is true or false" do
66
+ expect { @resource.allow_downgrade true }.not_to raise_error
67
+ expect { @resource.allow_downgrade false }.not_to raise_error
68
+ expect { @resource.allow_downgrade "something" }.to raise_error(ArgumentError)
69
+ end
70
+ end
71
+
60
72
  end
@@ -32,10 +32,11 @@ describe Chef::Resource::KernelModule do
32
32
  expect(resource.modname).to eql("foo")
33
33
  end
34
34
 
35
- it "supports :create and :flush actions" do
35
+ it "supports various actions" do
36
36
  expect { resource.action :install }.not_to raise_error
37
37
  expect { resource.action :uninstall }.not_to raise_error
38
38
  expect { resource.action :blacklist }.not_to raise_error
39
+ expect { resource.action :enable }.not_to raise_error
39
40
  expect { resource.action :disable }.not_to raise_error
40
41
  expect { resource.action :load }.not_to raise_error
41
42
  expect { resource.action :unload }.not_to raise_error
@@ -17,120 +17,60 @@
17
17
 
18
18
  require "spec_helper"
19
19
 
20
- describe Chef::Resource::MacosUserDefaults do
21
-
22
- let(:resource) { Chef::Resource::MacosUserDefaults.new("foo") }
23
- let(:provider) { resource.provider_for_action(:write) }
24
-
25
- it "has a resource name of :macos_userdefaults" do
26
- expect(resource.resource_name).to eq(:macos_userdefaults)
27
- end
28
-
29
- it "the domain property defaults to NSGlobalDomain" do
30
- expect(resource.domain).to eq("NSGlobalDomain")
31
- end
32
-
33
- it "the value property coerces keys in hashes to strings so we can compare them with plist data" do
34
- resource.value "User": "/Library/Managed Installs/way_fake.log"
35
- expect(resource.value).to eq({ "User" => "/Library/Managed Installs/way_fake.log" })
36
- end
37
-
38
- it "the host property defaults to nil" do
39
- expect(resource.host).to be_nil
40
- end
41
-
42
- it "the sudo property defaults to false" do
43
- expect(resource.sudo).to be false
44
- end
45
-
46
- it "sets the default action as :write" do
47
- expect(resource.action).to eq([:write])
48
- end
49
-
50
- it "supports :write action" do
51
- expect { resource.action :write }.not_to raise_error
52
- end
53
-
54
- describe "#defaults_export_cmd" do
55
- it "exports NSGlobalDomain if no domain is set" do
56
- expect(provider.defaults_export_cmd(resource)).to eq(["/usr/bin/defaults", "export", "NSGlobalDomain", "-"])
20
+ describe Chef::Resource::MacosUserDefaults, :macos_only do
21
+ let(:test_value) { "fakest_key_value" }
22
+ let(:test_key) { "fakest_key" }
23
+ let(:node) { Chef::Node.new }
24
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
25
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
26
+ let(:resource) {
27
+ Chef::Resource::MacosUserDefaults.new("foo", run_context).tap do |r|
28
+ r.value test_value
29
+ r.key test_key
57
30
  end
31
+ }
58
32
 
59
- it "exports a provided domain" do
60
- resource.domain "com.tim"
61
- expect(provider.defaults_export_cmd(resource)).to eq(["/usr/bin/defaults", "export", "com.tim", "-"])
33
+ context "has a default value" do
34
+ it ":macos_userdefaults for resource name" do
35
+ expect(resource.resource_name).to eq(:macos_userdefaults)
62
36
  end
63
37
 
64
- it "sets -currentHost if host is 'current'" do
65
- resource.host "current"
66
- expect(provider.defaults_export_cmd(resource)).to eq(["/usr/bin/defaults", "-currentHost", "export", "NSGlobalDomain", "-"])
38
+ it "NSGlobalDomain for the domain property" do
39
+ expect(resource.domain).to eq("NSGlobalDomain")
67
40
  end
68
41
 
69
- it "sets -host 'tim-laptop if host is 'tim-laptop'" do
70
- resource.host "tim-laptop"
71
- expect(provider.defaults_export_cmd(resource)).to eq(["/usr/bin/defaults", "-host", "tim-laptop", "export", "NSGlobalDomain", "-"])
72
- end
73
- end
74
-
75
- describe "#defaults_modify_cmd" do
76
- # avoid needing to set these required values over and over. We'll overwrite them where necessary
77
- before do
78
- resource.key = "foo"
79
- resource.value = "bar"
80
- end
81
-
82
- it "writes to NSGlobalDomain if domain isn't specified" do
83
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-string", "bar"])
84
- end
85
-
86
- it "uses the domain property if set" do
87
- resource.domain = "MyCustomDomain"
88
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "MyCustomDomain", "foo", "-string", "bar"])
42
+ it "nil for the host property" do
43
+ expect(resource.host).to be_nil
89
44
  end
90
45
 
91
- it "sets host specific values using host property" do
92
- resource.host = "tims_laptop"
93
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "-host", "tims_laptop", "write", "NSGlobalDomain", "foo", "-string", "bar"])
46
+ it "nil for the user property" do
47
+ expect(resource.user).to be_nil
94
48
  end
95
49
 
96
- it "if host is set to :current it passes CurrentHost" do
97
- resource.host = :current
98
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "-currentHost", "write", "NSGlobalDomain", "foo", "-string", "bar"])
99
- end
100
-
101
- it "raises ArgumentError if bool is specified, but the value can't be made into a bool" do
102
- resource.type "bool"
103
- expect { provider.defaults_modify_cmd }.to raise_error(ArgumentError)
104
- end
105
-
106
- it "autodetects array type and passes individual values" do
107
- resource.value = %w{one two three}
108
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-array", "one", "two", "three"])
109
- end
110
-
111
- it "autodetects string type and passes a single value" do
112
- resource.value = "one"
113
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-string", "one"])
50
+ it ":write for resource action" do
51
+ expect(resource.action).to eq([:write])
114
52
  end
53
+ end
115
54
 
116
- it "autodetects integer type and passes a single value" do
117
- resource.value = 1
118
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-int", 1])
55
+ context ":write" do
56
+ it "is a supported action" do
57
+ expect { resource.action :write }.not_to raise_error
119
58
  end
120
59
 
121
- it "autodetects boolean type from TrueClass value and passes a 'TRUE' string" do
122
- resource.value = true
123
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-bool", "TRUE"])
60
+ it "successfully updates the preference" do
61
+ resource.run_action(:write)
62
+ expect(resource.get_preference resource).eql? test_value
124
63
  end
64
+ end
125
65
 
126
- it "autodetects boolean type from FalseClass value and passes a 'FALSE' string" do
127
- resource.value = false
128
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-bool", "FALSE"])
66
+ context ":delete" do
67
+ it "is a supported action" do
68
+ expect { resource.action :delete }.not_to raise_error
129
69
  end
130
70
 
131
- it "autodetects dict type from Hash value and flattens keys & values" do
132
- resource.value = { "foo" => "bar" }
133
- expect(provider.defaults_modify_cmd).to eq(["/usr/bin/defaults", "write", "NSGlobalDomain", "foo", "-dict", "foo", "bar"])
71
+ it "successfully deletes the preference" do
72
+ resource.run_action(:delete)
73
+ expect(resource.get_preference resource).to be_nil
134
74
  end
135
75
  end
136
76
  end
@@ -19,14 +19,14 @@
19
19
  require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::RegistryKey, "initialize" do
22
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
22
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
23
23
 
24
24
  it "sets the resource_name to :registry_key" do
25
25
  expect(resource.resource_name).to eql(:registry_key)
26
26
  end
27
27
 
28
28
  it "the key property is the name_property" do
29
- expect(resource.key).to eql('HKCU\Software\Raxicoricofallapatorius')
29
+ expect(resource.key).to eql("HKCU\\Software\\Raxicoricofallapatorius")
30
30
  end
31
31
 
32
32
  it "sets the default action as :create" do
@@ -60,11 +60,11 @@ describe Chef::Resource::RegistryKey, "initialize" do
60
60
  end
61
61
 
62
62
  describe Chef::Resource::RegistryKey, "key" do
63
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
63
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
64
64
 
65
65
  it "allows a string" do
66
- resource.key 'HKCU\Software\Poosh'
67
- expect(resource.key).to eql('HKCU\Software\Poosh')
66
+ resource.key "HKCU\\Software\\Poosh"
67
+ expect(resource.key).to eql("HKCU\\Software\\Poosh")
68
68
  end
69
69
 
70
70
  it "does not allow an integer" do
@@ -77,7 +77,7 @@ describe Chef::Resource::RegistryKey, "key" do
77
77
  end
78
78
 
79
79
  describe Chef::Resource::RegistryKey, "values" do
80
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
80
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
81
81
 
82
82
  it "allows a single proper hash of registry values" do
83
83
  resource.values( { name: "poosh", type: :string, data: "carmen" } )
@@ -140,7 +140,7 @@ describe Chef::Resource::RegistryKey, "values" do
140
140
  end
141
141
 
142
142
  describe Chef::Resource::RegistryKey, "recursive" do
143
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
143
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
144
144
 
145
145
  it "allows a boolean" do
146
146
  resource.recursive(true)
@@ -165,7 +165,7 @@ describe Chef::Resource::RegistryKey, "recursive" do
165
165
  end
166
166
 
167
167
  describe Chef::Resource::RegistryKey, "architecture" do
168
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
168
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
169
169
 
170
170
  %i{i386 x86_64 machine}.each do |arch|
171
171
  it "allows #{arch} as a symbol" do
@@ -196,7 +196,7 @@ describe Chef::Resource::RegistryKey, "architecture" do
196
196
  end
197
197
 
198
198
  describe Chef::Resource::RegistryKey, ":unscrubbed_values" do
199
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
199
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
200
200
 
201
201
  it "returns unsafe data as-is" do
202
202
  key_values = [ { name: "poosh", type: :binary, data: 255.chr * 1 } ]
@@ -206,7 +206,7 @@ describe Chef::Resource::RegistryKey, ":unscrubbed_values" do
206
206
  end
207
207
 
208
208
  describe Chef::Resource::RegistryKey, "state" do
209
- let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') }
209
+ let(:resource) { Chef::Resource::RegistryKey.new("HKCU\\Software\\Raxicoricofallapatorius") }
210
210
 
211
211
  it "returns scrubbed values" do
212
212
  resource.values([ { name: "poosh", type: :binary, data: 255.chr * 1 } ])
@@ -158,6 +158,48 @@ describe Chef::Resource::RhsmRegister do
158
158
  end
159
159
  end
160
160
 
161
+ context "when a server_url is provided" do
162
+ it "returns a command containing the server url" do
163
+ allow(resource).to receive(:server_url).and_return("https://fqdn.example")
164
+ expect(provider.register_command).to match("--serverurl=https://fqdn.example")
165
+ end
166
+ end
167
+
168
+ context "when a base_url is provided" do
169
+ it "returns a command containing the base url" do
170
+ allow(resource).to receive(:base_url).and_return("https://fqdn.example")
171
+ expect(provider.register_command).to match("--baseurl=https://fqdn.example")
172
+ end
173
+ end
174
+
175
+ context "when a service_level is provided" do
176
+ it "returns a command containing the service level" do
177
+ allow(resource).to receive(:service_level).and_return("None")
178
+ allow(resource).to receive(:auto_attach).and_return(true)
179
+ expect(provider.register_command).to match("--servicelevel=None")
180
+ end
181
+
182
+ it "raises an exception if auto_attach is not set" do
183
+ allow(resource).to receive(:service_level).and_return("None")
184
+ allow(resource).to receive(:auto_attach).and_return(nil)
185
+ expect { provider.register_command }.to raise_error(RuntimeError)
186
+ end
187
+ end
188
+
189
+ context "when a release is provided" do
190
+ it "returns a command containing the release" do
191
+ allow(resource).to receive(:release).and_return("8.4")
192
+ allow(resource).to receive(:auto_attach).and_return(true)
193
+ expect(provider.register_command).to match("--release=8.4")
194
+ end
195
+
196
+ it "raises an exception if auto_attach is not set" do
197
+ allow(resource).to receive(:release).and_return("8.4")
198
+ allow(resource).to receive(:auto_attach).and_return(nil)
199
+ expect { provider.register_command }.to raise_error(RuntimeError)
200
+ end
201
+ end
202
+
161
203
  context "when a system_name is not provided" do
162
204
  it "returns a command containing the system name" do
163
205
  allow(resource).to receive(:system_name).and_return(nil)
@@ -45,6 +45,6 @@ describe Chef::Resource::WindowsAutorun do
45
45
 
46
46
  it "coerces forward slashes to backslashes for the path" do
47
47
  resource.path "C:/something.exe"
48
- expect(resource.path).to eql('C:\\something.exe')
48
+ expect(resource.path).to eql("C:\\something.exe")
49
49
  end
50
50
  end
@@ -76,7 +76,7 @@ describe Chef::Resource::WindowsFeaturePowershell do
76
76
  node.default["powershell_features_cache"]["disabled"] = ["dhcp"]
77
77
  node.default["powershell_features_cache"]["removed"] = ["snmp"]
78
78
  resource.feature_name "dhcp, snmp"
79
- resource.source 'D:\\sources\\sxs'
79
+ resource.source "D:\\sources\\sxs"
80
80
 
81
81
  expect(provider.features_to_install).to eq(%w{dhcp snmp})
82
82
  end