示例#1
0
    def testLabels(self):
        """Initialize some filesystems with valid and invalid labels."""

        # Ext2FS has a maximum length of 16
        self.assertFalse(fs.Ext2FS().labelFormatOK("root___filesystem"))
        self.assertTrue(fs.Ext2FS().labelFormatOK("root__filesystem"))

        # FATFS has a maximum length of 11
        self.assertFalse(fs.FATFS().labelFormatOK("rtfilesystem"))
        self.assertTrue(fs.FATFS().labelFormatOK("rfilesystem"))

        # JFS has a maximum length of 16
        self.assertFalse(fs.JFS().labelFormatOK("root___filesystem"))
        self.assertTrue(fs.JFS().labelFormatOK("root__filesystem"))

        # ReiserFS has a maximum length of 16
        self.assertFalse(fs.ReiserFS().labelFormatOK("root___filesystem"))
        self.assertTrue(fs.ReiserFS().labelFormatOK("root__filesystem"))

        #XFS has a maximum length 12 and does not allow spaces
        self.assertFalse(fs.XFS().labelFormatOK("root_filesyst"))
        self.assertFalse(fs.XFS().labelFormatOK("root file"))
        self.assertTrue(fs.XFS().labelFormatOK("root_filesys"))

        #HFS has a maximum length of 27, minimum length of 1, and does not allow colons
        self.assertFalse(fs.HFS().labelFormatOK("n" * 28))
        self.assertFalse(fs.HFS().labelFormatOK("root:file"))
        self.assertFalse(fs.HFS().labelFormatOK(""))
        self.assertTrue(fs.HFS().labelFormatOK("n" * 27))

        #HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
        self.assertFalse(fs.HFSPlus().labelFormatOK("n" * 129))
        self.assertFalse(fs.HFSPlus().labelFormatOK("root:file"))
        self.assertFalse(fs.HFSPlus().labelFormatOK(""))
        self.assertTrue(fs.HFSPlus().labelFormatOK("n" * 128))

        # NTFS has a maximum length of 128
        self.assertFalse(fs.NTFS().labelFormatOK("n" * 129))
        self.assertTrue(fs.NTFS().labelFormatOK("n" * 128))

        # all devices are permitted to be passed a label argument of None
        # some will ignore it completely
        for _k, v  in device_formats.items():
            self.assertIsNotNone(v(label=None))
示例#2
0
    def testMountingExt2FS(self):
        _LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]

        an_fs = fs.Ext2FS(device=_LOOP_DEV0, label="test")
        self.assertIsNone(an_fs.create())

        blivet.flags.installer_mode = False
        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))

        lost_and_found_selinux_context = selinux.getfilecon(lost_and_found)

        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:file_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.assertTrue(os.path.exists(lost_and_found))

        lost_and_found_selinux_context = selinux.getfilecon(lost_and_found)

        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')
示例#3
0
    def test_mounting_ext2fs(self):
        """ Test that lost+found directory gets assigned correct SELinux
            context if selinux_set_fcon is True, and retains some random old
            context if selinux_set_fcon is False.
        """
        LOST_AND_FOUND_CONTEXT = 'system_u:object_r:lost_found_t:s0'
        an_fs = fs.Ext2FS(device=self.loop_devices[0], label="test")

        if not an_fs.formattable or not an_fs.mountable:
            self.skipTest("can not create or mount filesystem %s" % an_fs.name)

        self.assertIsNone(an_fs.create())

        blivet.flags.selinux_reset_fcon = False
        mountpoint = tempfile.mkdtemp("test.selinux")
        an_fs.mount(mountpoint=mountpoint)

        lost_and_found = os.path.join(mountpoint, "lost+found")
        self.assertTrue(os.path.exists(lost_and_found))

        lost_and_found_selinux_context = selinux.getfilecon(lost_and_found)

        an_fs.unmount()
        os.rmdir(mountpoint)

        self.assertNotEqual(lost_and_found_selinux_context[1], LOST_AND_FOUND_CONTEXT)

        blivet.flags.selinux_reset_fcon = True
        mountpoint = tempfile.mkdtemp("test.selinux")
        an_fs.mount(mountpoint=mountpoint)

        lost_and_found = os.path.join(mountpoint, "lost+found")
        self.assertTrue(os.path.exists(lost_and_found))

        lost_and_found_selinux_context = selinux.getfilecon(lost_and_found)

        an_fs.unmount()
        os.rmdir(mountpoint)

        self.assertEqual(lost_and_found_selinux_context[1], LOST_AND_FOUND_CONTEXT)