mirror of https://github.com/fail2ban/fail2ban
TST: test for filter coverage in jail.conf
parent
bc5809ead0
commit
51d4263358
|
@ -46,7 +46,12 @@ class JailReader(ConfigReader):
|
||||||
self.__filter = None
|
self.__filter = None
|
||||||
self.__force_enable = force_enable
|
self.__force_enable = force_enable
|
||||||
self.__actions = list()
|
self.__actions = list()
|
||||||
|
self.__opts = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def options(self):
|
||||||
|
return self.__opts
|
||||||
|
|
||||||
def setName(self, value):
|
def setName(self, value):
|
||||||
self.__name = value
|
self.__name = value
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ class JailsReader(ConfigReader):
|
||||||
self.__jails = list()
|
self.__jails = list()
|
||||||
self.__force_enable = force_enable
|
self.__force_enable = force_enable
|
||||||
|
|
||||||
|
@property
|
||||||
|
def jails(self):
|
||||||
|
return self.__jails
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
return ConfigReader.read(self, "jail")
|
return ConfigReader.read(self, "jail")
|
||||||
|
|
||||||
|
|
|
@ -482,6 +482,21 @@ class JailsReaderTest(LogCaptureTestCase):
|
||||||
# ['gssftpd', 'qmail', 'apache-nohome', 'exim', 'dropbear', 'webmin-auth', 'cyrus-imap', 'sieve']
|
# ['gssftpd', 'qmail', 'apache-nohome', 'exim', 'dropbear', 'webmin-auth', 'cyrus-imap', 'sieve']
|
||||||
# self.assertEqual(get_all_confs('filter.d').difference(allFilters),
|
# self.assertEqual(get_all_confs('filter.d').difference(allFilters),
|
||||||
# set(['common']))
|
# set(['common']))
|
||||||
|
|
||||||
|
def testReadSockJailConfComplete(self):
|
||||||
|
jails = JailsReader(basedir=CONFIG_DIR, force_enable=True)
|
||||||
|
self.assertTrue(jails.read()) # opens fine
|
||||||
|
self.assertTrue(jails.getOptions()) # reads fine
|
||||||
|
# grab all filter names
|
||||||
|
filters = set(os.path.splitext(os.path.split(a)[1])[0]
|
||||||
|
for a in glob.glob(os.path.join('config', 'filter.d', '*.conf'))
|
||||||
|
if not a.endswith('common.conf'))
|
||||||
|
filters_jail = set(jail.options['filter'] for jail in jails.jails)
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertTrue(filters.issubset(filters_jail),
|
||||||
|
"More filters exists than are referenced in stock jail.conf %r" % filters.difference(filters_jail))
|
||||||
|
self.assertTrue(filters_jail.issubset(filters),
|
||||||
|
"Stock jail.conf references non-existent filters %r" % filters_jail.difference(filters))
|
||||||
|
|
||||||
def testReadStockJailConfForceEnabled(self):
|
def testReadStockJailConfForceEnabled(self):
|
||||||
# more of a smoke test to make sure that no obvious surprises
|
# more of a smoke test to make sure that no obvious surprises
|
||||||
|
|
Loading…
Reference in New Issue