mirror of https://github.com/fail2ban/fail2ban
move helper to test, normalize invocations in order to emphasize assert comparison.
parent
963e14c685
commit
59688d7cd5
|
@ -103,26 +103,6 @@ class TransmitterBase(LogCaptureTestCase):
|
||||||
# if we expected to get it set without problem, check new value
|
# if we expected to get it set without problem, check new value
|
||||||
self.assertEqual(v(self.transm.proceed(getCmd)), v((0, outValue)))
|
self.assertEqual(v(self.transm.proceed(getCmd)), v((0, outValue)))
|
||||||
|
|
||||||
def getBanListTest(self, jail, banip=None, unbanip=None, outList=[]):
|
|
||||||
"""Process set banip/set unbanip commands and compare the list of
|
|
||||||
banned IP addresses with outList."""
|
|
||||||
# Ban IP address
|
|
||||||
if banip is not None:
|
|
||||||
self.assertEqual(
|
|
||||||
self.transm.proceed(["set", jail, "banip", banip]),
|
|
||||||
(0, banip))
|
|
||||||
self.assertLogged("Ban %s" % banip, wait=True) # Give chance to ban
|
|
||||||
# Unban IP address
|
|
||||||
if unbanip is not None:
|
|
||||||
self.assertEqual(
|
|
||||||
self.transm.proceed(["set", jail, "unbanip", unbanip]),
|
|
||||||
(0, unbanip))
|
|
||||||
self.assertLogged("Unban %s" % unbanip, wait=True) # Give chance to unban
|
|
||||||
# Compare the list of banned IP addresses with outList
|
|
||||||
self.assertSortedEqual(
|
|
||||||
self.transm.proceed(["get", jail, "banip"]),
|
|
||||||
(0, outList))
|
|
||||||
|
|
||||||
def setGetTestNOK(self, cmd, inValue, jail=None):
|
def setGetTestNOK(self, cmd, inValue, jail=None):
|
||||||
setCmd = ["set", cmd, inValue]
|
setCmd = ["set", cmd, inValue]
|
||||||
getCmd = ["get", cmd]
|
getCmd = ["get", cmd]
|
||||||
|
@ -372,22 +352,40 @@ class Transmitter(TransmitterBase):
|
||||||
self.server.addJail(jail, FAST_BACKEND)
|
self.server.addJail(jail, FAST_BACKEND)
|
||||||
self.server.startJail(jail)
|
self.server.startJail(jail)
|
||||||
|
|
||||||
self.getBanListTest(jail)
|
# Helper to process set banip/set unbanip commands and compare the list of
|
||||||
self.getBanListTest(
|
# banned IP addresses with outList.
|
||||||
jail, banip="127.0.0.1", outList=["127.0.0.1"])
|
def _getBanListTest(jail, banip=None, unbanip=None, outList=[]):
|
||||||
self.getBanListTest(
|
# Ban IP address
|
||||||
jail, banip="192.168.0.1",
|
if banip is not None:
|
||||||
|
self.assertEqual(
|
||||||
|
self.transm.proceed(["set", jail, "banip", banip]),
|
||||||
|
(0, banip))
|
||||||
|
self.assertLogged("Ban %s" % banip, wait=True) # Give chance to ban
|
||||||
|
# Unban IP address
|
||||||
|
if unbanip is not None:
|
||||||
|
self.assertEqual(
|
||||||
|
self.transm.proceed(["set", jail, "unbanip", unbanip]),
|
||||||
|
(0, unbanip))
|
||||||
|
self.assertLogged("Unban %s" % unbanip, wait=True) # Give chance to unban
|
||||||
|
# Compare the list of banned IP addresses with outList
|
||||||
|
self.assertSortedEqual(
|
||||||
|
self.transm.proceed(["get", jail, "banip"]),
|
||||||
|
(0, outList))
|
||||||
|
|
||||||
|
_getBanListTest(jail,
|
||||||
|
outList=[])
|
||||||
|
_getBanListTest(jail, banip="127.0.0.1",
|
||||||
|
outList=["127.0.0.1"])
|
||||||
|
_getBanListTest(jail, banip="192.168.0.1",
|
||||||
outList=["127.0.0.1", "192.168.0.1"])
|
outList=["127.0.0.1", "192.168.0.1"])
|
||||||
self.getBanListTest(
|
_getBanListTest(jail, banip="192.168.1.10",
|
||||||
jail, banip="192.168.1.10",
|
|
||||||
outList=["127.0.0.1", "192.168.0.1", "192.168.1.10"])
|
outList=["127.0.0.1", "192.168.0.1", "192.168.1.10"])
|
||||||
self.getBanListTest(
|
_getBanListTest(jail, unbanip="127.0.0.1",
|
||||||
jail, unbanip="127.0.0.1",
|
|
||||||
outList=["192.168.0.1", "192.168.1.10"])
|
outList=["192.168.0.1", "192.168.1.10"])
|
||||||
self.getBanListTest(
|
_getBanListTest(jail, unbanip="192.168.1.10",
|
||||||
jail, unbanip="192.168.1.10", outList=["192.168.0.1"])
|
outList=["192.168.0.1"])
|
||||||
self.getBanListTest(jail, unbanip="192.168.0.1", outList=[])
|
_getBanListTest(jail, unbanip="192.168.0.1",
|
||||||
self.getBanListTest(jail)
|
outList=[])
|
||||||
|
|
||||||
def testJailMaxRetry(self):
|
def testJailMaxRetry(self):
|
||||||
self.setGetTest("maxretry", "5", 5, jail=self.jailName)
|
self.setGetTest("maxretry", "5", 5, jail=self.jailName)
|
||||||
|
|
Loading…
Reference in New Issue