2006-11-06 17:05:00 +01:00
|
|
|
#!/usr/bin/env python2.4
|
2006-11-30 15:50:28 +01:00
|
|
|
#
|
|
|
|
# Copyright 2006 sense.lab e.V.
|
|
|
|
#
|
|
|
|
# This file is part of the CryptoBox.
|
|
|
|
#
|
|
|
|
# The CryptoBox is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# The CryptoBox is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with the CryptoBox; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
import unittest
|
2006-11-27 20:25:26 +01:00
|
|
|
import cryptobox.core.tools as cbxTools
|
2006-11-06 17:05:00 +01:00
|
|
|
import os
|
|
|
|
|
2006-11-30 15:50:28 +01:00
|
|
|
## use /dev/ubd? if possible - otherwise /dev/hd?
|
|
|
|
## so it will be possible to use these tests inside of an uml
|
|
|
|
for d in ["ubdb", "ubda", "udbc", "ubdd", "hdb", "hda", "hdc", "hdd"]:
|
|
|
|
if os.path.exists("/dev/%s1" % d):
|
|
|
|
device = d
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
device = "hda"
|
|
|
|
|
|
|
|
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
class CryptoBoxToolsTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def testGetAbsoluteDeviceName(self):
|
2006-11-27 20:25:26 +01:00
|
|
|
func = cbxTools.getAbsoluteDeviceName
|
2006-11-30 15:50:28 +01:00
|
|
|
self.assertTrue(func(device) == "/dev/%s" % device)
|
2006-11-06 17:05:00 +01:00
|
|
|
self.assertTrue(func("loop0") == "/dev/loop0")
|
|
|
|
self.assertTrue(func(os.path.devnull) == os.path.devnull)
|
|
|
|
|
|
|
|
|
|
|
|
def testFindMajorMinorOfDevice(self):
|
2006-11-27 20:25:26 +01:00
|
|
|
func = cbxTools.findMajorMinorOfDevice
|
2006-11-06 17:05:00 +01:00
|
|
|
self.assertTrue(func(os.path.devnull) == (1,3))
|
|
|
|
self.assertTrue(func("/dev/nothere") is None)
|
|
|
|
|
|
|
|
|
|
|
|
def testFindMajorMinorDeviceName(self):
|
2006-11-27 20:25:26 +01:00
|
|
|
func = cbxTools.findMajorMinorDeviceName
|
2006-11-06 17:05:00 +01:00
|
|
|
dir = os.path.join(os.path.sep, "dev")
|
|
|
|
self.assertTrue(os.path.devnull in func(dir,1,3))
|
|
|
|
self.assertFalse(os.path.devnull in func(dir,2,3))
|
2006-11-30 15:50:28 +01:00
|
|
|
self.assertFalse(None in func(dir,17,23))
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
def testIsPartOfBlockDevice(self):
|
2006-11-27 20:25:26 +01:00
|
|
|
func = cbxTools.isPartOfBlockDevice
|
2006-11-30 15:50:28 +01:00
|
|
|
self.assertTrue(func("/dev/%s" % device, "/dev/%s1" % device))
|
|
|
|
self.assertFalse(func("/dev/%s" % device, "/dev/%s" % device))
|
|
|
|
self.assertFalse(func("/dev/%s1" % device, "/dev/%s" % device))
|
|
|
|
self.assertFalse(func("/dev/%s1" % device, "/dev/%s1" % device))
|
|
|
|
self.assertFalse(func("/dev/%s" % device, "/dev/hde1"))
|
|
|
|
self.assertFalse(func(None, "/dev/%s1" % device))
|
|
|
|
self.assertFalse(func("/dev/%s" % device, None))
|
2006-11-06 17:05:00 +01:00
|
|
|
self.assertFalse(func(None, ""))
|
|
|
|
self.assertFalse(func("loop0", "loop1"))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|
|
|
|
|