@ -2,13 +2,12 @@
import unittest
import sys
from CryptoBox import *
from CryptoBoxE xceptions import *
import CryptoBoxS ettings
import cryptobox . core . main
from cryptobox. core . e xceptions import *
import cryptobox. core . s ettings
class CryptoBoxPropsDeviceTests ( unittest . TestCase ) :
import CryptoBox
cb = CryptoBox . CryptoBoxProps ( )
cb = cryptobox . core . main . CryptoBoxProps ( )
def testAllowedDevices ( self ) :
''' isDeviceAllowed should accept permitted devices '''
@ -27,8 +26,6 @@ class CryptoBoxPropsDeviceTests(unittest.TestCase):
class CryptoBoxPropsConfigTests ( unittest . TestCase ) :
''' test here if everything with the config turns right '''
import os
import CryptoBox
files = {
" configFileOK " : " cbox-test_ok.conf " ,
" configFileBroken " : " cbox-test_broken.conf " ,
@ -91,35 +88,35 @@ CryptoBoxRootActions = CryptoBoxRootActions
def testConfigInit ( self ) :
''' Check various branches of config file loading '''
import os
self . assertRaises ( CBConfigUnavailableError , self . CryptoBox . CryptoBoxProps , " /invalid/path/to/config/file " )
self . assertRaises ( CBConfigUnavailableError , self . CryptoBox . CryptoBoxProps , " /etc/shadow " )
self . assertRaises ( CBConfigUnavailableError , cryptobox . core . main . CryptoBoxProps , " /invalid/path/to/config/file " )
self . assertRaises ( CBConfigUnavailableError , cryptobox . core . main . CryptoBoxProps , " /etc/shadow " )
""" check one of the following things:
1 ) are we successfully using an existing config file ?
2 ) do we break , if no config file is there ?
depending on the existence of a config file , only one of these conditions
can be checked - hints for more comprehensive tests are appreciated : ) """
for a in CryptoBoxSettings . CryptoBoxSettings . CONF_LOCATIONS :
for a in [ ' cryptobox.conf ' ] :
if os . path . exists ( a ) :
self . CryptoBox . CryptoBoxProps ( )
cryptobox . core . main . CryptoBoxProps ( )
break # this skips the 'else' clause
else : self . assertRaises ( CBConfigUnavailableError , self . CryptoBox . CryptoBoxProps )
self . assertRaises ( CBConfigUnavailableError , self . CryptoBox . CryptoBoxProps , [ ] )
else : self . assertRaises ( CBConfigUnavailableError , cryptobox . core . main . CryptoBoxProps )
self . assertRaises ( CBConfigUnavailableError , cryptobox . core . main . CryptoBoxProps , [ ] )
def testBrokenConfigs ( self ) :
""" Check various broken configurations """
self . writeConfig ( " SettingsDir " , " SettingsDir=/foo/bar " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . writeConfig ( " Level " , " Level = ho " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . writeConfig ( " Details " , " #out " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . writeConfig ( " super " , " super=/bin/invalid/no " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . writeConfig ( " CryptoBoxRootActions " , " #not here " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBConfigError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . writeConfig ( " CryptoBoxRootActions " , " CryptoBoxRootActions = /bin/false " , filename = self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBEnvironmentError , self . CryptoBox . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
self . assertRaises ( CBEnvironmentError , cryptobox . core . main . CryptoBoxProps , self . filenames [ " configFileBroken " ] )
def writeConfig ( self , replace = None , newline = None , filename = None ) :