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
Yaroslav Halchenko 2009-02-05 09:51:36 -05:00
commit 2a94e90363
4 changed files with 16 additions and 3 deletions

View File

@ -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))

View File

@ -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:

View File

@ -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):

View File

@ -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, [])