mirror of https://github.com/fail2ban/fail2ban
test cases fixed
parent
77dc5a334c
commit
c6e8c700f7
|
@ -127,9 +127,11 @@ class JailReader(ConfigReader):
|
||||||
|
|
||||||
if self.isEnabled():
|
if self.isEnabled():
|
||||||
# Read filter
|
# Read filter
|
||||||
if self.__opts["filter"]:
|
flt = self.__opts["filter"]
|
||||||
filterName, filterOpt = JailReader.extractOptions(
|
if flt:
|
||||||
self.__opts["filter"])
|
filterName, filterOpt = JailReader.extractOptions(flt)
|
||||||
|
if not filterName:
|
||||||
|
raise ValueError("Invalid filter declaration %r" % flt)
|
||||||
self.__filter = FilterReader(
|
self.__filter = FilterReader(
|
||||||
filterName, self.__name, filterOpt, share_config=self.share_config, basedir=self.getBaseDir())
|
filterName, self.__name, filterOpt, share_config=self.share_config, basedir=self.getBaseDir())
|
||||||
ret = self.__filter.read()
|
ret = self.__filter.read()
|
||||||
|
@ -157,6 +159,8 @@ class JailReader(ConfigReader):
|
||||||
if not act: # skip empty actions
|
if not act: # skip empty actions
|
||||||
continue
|
continue
|
||||||
actName, actOpt = JailReader.extractOptions(act)
|
actName, actOpt = JailReader.extractOptions(act)
|
||||||
|
if not actName:
|
||||||
|
raise ValueError("Invalid action declaration %r" % act)
|
||||||
if actName.endswith(".py"):
|
if actName.endswith(".py"):
|
||||||
self.__actions.append([
|
self.__actions.append([
|
||||||
"set",
|
"set",
|
||||||
|
@ -178,8 +182,8 @@ class JailReader(ConfigReader):
|
||||||
else:
|
else:
|
||||||
raise AttributeError("Unable to read action")
|
raise AttributeError("Unable to read action")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logSys.debug("Caught exception: %s" % (e,))
|
logSys.debug("Caught exception: %s", e, exc_info=True)
|
||||||
raise ValueError("Error in action definition %r" % e)
|
raise ValueError("Error in action definition %r: %r" % (act, e))
|
||||||
if not len(self.__actions):
|
if not len(self.__actions):
|
||||||
logSys.warning("No actions were defined for %s" % self.__name)
|
logSys.warning("No actions were defined for %s" % self.__name)
|
||||||
|
|
||||||
|
|
|
@ -193,13 +193,9 @@ class JailReaderTest(LogCaptureTestCase):
|
||||||
self.assertTrue(jail.read())
|
self.assertTrue(jail.read())
|
||||||
self.assertFalse(jail.getOptions())
|
self.assertFalse(jail.getOptions())
|
||||||
self.assertTrue(jail.isEnabled())
|
self.assertTrue(jail.isEnabled())
|
||||||
self.assertLogged('Error in action definition joho[foo')
|
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(
|
self.assertLogged(
|
||||||
"Caught exception: 'NoneType' object has no attribute 'endswith'")
|
"Caught exception: Invalid action declaration 'joho[foo'")
|
||||||
|
|
||||||
if STOCK:
|
if STOCK:
|
||||||
def testStockSSHJail(self):
|
def testStockSSHJail(self):
|
||||||
|
@ -496,7 +492,7 @@ class JailsReaderTest(LogCaptureTestCase):
|
||||||
def testReadTestJailConf(self):
|
def testReadTestJailConf(self):
|
||||||
jails = JailsReader(basedir=IMPERFECT_CONFIG, share_config=IMPERFECT_CONFIG_SHARE_CFG)
|
jails = JailsReader(basedir=IMPERFECT_CONFIG, share_config=IMPERFECT_CONFIG_SHARE_CFG)
|
||||||
self.assertTrue(jails.read())
|
self.assertTrue(jails.read())
|
||||||
self.assertFalse(jails.getOptions())
|
self.assertTrue(jails.getOptions())
|
||||||
self.assertRaises(ValueError, jails.convert)
|
self.assertRaises(ValueError, jails.convert)
|
||||||
comm_commands = jails.convert(allow_no_files=True)
|
comm_commands = jails.convert(allow_no_files=True)
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
|
@ -525,7 +521,12 @@ class JailsReaderTest(LogCaptureTestCase):
|
||||||
['start', 'emptyaction'],
|
['start', 'emptyaction'],
|
||||||
['start', 'missinglogfiles'],
|
['start', 'missinglogfiles'],
|
||||||
['start', 'brokenaction'],
|
['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("Errors in jail 'missingbitsjail'. Skipping...")
|
||||||
self.assertLogged("No file(s) found for glob /weapons/of/mass/destruction")
|
self.assertLogged("No file(s) found for glob /weapons/of/mass/destruction")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue