summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-12-30 15:57:04 -0800
committerTim Smith <tsmith84@gmail.com>2021-01-04 12:44:08 -0800
commit351522ea504aee9e635dc7de6e668c9346f89763 (patch)
tree338d0efc8aee69a1aa9d78c133f1576c92317d98
parent495873a950c4793b1a4e907fb973044097285b4f (diff)
downloadchef-uuid.tar.gz
Coerce uid to integer in Windows user resource.uuid
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/windows.rb10
-rw-r--r--lib/chef/resource/user/windows_user.rb5
-rw-r--r--spec/unit/resource/user/windows_user_spec.rb36
3 files changed, 50 insertions, 1 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
index 58ccec9b26..ea5f0f7421 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -105,4 +105,12 @@ include_recipe "::_ohai_hint"
hostname "new-hostname" do
windows_reboot false
-end \ No newline at end of file
+end
+
+user "phil" do
+ uid "8019"
+end
+
+user "phil" do
+ action :remove
+end
diff --git a/lib/chef/resource/user/windows_user.rb b/lib/chef/resource/user/windows_user.rb
index d504158edf..d738ba1636 100644
--- a/lib/chef/resource/user/windows_user.rb
+++ b/lib/chef/resource/user/windows_user.rb
@@ -29,6 +29,11 @@ class Chef
property :full_name, String,
description: "The full name of the user.",
introduced: "14.6"
+
+ # Override the property from the parent class to coerce to integer.
+ property :uid, [ String, Integer, NilClass ], # nil for backwards compat
+ description: "The numeric user identifier.",
+ coerce: proc { |n| n && Integer(n) rescue n }
end
end
end
diff --git a/spec/unit/resource/user/windows_user_spec.rb b/spec/unit/resource/user/windows_user_spec.rb
new file mode 100644
index 0000000000..32f8e69d99
--- /dev/null
+++ b/spec/unit/resource/user/windows_user_spec.rb
@@ -0,0 +1,36 @@
+#
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+
+describe Chef::Resource::User::WindowsUser, "#uid" do
+ let(:resource) { Chef::Resource::User::WindowsUser.new("notarealuser") }
+
+ it "allows a string" do
+ resource.uid "100"
+ expect(resource.uid).to eql(100)
+ end
+
+ it "allows an integer" do
+ resource.uid 100
+ expect(resource.uid).to eql(100)
+ end
+
+ it "does not allow a hash" do
+ expect { resource.uid({ woot: "i found it" }) }.to raise_error(ArgumentError)
+ end
+end