Changes to use unit tests in non-User Mode Linux environment; merged cryptobox.conf into

cryptobox-unittests.conf
This commit is contained in:
frisco 2009-05-11 10:02:49 +00:00
parent f2d88519b0
commit 615073e02c
9 changed files with 61 additions and 129 deletions

View file

@ -84,5 +84,17 @@ umount = /bin/umount
nice = /usr/bin/nice
super = /usr/bin/super
# this is the "program" name as defined in /etc/super.tab
# "CryptoBoxRootActionsLocal" (in /etc/super.tab) should point to the
# CryptoBoxRootActions.py file in your local working directory. This avoids
# conflicts with a locally (apt-)installed CryptoBoxRootActions.py file
CryptoBoxRootActions = CryptoBoxRootActionsLocal
[PluginSettings]
# plugin specific settings
# the section names _must_ be the same as the names of the plugins
## change the default network interface for the plugin "network"
#[[network]]
#interface = eth0

View file

@ -1,102 +0,0 @@
[Main]
# comma separated list of possible prefixes for accesible devices
# beware: .e.g "/dev/hd" grants access to _all_ harddisks
# (floppy disks are not supported, does anyone still use them?)
AllowedDevices = /dev/ram, /dev/ubdb, /dev/md_d127
# use separate config partition? (1=yes / 0=no)
UseConfigPartition = 1
# the default name prefix of not unnamed containers
DefaultVolumePrefix = "Disk "
# which cipher should cryptsetup-luks use?
#TODO: uml does not support this module - DefaultCipher = aes-cbc-essiv:sha256
DefaultCipher = aes-plain
# label of the configuration partition (you should never change this)
ConfigVolumeLabel = cbox_config
# which plugins should be disabled? (comma seperated list)
#DisabledPlugins = network, shutdown, partition
[Locations]
# where should we mount volumes?
# this directory must be writeable by the cryptobox user (see above)
#MountParentDir = /var/cache/cryptobox/mnt
MountParentDir = ../ttt/mnt
# settings directory: contains name database and plugin configuration
#SettingsDir = /var/cache/cryptobox/settings
SettingsDir = ../ttt/settings
# where are the clearsilver templates?
#TemplateDir = /usr/share/cryptobox/templates
TemplateDir = ../templates
# path to documentation files
#DocDir = /usr/share/doc/cryptobox/www-data
DocDir = ../doc/html
# plugin directories - you may specify more than one directory (comma seperated)
#PluginDir = /usr/share/cryptobox/plugins
PluginDir = ../plugins
# path to the hook directory (e.g. containing some scripts)
#HookDir = /etc/cryptobox/hooks.d
EventDir = ../event-scripts
[Log]
# possible values are "debug", "info", "warn" and "error" or numbers from
# 0 (debug) to 7 (error)
Level = debug
# where to write the log messages to?
# possible values are: file
# syslog support will be added later
Destination = file
# depending on the choosen destination (see above) you may select
# details. Possible values for the different destinations are:
# file: $FILENAME
# syslog: $LOG_FACILITY
#Details = /var/log/cryptobox.log
Details = ./cryptobox.log
#Details = SYSLOG
[WebSettings]
# URL of default stylesheet
Stylesheet = cryptobox-misc/cryptobox.css
# default language
Languages = en, de, sl, fr
[Programs]
cryptsetup = /sbin/cryptsetup
mkfs = /sbin/mkfs
blkid = /sbin/blkid
blockdev = /sbin/blockdev
mount = /bin/mount
umount = /bin/umount
nice = /usr/bin/nice
super = /usr/bin/super
# this is the "program" name as defined in /etc/super.tab
# "CryptoBoxRootActionsLocal" (in /etc/super.tab) should point to the
# CryptoBoxRootActions.py file in your local working directory - this avoids
# conflicts with a locally (apt-)installed CryptoBoxRootActions.py file
CryptoBoxRootActions = CryptoBoxRootActionsLocal
[PluginSettings]
# plugin specific settings
# the section names _must_ be the same as the names of the plugins
## change the default network interface for the plugin "network"
#[[network]]
#interface = eth0

View file

