"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "fail2ban/tests/banmanagertestcase.py" between
fail2ban-0.10.5.tar.gz and fail2ban-0.11.1.tar.gz

About:

banmanagertestcase.py  (fail2ban-0.10.5):banmanagertestcase.py  (fail2ban-0.11.1)
skipping to change at line 29 skipping to change at line 29
# Author: Cyril Jaquier # Author: Cyril Jaquier
# #
__author__ = "Cyril Jaquier" __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
import unittest import unittest
from .utils import setUpMyTime, tearDownMyTime
from ..server.banmanager import BanManager from ..server.banmanager import BanManager
from ..server.ticket import BanTicket from ..server.ticket import BanTicket
class AddFailure(unittest.TestCase): class AddFailure(unittest.TestCase):
def setUp(self): def setUp(self):
"""Call before every test case.""" """Call before every test case."""
super(AddFailure, self).setUp() super(AddFailure, self).setUp()
setUpMyTime()
self.__ticket = BanTicket('193.168.0.128', 1167605999.0) self.__ticket = BanTicket('193.168.0.128', 1167605999.0)
self.__banManager = BanManager() self.__banManager = BanManager()
def tearDown(self): def tearDown(self):
"""Call after every test case.""" """Call after every test case."""
super(AddFailure, self).tearDown() super(AddFailure, self).tearDown()
tearDownMyTime()
def testAdd(self): def testAdd(self):
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
self.assertEqual(self.__banManager.size(), 1) self.assertEqual(self.__banManager.size(), 1)
self.assertEqual(self.__banManager.getBanTotal(), 1) self.assertEqual(self.__banManager.getBanTotal(), 1)
self.__banManager.setBanTotal(0) self.__banManager.setBanTotal(0)
self.assertEqual(self.__banManager.getBanTotal(), 0) self.assertEqual(self.__banManager.getBanTotal(), 0)
def testAddDuplicate(self): def testAddDuplicate(self):
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
skipping to change at line 97 skipping to change at line 101
def testInListOK(self): def testInListOK(self):
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
ticket = BanTicket('193.168.0.128', 1167605999.0) ticket = BanTicket('193.168.0.128', 1167605999.0)
self.assertTrue(self.__banManager._inBanList(ticket)) self.assertTrue(self.__banManager._inBanList(ticket))
def testInListNOK(self): def testInListNOK(self):
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
ticket = BanTicket('111.111.1.111', 1167605999.0) ticket = BanTicket('111.111.1.111', 1167605999.0)
self.assertFalse(self.__banManager._inBanList(ticket)) self.assertFalse(self.__banManager._inBanList(ticket))
def testBanTimeIncr(self):
ticket = BanTicket(self.__ticket.getIP(), self.__ticket.getTime()
)
## increase twice and at end permanent, check time/count increase
:
c = 0
for i in (1000, 2000, -1):
self.__banManager.addBanTicket(self.__ticket); c += 1
ticket.setBanTime(i)
self.assertFalse(self.__banManager.addBanTicket(ticket));
# no incr of c (already banned)
self.assertEqual(str(self.__banManager.getTicketByID(tick
et.getIP())),
"BanTicket: ip=%s time=%s bantime=%s bancount=%s
#attempts=0 matches=[]" % (ticket.getIP(), ticket.getTime(), i, c))
## after permanent, it should remain permanent ban time (-1):
self.__banManager.addBanTicket(self.__ticket); c += 1
ticket.setBanTime(-1)
self.assertFalse(self.__banManager.addBanTicket(ticket)); # no in
cr of c (already banned)
ticket.setBanTime(1000)
self.assertFalse(self.__banManager.addBanTicket(ticket)); # no in
cr of c (already banned)
self.assertEqual(str(self.__banManager.getTicketByID(ticket.getIP
())),
"BanTicket: ip=%s time=%s bantime=%s bancount=%s #attempt
s=0 matches=[]" % (ticket.getIP(), ticket.getTime(), -1, c))
def testUnban(self): def testUnban(self):
btime = self.__banManager.getBanTime() btime = self.__banManager.getBanTime()
stime = self.__ticket.getTime() stime = self.__ticket.getTime()
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
self.assertTrue(self.__banManager._inBanList(self.__ticket)) self.assertTrue(self.__banManager._inBanList(self.__ticket))
self.assertEqual(self.__banManager.unBanList(stime), []) self.assertEqual(self.__banManager.unBanList(stime), [])
self.assertEqual(self.__banManager.unBanList(stime + btime + 1), [self.__ticket]) self.assertEqual(self.__banManager.unBanList(stime + btime + 1), [self.__ticket])
self.assertEqual(self.__banManager.size(), 0) self.assertEqual(self.__banManager.size(), 0)
## again, but now we will prolong ban-time and then try to unban again (1st too early): ## again, but now we will prolong ban-time and then try to unban again (1st too early):
self.assertTrue(self.__banManager.addBanTicket(self.__ticket)) self.assertTrue(self.__banManager.addBanTicket(self.__ticket))
skipping to change at line 139 skipping to change at line 162
self.assertEqual(self.__banManager.unBanList(self.__ticke t.getTime() + btime + 1), []) self.assertEqual(self.__banManager.unBanList(self.__ticke t.getTime() + btime + 1), [])
self.assertEqual(self.__banManager.size(), 1) self.assertEqual(self.__banManager.size(), 1)
finally: finally:
self.__banManager.setBanTime(btime) self.__banManager.setBanTime(btime)
class StatusExtendedCymruInfo(unittest.TestCase): class StatusExtendedCymruInfo(unittest.TestCase):
def setUp(self): def setUp(self):
"""Call before every test case.""" """Call before every test case."""
super(StatusExtendedCymruInfo, self).setUp() super(StatusExtendedCymruInfo, self).setUp()
unittest.F2B.SkipIfNoNetwork() unittest.F2B.SkipIfNoNetwork()
setUpMyTime()
self.__ban_ip = "93.184.216.34" self.__ban_ip = "93.184.216.34"
self.__asn = "15133" self.__asn = "15133"
self.__country = "EU" self.__country = "EU"
self.__rir = "ripencc" self.__rir = "ripencc"
ticket = BanTicket(self.__ban_ip, 1167605999.0) ticket = BanTicket(self.__ban_ip, 1167605999.0)
self.__banManager = BanManager() self.__banManager = BanManager()
self.assertTrue(self.__banManager.addBanTicket(ticket)) self.assertTrue(self.__banManager.addBanTicket(ticket))
def tearDown(self): def tearDown(self):
"""Call after every test case.""" """Call after every test case."""
super(StatusExtendedCymruInfo, self).tearDown() super(StatusExtendedCymruInfo, self).tearDown()
tearDownMyTime()
available = True, None available = True, None
def _getBanListExtendedCymruInfo(self): def _getBanListExtendedCymruInfo(self):
tc = StatusExtendedCymruInfo tc = StatusExtendedCymruInfo
if tc.available[0]: if tc.available[0]:
cymru_info = self.__banManager.getBanListExtendedCymruInf o( cymru_info = self.__banManager.getBanListExtendedCymruInf o(
timeout=(2 if unittest.F2B.fast else 20)) timeout=(2 if unittest.F2B.fast else 20))
else: # pragma: no cover - availability (once after error case on ly) else: # pragma: no cover - availability (once after error case on ly)
cymru_info = tc.available[1] cymru_info = tc.available[1]
 End of changes. 6 change blocks. 
0 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)