summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-09-11 11:26:35 -0700
committerTim Smith <tsmith84@gmail.com>2020-09-11 17:15:46 -0700
commit405778e51c3ffde480b6d2e94ec56b7dde9232c5 (patch)
treec3df03226b73115db5e30920e2bc343f297d447f
parentc0c510a465cb22cace9e37595945e50b6e79fba3 (diff)
downloadchef-405778e51c3ffde480b6d2e94ec56b7dde9232c5.tar.gz
Simplify validation and add some unit tests
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_user_privilege.rb18
-rw-r--r--spec/unit/resource/windows_user_privilege_spec.rb20
2 files changed, 23 insertions, 15 deletions
diff --git a/lib/chef/resource/windows_user_privilege.rb b/lib/chef/resource/windows_user_privilege.rb
index bfdab8cdf9..2814896fc3 100644
--- a/lib/chef/resource/windows_user_privilege.rb
+++ b/lib/chef/resource/windows_user_privilege.rb
@@ -133,23 +133,11 @@ class Chef
description: "An optional property to set the privilege for given users. Use only with set action."
property :privilege, [Array, String],
- description: "Privilege to set for users.",
+ description: "One or more privileges to set for users.",
required: true,
- coerce: proc { |v| v.is_a?(String) ? Array[v] : v },
+ coerce: proc { |v| Array[v] },
callbacks: {
- "Option privilege must include any of the: #{PRIVILEGE_OPTS}" => lambda { |n|
- if n.is_a?(String)
- these_options = Array[n]
- else
- these_options = n
- end
-
- if (these_options - PRIVILEGE_OPTS).empty?
- true
- else
- false
- end
- },
+ "Option privilege must include any of the: #{PRIVILEGE_OPTS}" => lambda { |n| (n - PRIVILEGE_OPTS).empty? },
}
load_current_value do |new_resource|
diff --git a/spec/unit/resource/windows_user_privilege_spec.rb b/spec/unit/resource/windows_user_privilege_spec.rb
index 7e1d2e5304..96f9eb93fe 100644
--- a/spec/unit/resource/windows_user_privilege_spec.rb
+++ b/spec/unit/resource/windows_user_privilege_spec.rb
@@ -24,7 +24,27 @@ describe Chef::Resource::WindowsUserPrivilege do
expect(resource.resource_name).to eql(:windows_user_privilege)
end
+ it "the principal property is the name_property" do
+ expect(resource.principal).to eql("fakey_fakerton")
+ end
+
+ it "the principal privilege property coerces to an array" do
+ resource.privilege "SeDenyRemoteInteractiveLogonRight"
+ expect(resource.privilege).to eql(["SeDenyRemoteInteractiveLogonRight"])
+ end
+
+ it "the principal privilege validates inputs against the allowed list of privs" do
+ expect { resource.privilege "invalidPriv" }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
it "sets the default action as :add" do
expect(resource.action).to eql([:add])
end
+
+ it "supports :add, :set, :clear, :remove actions" do
+ expect { resource.action :add }.not_to raise_error
+ expect { resource.action :set }.not_to raise_error
+ expect { resource.action :clear }.not_to raise_error
+ expect { resource.action :remove }.not_to raise_error
+ end
end