summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-12-30 15:57:04 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-30 16:02:22 -0800
commit6dfa208f81ba70bb24d980f6e8a881f36d0911da (patch)
tree6c86c02449fc15e3089a33ea83644ca61da18d6c
parent69129178ba11f8d4c329d477dfff9eacb4660025 (diff)
downloadchef-6dfa208f81ba70bb24d980f6e8a881f36d0911da.tar.gz
Coerce uid to integer in Windows user resource.
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 46176901dd..c6cd597fe0 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -125,4 +125,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