diff options
author | Markus Roberts <Markus@reality.com> | 2009-12-18 09:11:09 -0800 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2009-12-18 09:11:09 -0800 |
commit | d11c7503cc816e98b5deb890b49a7e8c47173e1b (patch) | |
tree | 5fb76ea4708a7758d744b71b022dc32eca895238 | |
parent | 0dc2dbafe65b59bfbb3ab66e26f595260bdde356 (diff) | |
download | puppet-d11c7503cc816e98b5deb890b49a7e8c47173e1b.tar.gz puppet-d11c7503cc816e98b5deb890b49a7e8c47173e1b.tar.xz puppet-d11c7503cc816e98b5deb890b49a7e8c47173e1b.zip |
Fix for #2951 (SELinux test errors on OS X)
This makes the SELinux library marginally more robust by dealing
consistently with a missing proc/mounts, and also resoves the test
failures in a way that allows meaningful test runs on non-SELinux
systems.
Signed-off-by: Markus Roberts <Markus@reality.com>
-rw-r--r-- | lib/puppet/util/selinux.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/selinux.rb | 21 |
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 331c8eb82..628a6ec23 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -166,8 +166,8 @@ module Puppet::Util::SELinux # that's expected rescue return nil - ensure - mountfh.close + ensure + mountfh.close if mountfh end mntpoint = {} diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb index 7e6cdaf30..88f4ac809 100755 --- a/spec/unit/util/selinux.rb +++ b/spec/unit/util/selinux.rb @@ -27,7 +27,12 @@ describe Puppet::Util::SELinux do Selinux.expects(:is_selinux_enabled).returns 0 selinux_support?.should be_false end - end + + it "should return nil if /proc/mounts does not exist" do + File.stubs(:open).with("/proc/mounts").raises("No such file or directory - /proc/mounts") + read_mounts.should == nil + end + end describe "filesystem detection" do before :each do @@ -189,7 +194,19 @@ describe Puppet::Util::SELinux do end describe "set_selinux_context" do - it "should return nil if there is no SELinux support" do + before :each do + fh = stub 'fh', :close => nil + File.stubs(:open).with("/proc/mounts").returns fh + fh.stubs(:read_nonblock).returns( + "rootfs / rootfs rw 0 0\n"+ + "/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n"+ + "/dev /dev tmpfs rw,relatime,mode=755 0 0\n"+ + "/proc /proc proc rw,relatime 0 0\n"+ + "/sys /sys sysfs rw,relatime 0 0\n" + ).then.raises EOFError + end + + it "should return nil if there is no SELinux support" do self.expects(:selinux_support?).returns false set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil end |