summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmidt <ts@soundcloud.com>2013-12-03 12:49:56 +0700
committerTobias Schmidt <ts@soundcloud.com>2013-12-04 01:41:34 +0700
commitbff171e7a00f951231efdb45e51c0ae1d97ba05d (patch)
treebbb49f706fc9cf66d2e16831005413042d139f2c
parent41ca23434f820885dd6d78ca49403b24d7400949 (diff)
downloadchef-bff171e7a00f951231efdb45e51c0ae1d97ba05d.tar.gz
[CHEF-4842] Fix comparison of user resources with non-ASCII comments
In case a comment of a user resource includes non-ASCII characters, the comparison whether the resource was changed will always fail. Therefore, such user resources will get modified during every chef-client run. Example: user "marci" do comment "Márton Salomváry" # ... end So far, this resulted in a comparision of "M\xC3\xA1rton Salomv\xC3\xA1ry" with "Márton Salomváry" which fails, unless the encoding gets changed prior to the comparision.
-rw-r--r--lib/chef/provider/user.rb6
-rw-r--r--spec/unit/provider/user_spec.rb6
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