- some bug fixed to pass all test cases;

- database_v1.db/bans/jail-name bug fixed - cause of different jail name in jails and bans, in test case (by updateDb): FOREIGN KEY constraint failed:
  $ sqlite3 fail2ban/tests/files/database_v1.db
  sqlite> select distinct jail from bans;
  DummyJail #16244880 with 0 tickets
  sqlite> select distinct name from jails;
  DummyJail #29162448 with 0 tickets
  sqlite> update bans set jail = (select distinct name from jails);
pull/716/head
sebres 2014-05-05 14:47:50 +02:00
parent 6f7c9b7d0f
commit ccf07c4b21
4 changed files with 9 additions and 9 deletions

View File

@ -46,16 +46,16 @@ before = paths-debian.conf
# "bantimeextra.enabled" allows to use database for searching of previously banned ip's to increase a # "bantimeextra.enabled" allows to use database for searching of previously banned ip's to increase a
# default ban time using special formula, default it is banTime * 1, 2, 4, 8, 16, 32... # default ban time using special formula, default it is banTime * 1, 2, 4, 8, 16, 32...
bantimeextra.enabled = true #bantimeextra.enabled = true
# "bantimeextra.findtime" is the max number of seconds that we search in the database, # "bantimeextra.findtime" is the max number of seconds that we search in the database,
# if it is not specified - whole database will be used for ban searching # if it is not specified - whole database will be used for ban searching
# (please observe current "dbpurgeage" value of fail2ban.conf). # (please observe current "dbpurgeage" value of fail2ban.conf).
bantimeextra.findtime = 24*60*60 #bantimeextra.findtime = 24*60*60
# "bantimeextra.rndtime" is the max number of seconds using for mixing with random time # "bantimeextra.rndtime" is the max number of seconds using for mixing with random time
# to prevent "clever" botnets calculate exact time IP can be unbanned again: # to prevent "clever" botnets calculate exact time IP can be unbanned again:
bantimeextra.rndtime = 5*60 #bantimeextra.rndtime = 5*60
# "bantimeextra.maxtime" is the max number of seconds using the ban time can reach (don't grows further) # "bantimeextra.maxtime" is the max number of seconds using the ban time can reach (don't grows further)
bantimeextra.maxtime = 24*60*60 #bantimeextra.maxtime = 24*60*60
# "bantimeextra.factor" is a coefficient to calculate exponent growing of the formula, # "bantimeextra.factor" is a coefficient to calculate exponent growing of the formula,
# by default value of factor "2.0 / 2.885385" and default value of formula, the ban time # by default value of factor "2.0 / 2.885385" and default value of formula, the ban time
# grows by 1, 2, 4, 8, 16 ... # grows by 1, 2, 4, 8, 16 ...

View File

@ -115,7 +115,7 @@ class Fail2BanDb(object):
"ip TEXT, " \ "ip TEXT, " \
"timeofban INTEGER NOT NULL, " \ "timeofban INTEGER NOT NULL, " \
"bantime INTEGER NOT NULL, " \ "bantime INTEGER NOT NULL, " \
"bancount INTEGER NOT NULL, " \ "bancount INTEGER NOT NULL default 1, " \
"data JSON, " \ "data JSON, " \
"FOREIGN KEY(jail) REFERENCES jails(name) " \ "FOREIGN KEY(jail) REFERENCES jails(name) " \
");" \ ");" \
@ -383,7 +383,7 @@ class Fail2BanDb(object):
#TODO: Implement data parts once arbitrary match keys completed #TODO: Implement data parts once arbitrary match keys completed
cur.execute( cur.execute(
"INSERT INTO bans(jail, ip, timeofban, bantime, bancount, data) VALUES(?, ?, ?, ?, ?, ?)", "INSERT INTO bans(jail, ip, timeofban, bantime, bancount, data) VALUES(?, ?, ?, ?, ?, ?)",
(jail.name, ticket.getIP(), ticket.getTime(), ticket.getBanTime(), ticket.getBanCount() + 1, (jail.name, ticket.getIP(), ticket.getTime(), ticket.getBanTime(jail.actions.getBanTime()), ticket.getBanCount() + 1,
{"matches": ticket.getMatches(), {"matches": ticket.getMatches(),
"failures": ticket.getAttempt()})) "failures": ticket.getAttempt()}))

View File

@ -96,10 +96,10 @@ class AddFailure(unittest.TestCase):
ticket_repr = repr(ticket) ticket_repr = repr(ticket)
self.assertEqual( self.assertEqual(
ticket_str, ticket_str,
'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5 matches=[]') 'FailTicket: ip=193.168.0.128 time=1167605999.0 bantime=None bancount=0 #attempts=5 matches=[]')
self.assertEqual( self.assertEqual(
ticket_repr, ticket_repr,
'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5 matches=[]') 'FailTicket: ip=193.168.0.128 time=1167605999.0 bantime=None bancount=0 #attempts=5 matches=[]')
self.assertFalse(ticket == False) self.assertFalse(ticket == False)
# and some get/set-ers otherwise not tested # and some get/set-ers otherwise not tested
ticket.setTime(1000002000.0) ticket.setTime(1000002000.0)
@ -107,7 +107,7 @@ class AddFailure(unittest.TestCase):
# and str() adjusted correspondingly # and str() adjusted correspondingly
self.assertEqual( self.assertEqual(
str(ticket), str(ticket),
'FailTicket: ip=193.168.0.128 time=1000002000.0 #attempts=5 matches=[]') 'FailTicket: ip=193.168.0.128 time=1000002000.0 bantime=None bancount=0 #attempts=5 matches=[]')
def testbanNOK(self): def testbanNOK(self):
self.__failManager.setMaxRetry(10) self.__failManager.setMaxRetry(10)

Binary file not shown.