[blivet:master 1/2] Make selinux test less precise.

mulhern amulhern at redhat.com
Thu Nov 13 15:22:22 UTC 2014


Previously they tested the exact value of the root_selinux_context.
However, when mounting and no default context available, the context
would not be set to the default value. So, the actual value of the
context is dependent on selinux's rules for the default context for that
root. It seems to have changed the rules for the default context for
directories in /tmp, now seeming to have no default context for those.

The real purpose of this test it to make sure that the lost+found directory
gets the correct context, when it exists. Those parts of the test are
doing just fine.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 tests/formats_test/selinux_test.py | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/tests/formats_test/selinux_test.py b/tests/formats_test/selinux_test.py
index 83c38d6..0c9d4c1 100755
--- a/tests/formats_test/selinux_test.py
+++ b/tests/formats_test/selinux_test.py
@@ -18,6 +18,11 @@ class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
         super(SELinuxContextTestCase, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB")])
 
     def testMountingExt2FS(self):
+        """ Test that lost+found directory gets assigned correct SELinux
+            context if installer_mode is True, and retains some random old
+            context if installer_mode is False.
+        """
+        LOST_AND_FOUND_CONTEXT = 'system_u:object_r:lost_found_t:s0'
         an_fs = fs.Ext2FS(device=self.loopDevices[0], label="test")
         self.assertIsNone(an_fs.create())
 
@@ -25,8 +30,6 @@ class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
         mountpoint = tempfile.mkdtemp("test.selinux")
         an_fs.mount(mountpoint=mountpoint)
 
-        root_selinux_context = selinux.getfilecon(mountpoint)
-
         lost_and_found = os.path.join(mountpoint, "lost+found")
         self.assertTrue(os.path.exists(lost_and_found))
 
@@ -35,17 +38,12 @@ class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
         an_fs.unmount()
         os.rmdir(mountpoint)
 
-        self.assertEqual(root_selinux_context[1], 'system_u:object_r:unlabeled_t:s0')
-
-        self.assertEqual(lost_and_found_selinux_context[1],
-           'system_u:object_r:unlabeled_t:s0')
+        self.assertNotEqual(lost_and_found_selinux_context[1], LOST_AND_FOUND_CONTEXT)
 
         blivet.flags.installer_mode = True
         mountpoint = tempfile.mkdtemp("test.selinux")
         an_fs.mount(mountpoint=mountpoint)
 
-        root_selinux_context = selinux.getfilecon(mountpoint)
-
         lost_and_found = os.path.join(mountpoint, "lost+found")
         self.assertTrue(os.path.exists(lost_and_found))
 
@@ -54,12 +52,10 @@ class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
         an_fs.unmount()
         os.rmdir(mountpoint)
 
-        self.assertEqual(root_selinux_context[1], 'system_u:object_r:file_t:s0')
-
-        self.assertEqual(lost_and_found_selinux_context[1],
-           'system_u:object_r:lost_found_t:s0')
+        self.assertEqual(lost_and_found_selinux_context[1], LOST_AND_FOUND_CONTEXT)
 
     def testMountingXFS(self):
+        """ XFS does not have a lost+found directory. """
         an_fs = fs.XFS(device=self.loopDevices[0], label="test")
         self.assertIsNone(an_fs.create())
 
@@ -67,29 +63,21 @@ class SELinuxContextTestCase(loopbackedtestcase.LoopBackedTestCase):
         mountpoint = tempfile.mkdtemp("test.selinux")
         an_fs.mount(mountpoint=mountpoint)
 
-        root_selinux_context = selinux.getfilecon(mountpoint)
-
         lost_and_found = os.path.join(mountpoint, "lost+found")
         self.assertFalse(os.path.exists(lost_and_found))
 
         an_fs.unmount()
         os.rmdir(mountpoint)
 
-        self.assertEqual(root_selinux_context[1], 'system_u:object_r:unlabeled_t:s0')
-
         blivet.flags.installer_mode = True
         mountpoint = tempfile.mkdtemp("test.selinux")
         an_fs.mount(mountpoint=mountpoint)
 
-        root_selinux_context = selinux.getfilecon(mountpoint)
-
         lost_and_found = os.path.join(mountpoint, "lost+found")
         self.assertFalse(os.path.exists(lost_and_found))
 
         an_fs.unmount()
         os.rmdir(mountpoint)
 
-        self.assertEqual(root_selinux_context[1], 'system_u:object_r:file_t:s0')
-
 if __name__ == "__main__":
     unittest.main()
-- 
1.9.3



More information about the anaconda-patches mailing list