From 2c03f5ad28a1025cf1aed9724d05eb9723428154 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 1 Feb 2018 18:04:04 +0100 Subject: [PATCH 1/2] simple syntax change (wrong escape in string): no functional changes --- fail2ban/tests/clientreadertestcase.py | 4 ++-- fail2ban/tests/fail2banregextestcase.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 6c0d9226..9e5f0dfe 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -448,9 +448,9 @@ class FilterReaderTest(unittest.TestCase): self.assertSortedEqual(c, output) def testFilterReaderSubstitionSection(self): - output = [['set', 'jailname', 'addfailregex', '^\s*to=fail2ban@localhost fromip=\s*$']] + output = [['set', 'jailname', 'addfailregex', '^\\s*to=fail2ban@localhost fromip=\\s*$']] filterName, filterOpt = extractOptions( - 'substition[failregex="^\s*\s*$", honeypot=""]') + 'substition[failregex="^\\s*\\s*$", honeypot=""]') filterReader = FilterReader('substition', "jailname", filterOpt, share_config=TEST_FILES_DIR_SHARE_CFG, basedir=TEST_FILES_DIR) filterReader.read() diff --git a/fail2ban/tests/fail2banregextestcase.py b/fail2ban/tests/fail2banregextestcase.py index 148d774c..b1786c03 100644 --- a/fail2ban/tests/fail2banregextestcase.py +++ b/fail2ban/tests/fail2banregextestcase.py @@ -292,7 +292,7 @@ class Fail2banRegexTest(LogCaptureTestCase): def testRegexEpochPatterns(self): (opts, args, fail2banRegex) = _Fail2banRegex( - "-r", "-d", "^\[{LEPOCH}\]\s+", "--maxlines", "5", + "-r", "-d", r"^\[{LEPOCH}\]\s+", "--maxlines", "5", "[1516469849] 192.0.2.1 FAIL: failure\n" "[1516469849551] 192.0.2.2 FAIL: failure\n" "[1516469849551000] 192.0.2.3 FAIL: failure\n" From f1661d35eabdb9700acb28eb46dbeb98983a216c Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 1 Feb 2018 18:30:00 +0100 Subject: [PATCH 2/2] fix sporadic error, wait for shutdown/exit messages by assert-check, better prevention of dual (parallel) stop --- fail2ban/tests/fail2banclienttestcase.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fail2ban/tests/fail2banclienttestcase.py b/fail2ban/tests/fail2banclienttestcase.py index 92e08bfc..318a1c50 100644 --- a/fail2ban/tests/fail2banclienttestcase.py +++ b/fail2ban/tests/fail2banclienttestcase.py @@ -312,7 +312,9 @@ def with_foreground_server_thread(startextra={}): # wait for end sign: Utils.wait_for(lambda: phase.get('end', None) is not None, MAX_WAITTIME) self.assertTrue(phase.get('end', None)) - self.assertLogged("Shutdown successful", "Exiting Fail2ban", all=True) + self.assertLogged("Shutdown successful", "Exiting Fail2ban", all=True, wait=MAX_WAITTIME) + # set to NOP: avoid dual call + self.stopAndWaitForServerEnd = lambda *args, **kwargs: None self.stopAndWaitForServerEnd = _stopAndWaitForServerEnd # wait for start thread: Utils.wait_for(lambda: phase.get('start', None) is not None, MAX_WAITTIME) @@ -333,7 +335,6 @@ def with_foreground_server_thread(startextra={}): # so don't kill (same process) - if success, just wait for end of worker: if phase.get('end', None): th.join() - self.stopAndWaitForServerEnd = None return wrapper return _deco_wrapper