|
9 | 9 | Facter.clear |
10 | 10 | end |
11 | 11 |
|
12 | | - it "should return true if SELinux enabled" do |
13 | | - Facter.fact(:kernel).stubs(:value).returns("Linux") |
| 12 | + describe "should detect if SELinux is enabled" do |
| 13 | + it "and return true with default /selinux" do |
| 14 | + Facter.fact(:kernel).stubs(:value).returns("Linux") |
14 | 15 |
|
15 | | - FileTest.stubs(:exists?).returns false |
16 | | - File.stubs(:read).with("/proc/self/attr/current").returns("notkernel") |
| 16 | + FileTest.stubs(:exists?).returns false |
| 17 | + File.stubs(:read).with("/proc/self/attr/current").returns("notkernel") |
17 | 18 |
|
18 | | - FileTest.expects(:exists?).with("/selinux/enforce").returns true |
19 | | - FileTest.expects(:exists?).with("/proc/self/attr/current").returns true |
20 | | - File.expects(:read).with("/proc/self/attr/current").returns("kernel") |
| 19 | + FileTest.expects(:exists?).with("/selinux/enforce").returns true |
| 20 | + FileTest.expects(:exists?).with("/proc/self/attr/current").returns true |
| 21 | + File.expects(:read).with("/proc/self/attr/current").returns("kernel") |
| 22 | + |
| 23 | + Facter.fact(:selinux).value.should == "true" |
| 24 | + end |
| 25 | + |
| 26 | + it "and return true with selinuxfs path from /proc" do |
| 27 | + Facter.fact(:kernel).stubs(:value).returns("Linux") |
| 28 | + |
| 29 | + mounts = mock() |
| 30 | + lines = [ "selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0" ] |
| 31 | + mounts.expects(:grep).multiple_yields(*lines) |
| 32 | + |
| 33 | + FileTest.expects(:exists?).with("/proc/self/mounts").returns true |
| 34 | + File.expects(:open).with("/proc/self/mounts").yields(mounts) |
| 35 | + |
| 36 | + FileTest.expects(:exists?).with("/sys/fs/selinux/enforce").returns true |
| 37 | + |
| 38 | + FileTest.expects(:exists?).with("/proc/self/attr/current").returns true |
| 39 | + File.expects(:read).with("/proc/self/attr/current").returns("kernel") |
| 40 | + |
| 41 | + Facter.fact(:selinux).value.should == "true" |
| 42 | + end |
| 43 | + |
| 44 | + it "and return true with multiple selinuxfs mounts from /proc" do |
| 45 | + Facter.fact(:kernel).stubs(:value).returns("Linux") |
| 46 | + |
| 47 | + mounts = mock() |
| 48 | + lines = [ |
| 49 | + "selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0", |
| 50 | + "selinuxfs /var/tmp/imgcreate-R2wmE6/install_root/sys/fs/selinux selinuxfs rw,relatime 0 0", |
| 51 | + ] |
| 52 | + mounts.expects(:grep).multiple_yields(*lines) |
| 53 | + |
| 54 | + FileTest.expects(:exists?).with("/proc/self/mounts").returns true |
| 55 | + File.expects(:open).with("/proc/self/mounts").yields(mounts) |
| 56 | + |
| 57 | + FileTest.expects(:exists?).with("/sys/fs/selinux/enforce").returns true |
| 58 | + |
| 59 | + FileTest.expects(:exists?).with("/proc/self/attr/current").returns true |
| 60 | + File.expects(:read).with("/proc/self/attr/current").returns("kernel") |
21 | 61 |
|
22 | | - Facter.fact(:selinux).value.should == "true" |
| 62 | + Facter.fact(:selinux).value.should == "true" |
| 63 | + end |
23 | 64 | end |
24 | 65 |
|
25 | 66 | it "should return true if SELinux policy enabled" do |
|
36 | 77 |
|
37 | 78 | it "should return an SELinux policy version" do |
38 | 79 | Facter.fact(:selinux).stubs(:value).returns("true") |
39 | | - FileTest.stubs(:exists?).with("/proc/self/mountinfo").returns false |
| 80 | + FileTest.stubs(:exists?).with("/proc/self/mounts").returns false |
40 | 81 |
|
41 | 82 | File.stubs(:read).with("/selinux/policyvers").returns("") |
42 | 83 |
|
|
0 commit comments