summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-12-22 13:56:13 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-12-22 13:56:13 -0800
commit4271813a92b522436c4c245abe51683e8243be5d (patch)
tree8889cbf15ee02eb9ff4c558d32d50394b83e48eb
parent155f40ec4d95b02bd38fbed427c41f69abbb75ea (diff)
downloadchef-4271813a92b522436c4c245abe51683e8243be5d.tar.gz
fix dscl group provider func breakage
i didn't fully grok the way the dscl providers were written and only half fixed the group dscl provider, but later did a better job fixing the user one. fixes the breakage caught in the dscl group func tests. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/group/dscl.rb22
-rw-r--r--spec/unit/provider/group/dscl_spec.rb42
2 files changed, 32 insertions, 32 deletions
diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb
index 46932adc94..71e42b36ba 100644
--- a/lib/chef/provider/group/dscl.rb
+++ b/lib/chef/provider/group/dscl.rb
@@ -48,7 +48,7 @@ class Chef
current_resource.group_name(new_resource.group_name)
group_info = nil
begin
- group_info = safe_dscl("read /Groups/#{new_resource.group_name}")
+ group_info = safe_dscl("read", "/Groups/#{new_resource.group_name}")
rescue Chef::Exceptions::Group
@group_exists = false
Chef::Log.debug("#{new_resource} group does not exist")
@@ -74,7 +74,7 @@ class Chef
# get a free GID greater than 200
def get_free_gid(search_limit = 1000)
gid = nil; next_gid_guess = 200
- groups_gids = safe_dscl("list /Groups gid")
+ groups_gids = safe_dscl("list", "/Groups", "gid")
while next_gid_guess < search_limit + 200
if groups_gids =~ Regexp.new("#{Regexp.escape(next_gid_guess.to_s)}\n")
next_gid_guess += 1
@@ -88,22 +88,22 @@ class Chef
def gid_used?(gid)
return false unless gid
- groups_gids = safe_dscl("list /Groups gid")
+ groups_gids = safe_dscl("list", "/Groups", "gid")
!!( groups_gids =~ Regexp.new("#{Regexp.escape(gid.to_s)}\n") )
end
def set_gid
new_resource.gid(get_free_gid) if [nil, ""].include? new_resource.gid
raise(Chef::Exceptions::Group, "gid is already in use") if gid_used?(new_resource.gid)
- safe_dscl("create /Groups/#{new_resource.group_name} PrimaryGroupID #{new_resource.gid}")
+ safe_dscl("create", "/Groups/#{new_resource.group_name}", "PrimaryGroupID", new_resource.gid)
end
def set_members
# First reset the memberships if the append is not set
unless new_resource.append
Chef::Log.debug("#{new_resource} removing group members #{current_resource.members.join(' ')}") unless current_resource.members.empty?
- safe_dscl("create /Groups/#{new_resource.group_name} GroupMembers ''") # clear guid list
- safe_dscl("create /Groups/#{new_resource.group_name} GroupMembership ''") # clear user list
+ safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembers", "") # clear guid list
+ safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembership", "") # clear user list
current_resource.members([ ])
end
@@ -115,7 +115,7 @@ class Chef
end
unless members_to_be_added.empty?
Chef::Log.debug("#{new_resource} setting group members #{members_to_be_added.join(', ')}")
- safe_dscl("append /Groups/#{new_resource.group_name} GroupMembership #{members_to_be_added.join(' ')}")
+ safe_dscl("append", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_added)
end
end
@@ -127,7 +127,7 @@ class Chef
end
unless members_to_be_removed.empty?
Chef::Log.debug("#{new_resource} removing group members #{members_to_be_removed.join(', ')}")
- safe_dscl("delete /Groups/#{new_resource.group_name} GroupMembership #{members_to_be_removed.join(' ')}")
+ safe_dscl("delete", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_removed)
end
end
end
@@ -160,12 +160,12 @@ class Chef
end
def dscl_create_group
- safe_dscl("create /Groups/#{new_resource.group_name}")
- safe_dscl("create /Groups/#{new_resource.group_name} Password '*'")
+ safe_dscl("create", "/Groups/#{new_resource.group_name}")
+ safe_dscl("create", "/Groups/#{new_resource.group_name}", "Password", "*")
end
def remove_group
- safe_dscl("delete /Groups/#{new_resource.group_name}")
+ safe_dscl("delete", "/Groups/#{new_resource.group_name}")
end
end
end
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index 9dc969c352..52d43f907d 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -51,8 +51,8 @@ describe Chef::Provider::Group::Dscl do
end
it "should run dscl with the supplied cmd /Path args" do
- expect(@provider).to receive(:dscl).with("cmd /Path args")
- @provider.safe_dscl("cmd /Path args")
+ expect(@provider).to receive(:dscl).with(*"cmd /Path args".split(" "))
+ @provider.safe_dscl(*"cmd /Path args".split(" "))
end
describe "with the dscl command returning a non zero exit status for a delete" do
@@ -62,13 +62,13 @@ describe Chef::Provider::Group::Dscl do
end
it "should return an empty string of standard output for a delete" do
- safe_dscl_retval = @provider.safe_dscl("delete /Path args")
+ safe_dscl_retval = @provider.safe_dscl(*"delete /Path args".split(" "))
expect(safe_dscl_retval).to be_a_kind_of(String)
expect(safe_dscl_retval).to eq("")
end
it "should raise an exception for any other command" do
- expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group)
+ expect { @provider.safe_dscl(*"cmd /Path arguments".split(" ")) }.to raise_error(Chef::Exceptions::Group)
end
end
@@ -78,13 +78,13 @@ describe Chef::Provider::Group::Dscl do
end
it "should raise an exception" do
- expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group)
+ expect { @provider.safe_dscl(*"cmd /Path arguments".split(" ")) }.to raise_error(Chef::Exceptions::Group)
end
end
describe "with the dscl command returning a zero exit status" do
it "should return the third array element, the string of standard output" do
- safe_dscl_retval = @provider.safe_dscl("cmd /Path args")
+ safe_dscl_retval = @provider.safe_dscl(*"cmd /Path args".split(" "))
expect(safe_dscl_retval).to be_a_kind_of(String)
expect(safe_dscl_retval).to eq("stdout")
end
@@ -99,7 +99,7 @@ describe Chef::Provider::Group::Dscl do
end
it "should run safe_dscl with list /Groups gid" do
- expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
+ expect(@provider).to receive(:safe_dscl).with(*"list /Groups gid".split(" "))
@provider.get_free_gid
end
@@ -121,7 +121,7 @@ describe Chef::Provider::Group::Dscl do
end
it "should run safe_dscl with list /Groups gid" do
- expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
+ expect(@provider).to receive(:safe_dscl).with(*"list /Groups gid".split(" "))
@provider.gid_used?(500)
end
@@ -171,8 +171,8 @@ describe Chef::Provider::Group::Dscl do
describe "with a valid gid number which is not already in use" do
it "should run safe_dscl with create /Groups/group PrimaryGroupID gid" do
allow(@provider).to receive(:get_free_gid).and_return(50)
- expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj PrimaryGroupID 50").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with(*"list /Groups gid".split(" "))
+ expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "PrimaryGroupID", 50).and_return(true)
@provider.set_gid
end
end
@@ -193,8 +193,8 @@ describe Chef::Provider::Group::Dscl do
end
it "should run safe_dscl with create /Groups/group GroupMembership to clear the Group's UID list" do
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "GroupMembers", "").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "GroupMembership", "").and_return(true)
@provider.set_members
end
end
@@ -211,9 +211,9 @@ describe Chef::Provider::Group::Dscl do
end
it "should run safe_dscl with append /Groups/group GroupMembership and group members all, your, base" do
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
- expect(@provider).to receive(:safe_dscl).with("append /Groups/aj GroupMembership all your base").and_return(true)
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "GroupMembers", "").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with(*"append /Groups/aj GroupMembership all your base".split(" ")).and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create", "/Groups/aj", "GroupMembership", "").and_return(true)
@provider.set_members
end
end
@@ -254,8 +254,8 @@ describe Chef::Provider::Group::Dscl do
it "creates the group, password field, gid, and sets group membership" do
expect(@provider).to receive(:set_gid).and_return(true)
expect(@provider).to receive(:set_members).and_return(true)
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj Password '*'")
- expect(@provider).to receive(:safe_dscl).with("create /Groups/aj")
+ expect(@provider).to receive(:safe_dscl).with(*"create /Groups/aj Password *".split(" "))
+ expect(@provider).to receive(:safe_dscl).with(*"create /Groups/aj".split(" "))
@provider.create_group
end
end
@@ -265,8 +265,8 @@ describe Chef::Provider::Group::Dscl do
@current_resource.group_name("oldval")
@new_resource.group_name("newname")
expect(@provider).to receive(:set_members).and_return(true)
- expect(@provider).to receive(:safe_dscl).with("create /Groups/newname")
- expect(@provider).to receive(:safe_dscl).with("create /Groups/newname Password '*'")
+ expect(@provider).to receive(:safe_dscl).with(*"create /Groups/newname".split(" "))
+ expect(@provider).to receive(:safe_dscl).with(*"create /Groups/newname Password *".split(" "))
@provider.manage_group
end
@@ -287,7 +287,7 @@ describe Chef::Provider::Group::Dscl do
describe "remove_group" do
it "should run safe_dscl with delete /Groups/group and with the new resources group name" do
- expect(@provider).to receive(:safe_dscl).with("delete /Groups/aj").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with(*"delete /Groups/aj".split(" ")).and_return(true)
@provider.remove_group
end
end
@@ -315,7 +315,7 @@ RecordName: com.apple.aj
RecordType: dsRecTypeStandard:Groups
GroupMembership: waka bar
EOF
- allow(@provider).to receive(:safe_dscl).with("read /Groups/aj").and_return(@output)
+ allow(@provider).to receive(:safe_dscl).with(*"read /Groups/aj".split(" ")).and_return(@output)
@current_resource = @provider.load_current_resource
end