diff --git a/fail2ban/server/datedetector.py b/fail2ban/server/datedetector.py index dbfb9e5d..4bdcefd2 100644 --- a/fail2ban/server/datedetector.py +++ b/fail2ban/server/datedetector.py @@ -194,7 +194,7 @@ class DateDetector(object): logSys.log(logLevel, "Got time %f for \"%r\" using template %s", date[0], date[1].group(), template.name) return date - except ValueError: + except ValueError: # pragma: no cover pass return None finally: diff --git a/fail2ban/server/jail.py b/fail2ban/server/jail.py index a866cb51..c5f2e9cd 100644 --- a/fail2ban/server/jail.py +++ b/fail2ban/server/jail.py @@ -76,7 +76,8 @@ class Jail: self.__queue = Queue.Queue() self.__filter = None logSys.info("Creating new jail '%s'" % self.name) - self._setBackend(backend) + if backend is not None: + self._setBackend(backend) def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.name) @@ -106,11 +107,12 @@ class Jail: logSys.info("Initiated %r backend" % b) self.__actions = Actions(self) return # we are done - except ImportError, e: + except ImportError, e: # pragma: no cover # Log debug if auto, but error if specific logSys.log( logging.DEBUG if backend == "auto" else logging.ERROR, "Backend %r failed to initialize due to %s" % (b, e)) + # pragma: no cover # log error since runtime error message isn't printed, INVALID COMMAND logSys.error( "Failed to initialize any backend for Jail %r" % self.name) diff --git a/fail2ban/tests/datedetectortestcase.py b/fail2ban/tests/datedetectortestcase.py index 095b706a..9a7d3e78 100644 --- a/fail2ban/tests/datedetectortestcase.py +++ b/fail2ban/tests/datedetectortestcase.py @@ -29,20 +29,29 @@ import time import datetime from ..server.datedetector import DateDetector +from ..server import datedetector from ..server.datetemplate import DateTemplate -from .utils import setUpMyTime, tearDownMyTime +from .utils import setUpMyTime, tearDownMyTime, LogCaptureTestCase +from ..helpers import getLogger +logSys = getLogger("fail2ban") -class DateDetectorTest(unittest.TestCase): + +class DateDetectorTest(LogCaptureTestCase): def setUp(self): """Call before every test case.""" + LogCaptureTestCase.setUp(self) + self.__old_eff_level = datedetector.logLevel + datedetector.logLevel = logSys.getEffectiveLevel() setUpMyTime() self.__datedetector = DateDetector() self.__datedetector.addDefaultTemplate() def tearDown(self): """Call after every test case.""" + LogCaptureTestCase.tearDown(self) + datedetector.logLevel = self.__old_eff_level tearDownMyTime() def testGetEpochTime(self):