Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-1459) Add support for root_home on OS X 10.9 #215

Merged
merged 1 commit into from
Jan 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/facter/root_home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ def get_root_home
Facter.add(:root_home) do
setcode { Facter::Util::RootHome.get_root_home }
end

Facter.add(:root_home) do
confine :kernel => :darwin
setcode do
str = Facter::Util::Resolution.exec("dscacheutil -q user -a name root")
hash = {}
str.split("\n").each do |pair|
key,value = pair.split(/:/)
hash[key] = value
end
hash['dir'].strip
end
end
8 changes: 8 additions & 0 deletions spec/fixtures/dscacheutil/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: root
password: *
uid: 0
gid: 0
dir: /var/root
shell: /bin/bash
gecos: rawr Root

29 changes: 20 additions & 9 deletions spec/unit/facter/root_home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
Facter::Util::RootHome.get_root_home.should == expected_root_home
end
end
context "macosx" do
let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
let(:expected_root_home) { "/var/root" }

it "should return /var/root" do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
Facter::Util::RootHome.get_root_home.should == expected_root_home
end
end
context "windows" do
before :each do
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
Expand All @@ -38,3 +29,23 @@
end
end
end

describe 'root_home', :type => :fact do
before { Facter.clear }
after { Facter.clear }

context "macosx" do
before do
Facter.fact(:kernel).stubs(:value).returns("Darwin")
Facter.fact(:osfamily).stubs(:value).returns("Darwin")
end
let(:expected_root_home) { "/var/root" }
sample_dscacheutil = File.read(fixtures('dscacheutil','root'))

it "should return /var/root" do
Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
Facter.fact(:root_home).value.should == expected_root_home
end
end

end