mirror of
https://github.com/fail2ban/fail2ban.git
synced 2026-03-11 08:55:31 +00:00
ENH: Throw exception if requested Jail is actually not defined at all
This commit is contained in:
parent
24e4cfe1b7
commit
8a0ac30bd9
2 changed files with 11 additions and 1 deletions
|
|
@ -54,7 +54,13 @@ class JailReader(ConfigReader):
|
|||
return self.__name
|
||||
|
||||
def read(self):
|
||||
return ConfigReader.read(self, "jail")
|
||||
out = ConfigReader.read(self, "jail")
|
||||
# Before returning -- verify that requested section
|
||||
# exists at all
|
||||
if not (self.__name in self.sections()):
|
||||
raise ValueError("Jail %r was not found among available"
|
||||
% self.__name)
|
||||
return out
|
||||
|
||||
def isEnabled(self):
|
||||
return self.__force_enable or self.__opts["enabled"]
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ option = %s
|
|||
|
||||
class JailReaderTest(unittest.TestCase):
|
||||
|
||||
def testIncorrectJail(self):
|
||||
jail = JailReader('XXXABSENTXXX', basedir=CONFIG_DIR)
|
||||
self.assertRaises(ValueError, jail.read)
|
||||
|
||||
def testStockSSHJail(self):
|
||||
jail = JailReader('ssh-iptables', basedir=CONFIG_DIR) # we are running tests from root project dir atm
|
||||
self.assertTrue(jail.read())
|
||||
|
|
|
|||
Loading…
Reference in a new issue