do not ignore used loop devices (size > 0)

fixed tests.cryptobox.py
This commit is contained in:
lars 2007-09-12 22:35:23 +00:00
parent 9c649312d0
commit a695d37b8c
2 changed files with 6 additions and 4 deletions

View file

@ -166,7 +166,7 @@ class Blockdevice:
if major == MAJOR_DEVNUM_RAM:
return False
## loop devices are ignored
if major == MAJOR_DEVNUM_LOOP:
if (major == MAJOR_DEVNUM_LOOP) and (self.size == 0):
return False
## removable devices are ignored (due to long timeouts)
if self.is_removable():
@ -774,6 +774,8 @@ def get_blockdevice(dev,
## it is an absolute path
if dev.startswith(devnode_dir):
## it is the name of a devicenode (e.g.: '/dev/hda1')
## simplify the path first
dev = os.path.realpath(dev)
found_dev = [ a_dev for a_dev in Blockdevices(
sysblock_dir, devnode_dir).get_devices()
if dev in a_dev.devnodes ]

View file

@ -42,13 +42,13 @@ class CryptoBoxDeviceTests(CommonTestClass):
def test_allowed_devices(self):
'''is_device_allowed should accept permitted devices'''
self.assertTrue(self.cb.is_device_allowed("/dev/loop1"))
self.assertTrue(self.cb.is_device_allowed("/dev/usb/../loop1"))
self.assertTrue(self.cb.is_device_allowed("/dev/pts/../loop1"))
def test_denied_devices(self):
'''is_device_allowed should fail with not explicitly allowed devices'''
self.assertFalse(self.cb.is_device_allowed("/dev/hda"))
self.assertFalse(self.cb.is_device_allowed("/dev/loopa/../hda"))
self.assertFalse(self.cb.is_device_allowed("/dev/hdc"))
self.assertFalse(self.cb.is_device_allowed("/dev/loopa/../hdc"))
self.assertFalse(self.cb.is_device_allowed("/"))
## this device does not exist -> no permission check possible
self.assertFalse(self.cb.is_device_allowed("/dev/loop"))