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 11:26:35 -0700
commitbbc16fe716ff2351fe81a18e4bf7d0ce75c5b555 (patch)
treea36c437a769ca03b41e86930d26c5d459cd03948
parent4b1d91928f6fbffea34d7169b5bb75591a6f27b7 (diff)
downloadchef-bbc16fe716ff2351fe81a18e4bf7d0ce75c5b555.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