small amend (preparing to merge in 0.11): more precise test and avoid "expired bantime" (in 0.11)

pull/2444/head
sebres 2019-06-11 15:46:06 +02:00
parent 93727abeb8
commit 3326ec95ce
1 changed files with 16 additions and 4 deletions

View File

@ -32,7 +32,7 @@ from ..server.actions import Actions
from ..server.ticket import FailTicket
from ..server.utils import Utils
from .dummyjail import DummyJail
from .utils import LogCaptureTestCase
from .utils import LogCaptureTestCase, with_alt_time, MyTime
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
@ -174,26 +174,38 @@ class ExecuteActions(LogCaptureTestCase):
self.assertLogged("action1 unban deleted aInfo IP")
self.assertLogged("action2 unban deleted aInfo IP")
@with_alt_time
def testUnbanOnBusyBanBombing(self):
# check unban happens in-between of "ban bombing" despite lower precedence,
# if it is not work, we'll see "Unbanned 25" earliest at flushing (after stop)
# each 3rd ban we should see an unban check (and tickets gets unbanned):
self.__actions.banPrecedence = 3
self.__actions.setBanTime(100)
self.__actions.start()
MyTime.setTime(0); # avoid "expired bantime" (in 0.11)
i = 0
while i < 25:
ip = "192.0.2.%d" % i
self.__jail.putFailTicket(FailTicket(ip, 0))
if not i: # wait for first to start "ban bombing":
self.assertLogged('Ban %s' % ip, wait=True)
i += 1
# wait for last ban (all 25 tickets gets banned):
self.assertLogged(' / 25,', wait=True)
MyTime.setTime(200); # unban time for 25 tickets reached
while i < 50:
ip = "192.0.2.%d" % i
self.__jail.putFailTicket(FailTicket(ip, 200))
i += 1
# wait for last ban (all 50 tickets gets banned):
self.assertLogged(' / 50,', wait=True)
self.__actions.stop()
self.__actions.join()
self.assertNotLogged('Unbanned 25, 0 ticket(s)', wait=False)
self.assertLogged('Unbanned 25, 0 ticket(s)')
self.assertNotLogged('Unbanned 50, 0 ticket(s)')