meantime commit: code review, simplification, pythonization, etc.

pull/1414/head
sebres 9 years ago
parent a093828602
commit 3893a6b780

@ -375,6 +375,8 @@ class Filter(JailThread):
# @return True if IP address is in ignore list # @return True if IP address is in ignore list
def inIgnoreIPList(self, ip, log_ignore=False): def inIgnoreIPList(self, ip, log_ignore=False):
if isinstance(ip, basestring):
ip = IPAddr(ip)
for net in self.__ignoreIpList: for net in self.__ignoreIpList:
# if it isn't a valid IP address, try DNS resolution # if it isn't a valid IP address, try DNS resolution
if not net.isValidIP() and net.getRaw() != "": if not net.isValidIP() and net.getRaw() != "":
@ -394,7 +396,6 @@ class Filter(JailThread):
command = CommandAction.replaceTag(self.__ignoreCommand, { 'ip': ip } ) command = CommandAction.replaceTag(self.__ignoreCommand, { 'ip': ip } )
logSys.debug('ignore command: ' + command) logSys.debug('ignore command: ' + command)
ret_ignore = CommandAction.executeCmd(command) ret_ignore = CommandAction.executeCmd(command)
self.logIgnoreIp(ip, log_ignore and ret_ignore, ignore_source="command") self.logIgnoreIp(ip, log_ignore and ret_ignore, ignore_source="command")
return ret_ignore return ret_ignore

@ -125,14 +125,14 @@ class TransmitterBase(unittest.TestCase):
self.transm.proceed(["get", jail, cmd]), (0, [])) self.transm.proceed(["get", jail, cmd]), (0, []))
for n, value in enumerate(values): for n, value in enumerate(values):
ret = self.transm.proceed(["set", jail, cmdAdd, value]) ret = self.transm.proceed(["set", jail, cmdAdd, value])
self.assertEqual((ret[0], sorted(ret[1])), (0, sorted(values[:n+1]))) self.assertEqual((ret[0], sorted(map(str, ret[1]))), (0, sorted(map(str, values[:n+1]))))
ret = self.transm.proceed(["get", jail, cmd]) ret = self.transm.proceed(["get", jail, cmd])
self.assertEqual((ret[0], sorted(ret[1])), (0, sorted(values[:n+1]))) self.assertEqual((ret[0], sorted(map(str, ret[1]))), (0, sorted(map(str, values[:n+1]))))
for n, value in enumerate(values): for n, value in enumerate(values):
ret = self.transm.proceed(["set", jail, cmdDel, value]) ret = self.transm.proceed(["set", jail, cmdDel, value])
self.assertEqual((ret[0], sorted(ret[1])), (0, sorted(values[n+1:]))) self.assertEqual((ret[0], sorted(map(str, ret[1]))), (0, sorted(map(str, values[n+1:]))))
ret = self.transm.proceed(["get", jail, cmd]) ret = self.transm.proceed(["get", jail, cmd])
self.assertEqual((ret[0], sorted(ret[1])), (0, sorted(values[n+1:]))) self.assertEqual((ret[0], sorted(map(str, ret[1]))), (0, sorted(map(str, values[n+1:]))))
def jailAddDelRegexTest(self, cmd, inValues, outValues, jail): def jailAddDelRegexTest(self, cmd, inValues, outValues, jail):
cmdAdd = "add" + cmd cmdAdd = "add" + cmd

Loading…
Cancel
Save