summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Zholobov <legal90@gmail.com>2015-04-05 19:46:06 +0300
committerLamont Granquist <lamont@scriptkiddie.org>2015-10-23 12:39:00 -0700
commitd246a05fe763e34c0b9fac698d88a45f4daa1a94 (patch)
tree90f34da0388a23e177a7634f5fd5d5e45ecc3d10
parent60ce05c7af318488655344d134e4fb270f61d888 (diff)
downloadchef-d246a05fe763e34c0b9fac698d88a45f4daa1a94.tar.gz
provider/user/dscl: Set default gid to 20
gid should always be defined to create user account properly on OS X. "staff" (gid 20) is a default group for regular user accounts.
-rw-r--r--lib/chef/provider/user/dscl.rb7
-rw-r--r--spec/unit/provider/user/dscl_spec.rb7
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb
index 0c0c85e18b..d9e235d4b1 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -257,10 +257,13 @@ user password using shadow hash.")
#
# Sets the group id for the user using dscl. Fails if a group doesn't
- # exist on the system with given group id.
+ # exist on the system with given group id. If `gid` is not specified, it
+ # sets a default Mac user group "staff", with id 20.
#
def dscl_set_gid
- unless @new_resource.gid && @new_resource.gid.to_s.match(/^\d+$/)
+ if @new_resource.gid.nil?
+ @new_resource.gid(20)
+ elsif !@new_resource.gid.to_s.match(/^\d+$/)
begin
possible_gid = run_dscl("read /Groups/#{@new_resource.gid} PrimaryGroupID").split(" ").last
rescue Chef::Exceptions::DsclCommandFailed => e
diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb
index 32d0812d8c..e8cf6445be 100644
--- a/spec/unit/provider/user/dscl_spec.rb
+++ b/spec/unit/provider/user/dscl_spec.rb
@@ -789,6 +789,13 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30")
expect { provider.dscl_set_gid }.to raise_error(Chef::Exceptions::GroupIDNotFound)
end
end
+
+ it "should set group ID to 20 if it's not specified" do
+ new_resource.gid nil
+ expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '20'").ordered.and_return(true)
+ provider.dscl_set_gid
+ expect(new_resource.gid).to eq(20)
+ end
end
describe "when the user exists and chef is managing it" do