summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffrey Hichborn <geoff@socialcast.com>2016-10-13 09:36:00 -0700
committerGeoffrey Hichborn <geoff@socialcast.com>2016-10-13 12:47:58 -0700
commita28b5024f9725939e2bd3666e83d5ea576b5ffa3 (patch)
treea01d160ac5514f792878c3fc198662032f3f6c2d
parent5e7c3b96f125c6a07c6c48c0d27899100b3be9a6 (diff)
downloadchef-a28b5024f9725939e2bd3666e83d5ea576b5ffa3.tar.gz
Refactored Chef::Provider::User to short circuit and provider better comparison of home paths to fix Issue #5444
Signed-off-by: Geoffrey Hichborn <geoff@socialcast.com>
-rw-r--r--lib/chef/provider/user.rb10
-rw-r--r--spec/unit/provider/user_spec.rb6
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index f6b088d333..4b05ac8f5e 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -113,15 +113,13 @@ class Chef
# <true>:: If a change is required
# <false>:: If the users are identical
def compare_user
- changed = [ :comment, :home, :shell, :password ].select do |user_attrib|
- !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib) != @current_resource.send(user_attrib)
- end
+ return true if !@new_resource.home.nil? && Pathname.new(@new_resource.home).cleanpath != Pathname.new(@current_resource.home).cleanpath
- changed += [ :uid, :gid ].select do |user_attrib|
- !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_s != @current_resource.send(user_attrib).to_s
+ [ :comment, :shell, :password, :uid, :gid ].each do |user_attrib|
+ return true if !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_s != @current_resource.send(user_attrib).to_s
end
- changed.any?
+ false
end
def action_create
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 1a8ad6ad1b..719dc8d492 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -221,6 +221,12 @@ describe Chef::Provider::User do
it "should return false if the objects are identical" do
expect(@provider.compare_user).to eql(false)
end
+
+ it "should ignore differences in trailing slash in home paths" do
+ @new_resource.home "/home/adam"
+ @current_resource.home "/home/adam/"
+ expect(@provider.compare_user).to eql(false)
+ end
end
describe "action_create" do