diff options
author | lamont-granquist <lamont@scriptkiddie.org> | 2013-12-03 11:35:30 -0800 |
---|---|---|
committer | lamont-granquist <lamont@scriptkiddie.org> | 2013-12-03 11:35:30 -0800 |
commit | ca77ec8471560de11ca1ca3244c8fdaa178741cc (patch) | |
tree | bbb49f706fc9cf66d2e16831005413042d139f2c | |
parent | 41ca23434f820885dd6d78ca49403b24d7400949 (diff) | |
parent | bff171e7a00f951231efdb45e51c0ae1d97ba05d (diff) | |
download | chef-ca77ec8471560de11ca1ca3244c8fdaa178741cc.tar.gz |
Merge pull request #1156 from soundcloud/fix-user-resource-comparison
[CHEF-4842] Fix comparison of user resources with non-ASCII comments
-rw-r--r-- | lib/chef/provider/user.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/user_spec.rb | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb index 738f7660f8..2ab7b0fb98 100644 --- a/lib/chef/provider/user.rb +++ b/lib/chef/provider/user.rb @@ -63,11 +63,15 @@ class Chef if user_info @current_resource.uid(user_info.uid) @current_resource.gid(user_info.gid) - @current_resource.comment(user_info.gecos) @current_resource.home(user_info.dir) @current_resource.shell(user_info.shell) @current_resource.password(user_info.passwd) + if @new_resource.comment && user_info.gecos.respond_to?(:force_encoding) + user_info.gecos.force_encoding(@new_resource.comment.encoding) + end + @current_resource.comment(user_info.gecos) + if @new_resource.password && @current_resource.password == 'x' begin require 'shadow' diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index d054fcc440..d5e694b79c 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -91,6 +91,12 @@ describe Chef::Provider::User do @current_resource.username.should == @new_resource.username end + it "should change the encoding of gecos to the encoding of the new resource", :ruby_gte_19_only do + @pw_user.gecos.force_encoding('ASCII-8BIT') + @provider.load_current_resource + @provider.current_resource.comment.encoding.should == @new_resource.comment.encoding + end + it "should look up the user in /etc/passwd with getpwnam" do Etc.should_receive(:getpwnam).with(@new_resource.username).and_return(@pw_user) @provider.load_current_resource |