From 17472a8b56de0673adca8efc62e84d1ecb271cbf Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 10 May 2015 06:36:29 -0400 Subject: [PATCH] BF: guarantee order of dbfile to be before dbpurgeage (Closes #1048) --- fail2ban/server/transmitter.py | 1 + fail2ban/tests/clientreadertestcase.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/fail2ban/server/transmitter.py b/fail2ban/server/transmitter.py index 537cd34d..0d9f0fe4 100644 --- a/fail2ban/server/transmitter.py +++ b/fail2ban/server/transmitter.py @@ -139,6 +139,7 @@ class Transmitter: elif name == "dbpurgeage": db = self.__server.getDatabase() if db is None: + logSys.warning("dbpurgeage setting was not in effect since no db yet") return None else: db.purgeage = command[1] diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index e3f1699a..25633a19 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -622,6 +622,21 @@ class JailsReaderTest(LogCaptureTestCase): configurator.getOptions() configurator.convertToProtocol() commands = configurator.getConfigStream() + + # verify that dbfile comes before dbpurgeage + def find_set(option): + for i, e in enumerate(commands): + if e[0] == 'set' and e[1] == option: + return i + raise ValueError("Did not find command 'set %s' among commands %s" + % (option, commands)) + + # Set up of logging should come first + self.assertEqual(find_set('logtarget'), 1) + self.assertEqual(find_set('loglevel'), 2) + # then dbfile should be before dbpurgeage + self.assertGreater(find_set('dbpurgeage'), find_set('dbfile')) + # and there is logging information left to be passed into the # server self.assertEqual(sorted(commands),