test cases fixed

pull/1619/head
sebres 2016-11-22 13:57:06 +01:00
parent 77dc5a334c
commit c6e8c700f7
2 changed files with 18 additions and 13 deletions

View File

@ -127,9 +127,11 @@ class JailReader(ConfigReader):
if self.isEnabled():
# Read filter
if self.__opts["filter"]:
filterName, filterOpt = JailReader.extractOptions(
self.__opts["filter"])
flt = self.__opts["filter"]
if flt:
filterName, filterOpt = JailReader.extractOptions(flt)
if not filterName:
raise ValueError("Invalid filter declaration %r" % flt)
self.__filter = FilterReader(
filterName, self.__name, filterOpt, share_config=self.share_config, basedir=self.getBaseDir())
ret = self.__filter.read()
@ -157,6 +159,8 @@ class JailReader(ConfigReader):
if not act: # skip empty actions
continue
actName, actOpt = JailReader.extractOptions(act)
if not actName:
raise ValueError("Invalid action declaration %r" % act)
if actName.endswith(".py"):
self.__actions.append([
"set",
@ -178,8 +182,8 @@ class JailReader(ConfigReader):
else:
raise AttributeError("Unable to read action")
except Exception as e:
logSys.debug("Caught exception: %s" % (e,))
raise ValueError("Error in action definition %r" % e)
logSys.debug("Caught exception: %s", e, exc_info=True)
raise ValueError("Error in action definition %r: %r" % (act, e))
if not len(self.__actions):
logSys.warning("No actions were defined for %s" % self.__name)

View File

@ -193,13 +193,9 @@ class JailReaderTest(LogCaptureTestCase):
self.assertTrue(jail.read())
self.assertFalse(jail.getOptions())
self.assertTrue(jail.isEnabled())
self.assertLogged('Error in action definition joho[foo')
# This unittest has been deactivated for some time...
# self.assertLogged(
# 'Caught exception: While reading action joho[foo we should have got 1 or 2 groups. Got: 0')
# let's test for what is actually logged and handle changes in the future
self.assertLogged("Error in action definition 'joho[foo'")
self.assertLogged(
"Caught exception: 'NoneType' object has no attribute 'endswith'")
"Caught exception: Invalid action declaration 'joho[foo'")
if STOCK:
def testStockSSHJail(self):
@ -496,7 +492,7 @@ class JailsReaderTest(LogCaptureTestCase):
def testReadTestJailConf(self):
jails = JailsReader(basedir=IMPERFECT_CONFIG, share_config=IMPERFECT_CONFIG_SHARE_CFG)
self.assertTrue(jails.read())
self.assertFalse(jails.getOptions())
self.assertTrue(jails.getOptions())
self.assertRaises(ValueError, jails.convert)
comm_commands = jails.convert(allow_no_files=True)
self.maxDiff = None
@ -525,7 +521,12 @@ class JailsReaderTest(LogCaptureTestCase):
['start', 'emptyaction'],
['start', 'missinglogfiles'],
['start', 'brokenaction'],
['start', 'parse_to_end_of_jail.conf'],]))
['start', 'parse_to_end_of_jail.conf'],
['config-error',
'Jail \'brokenactiondef\' skipped, because of wrong configuration: Error in action definition \'joho[foo\': ValueError("Invalid action declaration \'joho[foo\'",)'],
['config-error',
"Jail 'missingbitsjail' skipped, because of wrong configuration: Unable to read the filter 'catchallthebadies'"],
]))
self.assertLogged("Errors in jail 'missingbitsjail'. Skipping...")
self.assertLogged("No file(s) found for glob /weapons/of/mass/destruction")