diff --git a/fail2ban/client/jailreader.py b/fail2ban/client/jailreader.py index 0a9d4226..8425ea5a 100644 --- a/fail2ban/client/jailreader.py +++ b/fail2ban/client/jailreader.py @@ -46,7 +46,12 @@ class JailReader(ConfigReader): self.__filter = None self.__force_enable = force_enable self.__actions = list() + self.__opts = None + @property + def options(self): + return self.__opts + def setName(self, value): self.__name = value diff --git a/fail2ban/client/jailsreader.py b/fail2ban/client/jailsreader.py index f0794915..17e2ac22 100644 --- a/fail2ban/client/jailsreader.py +++ b/fail2ban/client/jailsreader.py @@ -46,6 +46,10 @@ class JailsReader(ConfigReader): self.__jails = list() self.__force_enable = force_enable + @property + def jails(self): + return self.__jails + def read(self): return ConfigReader.read(self, "jail") diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 0c4892a5..29cb50f1 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -482,6 +482,21 @@ class JailsReaderTest(LogCaptureTestCase): # ['gssftpd', 'qmail', 'apache-nohome', 'exim', 'dropbear', 'webmin-auth', 'cyrus-imap', 'sieve'] # self.assertEqual(get_all_confs('filter.d').difference(allFilters), # 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): # more of a smoke test to make sure that no obvious surprises