From fa33c10522b7ad8719e275e6f0be981c7ada348e Mon Sep 17 00:00:00 2001 From: Phil Dibowitz Date: Mon, 4 Aug 2014 11:45:40 -0700 Subject: Fix OSX Group provider to be properly idempotent Currently the OSX Group provider use the 'Etc' module to determine what exists, and the 'dscl' command to change things. Etc will look to /etc/group by default and fallback to 'dscl', which causes idempotency incorrectness. This change the Group provider to simply look at 'dscl' always. --- spec/unit/provider/group/dscl_spec.rb | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'spec/unit/provider/group') diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index 5a02ee8dfb..8848a01bf2 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -240,6 +240,7 @@ describe Chef::Provider::Group::Dscl do @provider.load_current_resource @provider.define_resource_requirements end + it "raises an error if the required binary /usr/bin/dscl doesn't exist" do File.should_receive(:exists?).with("/usr/bin/dscl").and_return(false) @@ -251,7 +252,7 @@ describe Chef::Provider::Group::Dscl do lambda { @provider.process_resource_requirements }.should_not raise_error end end - + describe "when creating the group" do it "creates the group, password field, gid, and sets group membership" do @provider.should_receive(:set_gid).and_return(true) @@ -294,3 +295,39 @@ describe Chef::Provider::Group::Dscl do end end end + +describe 'Test DSCL loading' do + before do + @node = Chef::Node.new + @events = Chef::EventDispatch::Dispatcher.new + @run_context = Chef::RunContext.new(@node, {}, @events) + @new_resource = Chef::Resource::Group.new("aj") + @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) + @output = <<-EOF +AppleMetaNodeLocation: /Local/Default +Comment: + Test Group +GeneratedUID: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA +NestedGroups: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAB +Password: * +PrimaryGroupID: 999 +RealName: + TestGroup +RecordName: com.apple.aj +RecordType: dsRecTypeStandard:Groups +GroupMembership: waka bar +EOF + @provider.stub(:safe_dscl).with("read /Groups/aj").and_return(@output) + @current_resource = @provider.load_current_resource + + end + + it 'should parse gid properly' do + File.stub(:exists?).and_return(true) + @current_resource.gid.should eq("999") + end + it 'should parse members properly' do + File.stub(:exists?).and_return(true) + @current_resource.members.should eq(['waka', 'bar']) + end +end -- cgit v1.2.1