@ -1,4 +1,5 @@
#!/bin/sh
#
# run this script _before_ you do a commit and fix errors before uploading
#
@ -8,6 +9,7 @@
# CryptoBoxRootActionsLocal ./CryptoBoxRootActions cryptobox
#
GETOPT="getopt"
BASE_DIR=$(cd "$(dirname $0)/.."; pwd)
export PYTHONPATH=$BASE_DIR/src
@ -22,17 +24,29 @@ enable_filecheck()
sed -i "s/^OVERRIDE_FILECHECK = .*$/OVERRIDE_FILECHECK = False/" "$BASE_DIR/bin/CryptoBoxRootActions"
}
# check if /dev/loop1 is available - otherwise some tests will fail!
if /sbin/losetup /dev/loop1 &>/dev/null || test -e /dev/ubdb
then true
else echo "misconfiguration detected: sorry - you need /dev/loop1 for the tests" >&2
echo "just do the following:" >&2
echo " dd if=/dev/zero of=test.img bs=1M count=1 seek=100" >&2
echo " sudo /sbin/losetup /dev/loop1 test.img" >&2
echo "then you can run the tests again ..." >&2
echo >&2
exit 1
fi
#Using getopt(1) would be the super-thorough way to do this; use the
#quick-and-dirty method instead
# case $1 in
# --clobber=*)
# TEST_DISK=`echo $1 | sed 's/[-a-zA-Z0-9]*=//'`
# ;;
# *)
# ;;
#
#esac
#parse out the remaining command line arguments
## now check that TEST_DISK is not empty and is a block device (more flexibility could possibly be added)
####################################################################3
##Attention!!! Don't check this in with the following variable set!
##
## the "/dev/" prefix is already assumed by the test classes
#CNAS_UTEST_CLOBBER="sdb"
CNAS_UTEST_CLOBBER=""
export CNAS_UTEST_CLOBBER
dest_files=""
while test $# -gt 0

View file

@ -33,7 +33,7 @@ export PYTHONPATH="$BIN_DIR/../src"
#export HTTPS=1
PREFERRED_CONF_FILE=$BIN_DIR/cryptobox-local.conf
FALLBACK_CONF_FILE=$BIN_DIR/cryptobox.conf
FALLBACK_CONF_FILE=$BIN_DIR/cryptobox-unittests.conf
## determine the configuration file
CONFIG_FILE=$FALLBACK_CONF_FILE

View file

@ -1,4 +1,9 @@
#!/bin/sh
#uml-setup.sh
#
#This file does some setup required for running the unit tests under
#User Mode Linux (UML). If you are using a different test setup, it
#does not apply.
PROJ_DIR=$(dirname "$0")/..
PROJ_DIR=$(cd "$PROJ_DIR"; pwd)

View file

@ -30,3 +30,6 @@ class unittests(WebInterfaceTestClass):
self.cmd.go(url)
self.cmd.find('VERY careful')
#TODO: add tests for case where we're creating a config
# partition followed by two "data" partitions. All the
# partitions need to be created.

View file

@ -69,13 +69,14 @@ class CommonTestClass(unittest.TestCase):
## search for a usable block device
## use /dev/ubd? if possible - otherwise /dev/hd?
## so it will be possible to use these tests inside of a uml
self.blockdevice = testtools.find_test_device()
self.DRIVE_TO_CLOBBER = os.environ.get("CNAS_UTEST_CLOBBER")
self.blockdevice = testtools.find_test_device(self.DRIVE_TO_CLOBBER)
## umount the partitions of this device (just to be sure)
for num in range(12):
testtools.umount("%s%d" % (self.blockdevice, num))
## format device and partition block device if necessary
testtools.prepare_partition(self.blockdevice)
self.blockdevice = testtools.find_test_device()
self.blockdevice = testtools.find_test_device(self.DRIVE_TO_CLOBBER)
self.device = self.blockdevice + "1"
self.blockdevice_html = self.blockdevice.replace("/", "%2F")
## the assumption is not always valid - but usually it is ok

View file

@ -45,7 +45,7 @@ class CryptoBoxDeviceTests(CommonTestClass):
'''is_device_allowed should accept permitted devices'''
# check if one of the common devices exists and is allowed
blockdevice_found = False
for dev_node in COMMON_ALLOWED_DEVICES:
for dev_node in (COMMON_ALLOWED_DEVICES + [ self.blockdevice ]):
if os.path.exists(dev_node):
self.assertTrue(self.cb.is_device_allowed(dev_node))
blockdevice_found = True

View file

@ -26,27 +26,26 @@ just inherit one of its classes and add some test functions
__revision__ = "$Id$"
TEST_DEVICE_LIST = ["ubdb", "loop", "ubda", "udbc", "ubdd", "sd"]
import os
import subprocess
def find_test_device():
"""Search for a valid test device - the data will get lost ...
def find_test_device(candidate):
"""Check for a valid test device - the data will get lost ...
the result is the parent blockdevice (containing the partition table)
and the single partition
"""
for dev in TEST_DEVICE_LIST:
if os.path.exists("/dev/%s" % dev) \
and os.access("/dev/%s" % dev, os.W_OK):
try:
## try if it is a symlink
return os.readlink("/dev/%s" % dev)
except OSError:
## not a symlink (usual)
return "/dev/%s" % dev
dev = candidate
if os.path.exists("/dev/%s" % dev) \
and os.access("/dev/%s" % dev, os.W_OK):
try:
## try if it is a symlink
return os.readlink("/dev/%s" % dev)
except OSError:
## not a symlink (usual)
return "/dev/%s" % dev
else:
raise Exception, "no valid device for testing found"