@ -330,22 +330,49 @@ class Transmitter(TransmitterBase):
self . server . startJail ( self . jailName ) # Jail must be started
self . assertEqual (
self . transm . proceed ( [ " set " , self . jailName , " banip " , " 1 27 .0.0.1" ] ) ,
( 0 , " 127.0.0.1 " ) )
self . assertLogged ( " Ban 1 27.0.0.1" , wait = True ) # Give chance to ban
self . transm . proceed ( [ " set " , self . jailName , " banip " , " 1 9 2.0.2.1" , " 192. 0.2. 1" , " 192.0.2.2 " ] ) ,
( 0 , 2 ) )
self . assertLogged ( " Ban 1 92.0.2.1" , " Ban 192.0.2.2 " , all = True , wait = True ) # Give chance to ban
self . assertEqual (
self . transm . proceed ( [ " set " , self . jailName , " banip " , " Badger " ] ) ,
( 0 , " Badger " ) ) #NOTE: Is IP address validated? Is DNS Lookup done?
( 0 , 1 ) ) #NOTE: Is IP address validated? Is DNS Lookup done?
self . assertLogged ( " Ban Badger " , wait = True ) # Give chance to ban
# Unban IP
# Unban IP (first/last are not banned, so checking unban of both other succeeds):
self . assertEqual (
self . transm . proceed (
[ " set " , self . jailName , " unbanip " , " 127.0.0.1 " ] ) ,
( 0 , " 127.0.0.1 " ) )
# Unban IP which isn't banned
[ " set " , self . jailName , " unbanip " , " 192.0.2.255 " , " 192.0.2.1 " , " 192.0.2.2 " , " 192.0.2.254 " ] ) ,
( 0 , 2 ) )
self . assertLogged ( " Unban 192.0.2.1 " , " Unban 192.0.2.2 " , all = True , wait = True )
self . assertLogged ( " 192.0.2.255 is not banned " , " 192.0.2.254 is not banned " , all = True , wait = True )
self . pruneLog ( )
# Unban IP which isn't banned (error):
self . assertEqual (
self . transm . proceed (
[ " set " , self . jailName , " unbanip " , " 192.168.1.1 " ] ) [ 0 ] , 1 )
[ " set " , self . jailName , " unbanip " , " --report-absent " , " 192.0.2.255 " ] ) [ 0 ] , 1 )
# ... (no error, IPs logged only):
self . assertEqual (
self . transm . proceed (
[ " set " , self . jailName , " unbanip " , " 192.0.2.255 " , " 192.0.2.254 " ] ) , ( 0 , 0 ) )
self . assertLogged ( " 192.0.2.255 is not banned " , " 192.0.2.254 is not banned " , all = True , wait = True )
def testJailAttemptIP ( self ) :
self . server . startJail ( self . jailName ) # Jail must be started
def attempt ( ip , matches ) :
return self . transm . proceed ( [ " set " , self . jailName , " attempt " , ip ] + matches )
self . setGetTest ( " maxretry " , " 5 " , 5 , jail = self . jailName )
# produce 2 single attempts per IP:
for i in ( 1 , 2 ) :
for ip in ( " 192.0.2.1 " , " 192.0.2.2 " ) :
self . assertEqual ( attempt ( ip , [ " test failure %d " % i ] ) , ( 0 , 1 ) )
self . assertLogged ( " 192.0.2.1:2 " , " 192.0.2.2:2 " , all = True , wait = True )
# this 3 attempts at once should cause a ban:
self . assertEqual ( attempt ( ip , [ " test failure %d " % i for i in ( 3 , 4 , 5 ) ] ) , ( 0 , 1 ) )
self . assertLogged ( " 192.0.2.2:5 " , wait = True )
# resulted to ban for "192.0.2.2" but not for "192.0.2.1":
self . assertLogged ( " Ban 192.0.2.2 " , wait = True )
self . assertNotLogged ( " Ban 192.0.2.1 " )
def testJailMaxRetry ( self ) :
self . setGetTest ( " maxretry " , " 5 " , 5 , jail = self . jailName )