From 4bb1fd519db09c44a76b35963cc0152a703c90f4 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 4 Mar 2025 14:39:24 +0100 Subject: [PATCH] test-suite: if failed, sample regexs factory would show responsible header line (failJSON) together with the error line --- fail2ban/tests/samplestestcase.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fail2ban/tests/samplestestcase.py b/fail2ban/tests/samplestestcase.py index 40c9a8ae..fe3676fd 100644 --- a/fail2ban/tests/samplestestcase.py +++ b/fail2ban/tests/samplestestcase.py @@ -163,6 +163,7 @@ def testSampleRegexsFactory(name, basedir): ignoreBlock = False lnnum = 0 for line in logFile: + jsonline = '' lnnum += 1 jsonREMatch = re.match("^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$", line) if jsonREMatch: @@ -204,6 +205,7 @@ def testSampleRegexsFactory(name, basedir): except ValueError as e: # pragma: no cover - we've valid json's raise ValueError("%s: %s:%i" % (e, logFile.getFileName(), lnnum)) + jsonline = line line = next(logFile) lnnum += 1 elif ignoreBlock or line.startswith("#") or not line.strip(): @@ -300,8 +302,9 @@ def testSampleRegexsFactory(name, basedir): import pprint raise AssertionError("%s: %s on: %s:%i, line:\n %s\nregex (%s):\n %s\n" "faildata: %s\nfail: %s" % ( - fltName, e, logFile.getFileName(), lnnum, - line, failregex, regexList[failregex] if failregex != -1 else None, + fltName, e, logFile.getFileName(), lnnum, + (("%s\n\u25ba %s" % (jsonline, line)) if jsonline else line), + failregex, regexList[failregex] if failregex != -1 else None, '\n'.join(pprint.pformat(faildata).splitlines()), '\n'.join(pprint.pformat(fail).splitlines())))