From 5becaf8ef2b8cd37d65de8079ce38d5e2c05be6d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 1 Nov 2012 15:34:20 -0400 Subject: [PATCH] BF: (python 2.[45]) store backends names in a list to use .index later on (Closes gh-83) .index() got into tuple's API only in 2.6 --- fail2ban-testcases | 1 + server/jail.py | 4 +++- testcases/filtertestcase.py | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index ea95e9c5..cc616c0e 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -125,6 +125,7 @@ tests.addTest(unittest.makeSuite(filtertestcase.LogFile)) tests.addTest(unittest.makeSuite(filtertestcase.LogFileMonitor)) tests.addTest(unittest.makeSuite(filtertestcase.GetFailures)) tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests)) +tests.addTest(unittest.makeSuite(filtertestcase.JailTests)) # DateDetector tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) diff --git a/server/jail.py b/server/jail.py index 4ab83db4..dee64e7f 100644 --- a/server/jail.py +++ b/server/jail.py @@ -33,7 +33,9 @@ logSys = logging.getLogger("fail2ban.jail") class Jail: #Known backends. Each backend should have corresponding __initBackend method - _BACKENDS = ('pyinotify', 'gamin', 'polling') + # yoh: stored in a list instead of a tuple since only + # list had .index until 2.6 + _BACKENDS = ['pyinotify', 'gamin', 'polling'] def __init__(self, name, backend = "auto"): self.__name = name diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index eade537f..c10fa78d 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -28,6 +28,7 @@ import sys import time import tempfile +from server.jail import Jail from server.filterpoll import FilterPoll from server.filter import FileFilter, DNSUtils from server.failmanager import FailManager @@ -626,3 +627,10 @@ class DNSUtilsTests(unittest.TestCase): self.assertEqual(res, ['192.0.43.10']) else: self.assertEqual(res, []) + +class JailTests(unittest.TestCase): + + def testSetBackend_gh83(self): + # smoke test + jail = Jail('test', backend='polling') # Must not fail to initiate +