mirror of https://github.com/fail2ban/fail2ban
commit
8dccf099e4
|
@ -157,9 +157,9 @@ class Regex:
|
||||||
self._tupleValues.sort()
|
self._tupleValues.sort()
|
||||||
self._altValues = self._altValues if len(self._altValues) else None
|
self._altValues = self._altValues if len(self._altValues) else None
|
||||||
self._tupleValues = self._tupleValues if len(self._tupleValues) else None
|
self._tupleValues = self._tupleValues if len(self._tupleValues) else None
|
||||||
except sre_constants.error:
|
except sre_constants.error as e:
|
||||||
raise RegexException("Unable to compile regular expression '%s'" %
|
raise RegexException("Unable to compile regular expression '%s':\n%s" %
|
||||||
regex)
|
(regex, e))
|
||||||
# set fetch handler depending on presence of alternate (or tuple) tags:
|
# set fetch handler depending on presence of alternate (or tuple) tags:
|
||||||
self.getGroups = self._getGroupsWithAlt if (self._altValues or self._tupleValues) else self._getGroups
|
self.getGroups = self._getGroupsWithAlt if (self._altValues or self._tupleValues) else self._getGroups
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,13 @@ class Fail2banRegexTest(LogCaptureTestCase):
|
||||||
"test", r".** from <HOST>$"
|
"test", r".** from <HOST>$"
|
||||||
))
|
))
|
||||||
self.assertLogged("Unable to compile regular expression")
|
self.assertLogged("Unable to compile regular expression")
|
||||||
|
self.assertLogged("multiple repeat", "at position 2", all=False); # details of failed compilation
|
||||||
|
self.pruneLog()
|
||||||
|
self.assertFalse(_test_exec(
|
||||||
|
"test", r"^(?:(?P<type>A)|B)? (?(typo)...) from <ADDR>"
|
||||||
|
))
|
||||||
|
self.assertLogged("Unable to compile regular expression")
|
||||||
|
self.assertLogged("unknown group name: 'typo'", "at position 23", all=False); # details of failed compilation
|
||||||
|
|
||||||
def testWrongIngnoreRE(self):
|
def testWrongIngnoreRE(self):
|
||||||
self.assertFalse(_test_exec(
|
self.assertFalse(_test_exec(
|
||||||
|
@ -140,6 +147,7 @@ class Fail2banRegexTest(LogCaptureTestCase):
|
||||||
"test", r".*? from <HOST>$", r".**"
|
"test", r".*? from <HOST>$", r".**"
|
||||||
))
|
))
|
||||||
self.assertLogged("Unable to compile regular expression")
|
self.assertLogged("Unable to compile regular expression")
|
||||||
|
self.assertLogged("multiple repeat", "at position 2", all=False); # details of failed compilation
|
||||||
|
|
||||||
def testWrongFilterOptions(self):
|
def testWrongFilterOptions(self):
|
||||||
self.assertFalse(_test_exec(
|
self.assertFalse(_test_exec(
|
||||||
|
|
Loading…
Reference in New Issue