diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-12-30 12:03:08 -0800 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-12-30 12:04:14 -0800 |
commit | cbcee1199d5d5d27e94d559a4b2b254fe93c8a38 (patch) | |
tree | 490e65b6f89c0b92944a30c850e4378c5ce6280c | |
parent | c46440d349b2328dab9a868559dcb72ffb0b426d (diff) | |
download | chef-coerce-user-uid-and-gid-to-integer.tar.gz |
Coerce uid and gid to integer to prevent failures in Windows.coerce-user-uid-and-gid-to-integer
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r-- | kitchen-tests/cookbooks/end_to_end/recipes/windows.rb | 10 | ||||
-rw-r--r-- | lib/chef/resource/user.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/user_spec.rb | 4 |
3 files changed, 15 insertions, 5 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.rb b/lib/chef/resource/user.rb index 408932175d..d0ff0e3eae 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -67,10 +67,12 @@ class Chef default: false property :uid, [ String, Integer, NilClass ], # nil for backwards compat - description: "The numeric user identifier." + description: "The numeric user identifier.", + coerce: proc { |n| n && Integer(n) } property :gid, [ String, Integer, NilClass ], # nil for backwards compat - description: "The numeric group identifier." + description: "The numeric group identifier.", + coerce: proc { |n| n && Integer(n) } alias_method :group, :gid end diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb index 58c17024af..5f8c189502 100644 --- a/spec/unit/resource/user_spec.rb +++ b/spec/unit/resource/user_spec.rb @@ -85,7 +85,7 @@ end it "allows a string" do resource.send(attrib, "100") - expect(resource.send(attrib)).to eql("100") + expect(resource.send(attrib)).to eql(100) end it "allows an integer" do @@ -94,7 +94,7 @@ end end it "does not allow a hash" do - expect { resource.send(attrib, { woot: "i found it" }) }.to raise_error(ArgumentError) + expect { resource.send(attrib, { woot: "i found it" }) }.to raise_error(TypeError) end end |