mirror of https://github.com/fail2ban/fail2ban
Merge branch 'up/fix_searchIP_v2' into build
* up/fix_searchIP_v2: NF: adding unittests for previous commit BF: anchoring regex for IP with " *$" at the end + adjust regexp for <HOST>debian-releases/squeeze
commit
2a94e90363
|
@ -57,6 +57,7 @@ tests = unittest.TestSuite()
|
|||
tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP))
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.LogFile))
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.GetFailures))
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests))
|
||||
# Server
|
||||
#tests.addTest(unittest.makeSuite(servertestcase.StartStop))
|
||||
#tests.addTest(unittest.makeSuite(servertestcase.Transmitter))
|
||||
|
|
|
@ -44,7 +44,7 @@ class Regex:
|
|||
self._matchCache = None
|
||||
# Perform shortcuts expansions.
|
||||
# Replace "<HOST>" with default regular expression for host.
|
||||
regex = regex.replace("<HOST>", "(?:::f{4,6}:)?(?P<host>\S+)")
|
||||
regex = regex.replace("<HOST>", "(?:::f{4,6}:)?(?P<host>[\w\-.^_]+)")
|
||||
if regex.lstrip() == '':
|
||||
raise RegexException("Cannot add empty regex")
|
||||
try:
|
||||
|
|
|
@ -492,7 +492,7 @@ import socket, struct
|
|||
|
||||
class DNSUtils:
|
||||
|
||||
IP_CRE = re.compile("(?:\d{1,3}\.){3}\d{1,3}")
|
||||
IP_CRE = re.compile("(?:\d{1,3}\.){3}\d{1,3}$")
|
||||
|
||||
#@staticmethod
|
||||
def dnsToIp(dns):
|
||||
|
|
|
@ -26,7 +26,7 @@ __license__ = "GPL"
|
|||
|
||||
import unittest
|
||||
from server.filterpoll import FilterPoll
|
||||
from server.filter import FileFilter
|
||||
from server.filter import FileFilter, DNSUtils
|
||||
from server.failmanager import FailManager
|
||||
from server.failmanager import FailManagerEmpty
|
||||
|
||||
|
@ -195,3 +195,15 @@ class GetFailures(unittest.TestCase):
|
|||
self.__filter.getFailures(GetFailures.FILENAME_02)
|
||||
|
||||
self.assertRaises(FailManagerEmpty, self.__filter.failManager.toBan)
|
||||
|
||||
class DNSUtilsTests(unittest.TestCase):
|
||||
|
||||
def testTextToIp(self):
|
||||
bogus = [
|
||||
'doh1.2.3.4.buga.xxxxx.yyy',
|
||||
'1.2.3.4.buga.xxxxx.yyy',
|
||||
]
|
||||
"""Really bogus addresses which should have no matches"""
|
||||
for s in bogus:
|
||||
res = DNSUtils.textToIp(s)
|
||||
self.assertEqual(res, [])
|
||||
|
|
Loading…
Reference in New Issue