diff --git a/.travis.yml b/.travis.yml index 8da3e0bb..2d091754 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,5 +14,5 @@ install: script: - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc fail2ban-testcases; else python ./fail2ban-testcases; fi -after_script: +after_success: - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi diff --git a/server/action.py b/server/action.py index 5fde3ae1..ce9651e8 100644 --- a/server/action.py +++ b/server/action.py @@ -297,10 +297,8 @@ class Action: if not Action.executeCmd(checkCmd): logSys.error("Invariant check failed. Trying to restore a sane" + " environment") - stopCmd = Action.replaceTag(self.__actionStop, self.__cInfo) - Action.executeCmd(stopCmd) - startCmd = Action.replaceTag(self.__actionStart, self.__cInfo) - Action.executeCmd(startCmd) + self.execActionStop() + self.execActionStart() if not Action.executeCmd(checkCmd): logSys.fatal("Unable to restore environment") return False diff --git a/server/server.py b/server/server.py index a0824f1d..5f1a52c1 100644 --- a/server/server.py +++ b/server/server.py @@ -66,7 +66,7 @@ class Server: # First set the mask to only allow access to owner os.umask(0077) - if self.__daemon: + if self.__daemon: # pragma: no cover logSys.info("Starting in daemon mode") ret = self.__createDaemon() if ret: @@ -379,7 +379,7 @@ class Server: try: handler.flush() handler.close() - except (ValueError, KeyError): + except (ValueError, KeyError): # pragma: no cover if sys.version_info >= (2,6): raise # is known to be thrown after logging was shutdown once @@ -404,7 +404,7 @@ class Server: finally: self.__loggingLock.release() - def __createDaemon(self): + def __createDaemon(self): # pragma: no cover """ Detach a process from the controlling terminal and run it in the background as a daemon. diff --git a/testcases/actiontestcase.py b/testcases/actiontestcase.py index b8292c27..50ae2816 100644 --- a/testcases/actiontestcase.py +++ b/testcases/actiontestcase.py @@ -61,6 +61,23 @@ class ExecuteAction(unittest.TestCase): def _is_logged(self, s): return s in self._log.getvalue() + def testReplaceTag(self): + aInfo = { + 'HOST': "192.0.2.0", + 'ABC': "123", + 'xyz': "890", + } + self.assertEqual( + self.__action.replaceTag("Text text", aInfo), + "Text 192.0.2.0 text") + self.assertEqual( + self.__action.replaceTag("Text text ABC", aInfo), + "Text 890 text 123 ABC") + self.assertEqual( + self.__action.replaceTag("", + {'matches': "some >char< should \< be[ escap}ed&"}), + r"some \>char\< should \\\< be\[ escap\}ed\&") + def testExecuteActionBan(self): self.__action.setActionStart("touch /tmp/fail2ban.test") self.__action.setActionStop("rm -f /tmp/fail2ban.test") diff --git a/testcases/servertestcase.py b/testcases/servertestcase.py index ffb057a9..1b6eb8d3 100644 --- a/testcases/servertestcase.py +++ b/testcases/servertestcase.py @@ -504,7 +504,9 @@ class TransmitterLogging(TransmitterBase): def testLogLevel(self): self.setGetTest("loglevel", "4", 4) + self.setGetTest("loglevel", "3", 3) self.setGetTest("loglevel", "2", 2) + self.setGetTest("loglevel", "1", 1) self.setGetTest("loglevel", "-1", -1) self.setGetTest("loglevel", "0", 0) self.setGetTestNOK("loglevel", "Bird")