cryptonas-branches/pythonrewrite/bin2/unittests.CryptoBox.py
lars 84028f4a92 added python version checks
added startup test to CryptoBox
integrate CryptoBoxRootActions into CryptoBox (see example-super.tab for details)
implemented "mount" and "umount" in CryptoBoxRootActions
adapted CryptoBoxRootActions checks to 'super'
2006-08-23 13:27:25 +00:00

80 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python2.4
import unittest
class CryptoBoxPropsDeviceTests(unittest.TestCase):
import CryptoBox
cb = CryptoBox.CryptoBoxProps()
def testAllowedDevices(self):
'''isDeviceAllowed should accept permitted devices'''
self.assertTrue(self.cb.isDeviceAllowed("/dev/loop"))
self.assertTrue(self.cb.isDeviceAllowed("/dev/loop1"))
self.assertTrue(self.cb.isDeviceAllowed("/dev/loop/urgd"))
self.assertTrue(self.cb.isDeviceAllowed("/dev/usb/../loop1"))
def testDeniedDevices(self):
'''isDeviceAllowed should fail with not explecitly allowed devices'''
self.assertFalse(self.cb.isDeviceAllowed("/dev/hda"))
self.assertFalse(self.cb.isDeviceAllowed("/dev/loopa/../hda"))
self.assertFalse(self.cb.isDeviceAllowed("/"))
class CryptoBoxPropsConfigTests(unittest.TestCase):
'''test here if everything with the config turns right'''
import filehandling
import os
import CryptoBox
files = { "configFile" : "cbox-test.conf",
"nameDBFile" : "cryptobox_names.db",
"logFile" : "cryptobox.log",
"tmpdir" : "cryptobox-mnt" }
tmpdirname = ""
filenames = {}
configContent = """
[Main]
AllowedDevices = /dev/loop
DefaultVolumePrefix = "Data "
DataDir = /tmp
NameDatabase = cryptobox_names.db
[System]
User = 1000
Group = 1000
MountParentDir = /tmp/mnt
DefaultCipher = aes-cbc-essiv:sha256
[Log]
Level = debug
Facility = file
Destination = /tmp/cryptobox.log
[Programs]
blkid = /sbin/blkid
cryptsetup = /sbin/cryptsetup
"""
def setUp(self):
'''generate all files in tmp and remember the names'''
os = self.os
self.tmpdirname = self.filehandling.gen_temp_dir(self.files["tmpdir"])
os.chdir(self.tmpdirname)
for file in self.files.keys():
#TODO: files are not really created in tmpdirname
self.filenames[file] = self.filehandling.gen_temp_file(self.files[file])
def tearDown(self):
'''remove the created tmpfiles'''
os = self.os
os.chdir(self.tmpdirname)
for file in self.filenames.values():
if os.path.exists(file):
#os.remove(file)
pass
def testConfigFile(self):
'''testConfigFile TODO'''
self.assertTrue(1)
if __name__ == "__main__":
unittest.main()