mirror of https://github.com/fail2ban/fail2ban
test-suite: if failed, sample regexs factory would show responsible header line (failJSON) together with the error line
parent
cf9c8f1e9b
commit
4bb1fd519d
|
@ -163,6 +163,7 @@ def testSampleRegexsFactory(name, basedir):
|
||||||
ignoreBlock = False
|
ignoreBlock = False
|
||||||
lnnum = 0
|
lnnum = 0
|
||||||
for line in logFile:
|
for line in logFile:
|
||||||
|
jsonline = ''
|
||||||
lnnum += 1
|
lnnum += 1
|
||||||
jsonREMatch = re.match("^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$", line)
|
jsonREMatch = re.match("^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$", line)
|
||||||
if jsonREMatch:
|
if jsonREMatch:
|
||||||
|
@ -204,6 +205,7 @@ def testSampleRegexsFactory(name, basedir):
|
||||||
except ValueError as e: # pragma: no cover - we've valid json's
|
except ValueError as e: # pragma: no cover - we've valid json's
|
||||||
raise ValueError("%s: %s:%i" %
|
raise ValueError("%s: %s:%i" %
|
||||||
(e, logFile.getFileName(), lnnum))
|
(e, logFile.getFileName(), lnnum))
|
||||||
|
jsonline = line
|
||||||
line = next(logFile)
|
line = next(logFile)
|
||||||
lnnum += 1
|
lnnum += 1
|
||||||
elif ignoreBlock or line.startswith("#") or not line.strip():
|
elif ignoreBlock or line.startswith("#") or not line.strip():
|
||||||
|
@ -300,8 +302,9 @@ def testSampleRegexsFactory(name, basedir):
|
||||||
import pprint
|
import pprint
|
||||||
raise AssertionError("%s: %s on: %s:%i, line:\n %s\nregex (%s):\n %s\n"
|
raise AssertionError("%s: %s on: %s:%i, line:\n %s\nregex (%s):\n %s\n"
|
||||||
"faildata: %s\nfail: %s" % (
|
"faildata: %s\nfail: %s" % (
|
||||||
fltName, e, logFile.getFileName(), lnnum,
|
fltName, e, logFile.getFileName(), lnnum,
|
||||||
line, failregex, regexList[failregex] if failregex != -1 else None,
|
(("%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(faildata).splitlines()),
|
||||||
'\n'.join(pprint.pformat(fail).splitlines())))
|
'\n'.join(pprint.pformat(fail).splitlines())))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue