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

Fix be_mode, be_executable, be_owned_by and be_grouped_into matcher on Darwin (OS X) #103

Merged
merged 2 commits into from May 14, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/serverspec/commands/darwin.rb
Expand Up @@ -9,6 +9,25 @@ def check_file_md5checksum file, expected
"openssl md5 #{escape(file)} | cut -d'=' -f2 | cut -c 2- | grep -E ^#{escape(expected)}$"
end

def check_mode file, mode
regexp = "^#{mode}$"
"stat -f %A #{escape(file)} | grep -- #{escape(regexp)}"
end

def check_owner file, owner
regexp = "^#{owner}$"
"stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}"
end

def check_grouped file, group
regexp = "^#{group}$"
"stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}"
end

def get_mode(file)
"stat -f %A #{escape(file)}"
end

def check_access_by_user file, user, access
"sudo -u #{user} -s /bin/test -#{access} #{file}"
end
Expand Down
9 changes: 4 additions & 5 deletions spec/darwin/commands_spec.rb
Expand Up @@ -110,22 +110,21 @@
describe 'check_file_md5checksum', :os => :darwin do
subject { commands.check_file_md5checksum('/usr/bin/rsync', '03ba2dcdd50ec3a7a45d3900902a83ce') }
it { should eq "openssl md5 /usr/bin/rsync | cut -d'=' -f2 | cut -c 2- | grep -E ^03ba2dcdd50ec3a7a45d3900902a83ce$" }
it { should_not eq "openssl md5 /usr/bin/rsync | cut -d'=' -f2 | cut -c 2- | grep -E ^03ba2dcdd50ec3a7a45d3900902a83c" }
end

describe 'check_mode', :os => :darwin do
subject { commands.check_mode('/etc/sudoers', 440) }
it { should eq 'stat -c %a /etc/sudoers | grep -- \\^440\\$' }
it { should eq 'stat -f %A /etc/sudoers | grep -- \\^440\\$' }
end

describe 'check_owner', :os => :darwin do
subject { commands.check_owner('/etc/passwd', 'root') }
it { should eq 'stat -c %U /etc/passwd | grep -- \\^root\\$' }
it { should eq 'stat -f %Su /etc/passwd | grep -- \\^root\\$' }
end

describe 'check_grouped', :os => :darwin do
subject { commands.check_grouped('/etc/passwd', 'wheel') }
it { should eq 'stat -c %G /etc/passwd | grep -- \\^wheel\\$' }
it { should eq 'stat -f %Sg /etc/passwd | grep -- \\^wheel\\$' }
end

describe 'check_cron_entry', :os => :darwin do
Expand Down Expand Up @@ -188,7 +187,7 @@

describe 'get_mode', :os => :darwin do
subject { commands.get_mode('/dev') }
it { should eq 'stat -c %a /dev' }
it { should eq 'stat -f %A /dev' }
end

describe 'check_access_by_user', :os => :darwin do
Expand Down