mirror of https://github.com/fail2ban/fail2ban
Merge branch 'datedetector-testcase' of https://github.com/kwirk/fail2ban
* 'datedetector-testcase' of https://github.com/kwirk/fail2ban: Correct datedetector testcases for TAI64N format Additional date/time formats for datedetector testcasespull/150/merge
commit
e3d3a6ac02
|
@ -158,6 +158,7 @@ class DateStrptime(DateTemplate):
|
||||||
"pattern" % (opattern, e))
|
"pattern" % (opattern, e))
|
||||||
if date[0] < 2000:
|
if date[0] < 2000:
|
||||||
# There is probably no year field in the logs
|
# There is probably no year field in the logs
|
||||||
|
# NOTE: Possibly makes week/year day incorrect
|
||||||
date[0] = MyTime.gmtime()[0]
|
date[0] = MyTime.gmtime()[0]
|
||||||
# Bug fix for #1241756
|
# Bug fix for #1241756
|
||||||
# If the date is greater than the current time, we suppose
|
# If the date is greater than the current time, we suppose
|
||||||
|
@ -166,10 +167,12 @@ class DateStrptime(DateTemplate):
|
||||||
logSys.debug(
|
logSys.debug(
|
||||||
u"Correcting deduced year from %d to %d since %f > %f" %
|
u"Correcting deduced year from %d to %d since %f > %f" %
|
||||||
(date[0], date[0]-1, time.mktime(date), MyTime.time()))
|
(date[0], date[0]-1, time.mktime(date), MyTime.time()))
|
||||||
|
# NOTE: Possibly makes week/year day incorrect
|
||||||
date[0] -= 1
|
date[0] -= 1
|
||||||
elif date[1] == 1 and date[2] == 1:
|
elif date[1] == 1 and date[2] == 1:
|
||||||
# If it is Jan 1st, it is either really Jan 1st or there
|
# If it is Jan 1st, it is either really Jan 1st or there
|
||||||
# is neither month nor day in the log.
|
# is neither month nor day in the log.
|
||||||
|
# NOTE: Possibly makes week/year day incorrect
|
||||||
date[1] = MyTime.gmtime()[1]
|
date[1] = MyTime.gmtime()[1]
|
||||||
date[2] = MyTime.gmtime()[2]
|
date[2] = MyTime.gmtime()[2]
|
||||||
return date
|
return date
|
||||||
|
|
|
@ -46,35 +46,45 @@ class DateDetectorTest(unittest.TestCase):
|
||||||
date = [2006, 1, 23, 21, 59, 59, 0, 23, 0]
|
date = [2006, 1, 23, 21, 59, 59, 0, 23, 0]
|
||||||
dateUnix = 1138049999.0
|
dateUnix = 1138049999.0
|
||||||
|
|
||||||
self.assertEqual(self.__datedetector.getTime(log), date)
|
self.assertEqual(self.__datedetector.getTime(log)[:6], date[:6])
|
||||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||||
|
|
||||||
def testGetTime(self):
|
def testGetTime(self):
|
||||||
log = "Jan 23 21:59:59 [sshd] error: PAM: Authentication failure"
|
log = "Jan 23 21:59:59 [sshd] error: PAM: Authentication failure"
|
||||||
date = [2005, 1, 23, 21, 59, 59, 1, 23, -1]
|
date = [2005, 1, 23, 21, 59, 59, 6, 23, -1]
|
||||||
dateUnix = 1106513999.0
|
dateUnix = 1106513999.0
|
||||||
|
|
||||||
self.assertEqual(self.__datedetector.getTime(log), date)
|
self.assertEqual(self.__datedetector.getTime(log)[:6], date[:6])
|
||||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||||
|
|
||||||
def testVariousTimes(self):
|
def testVariousTimes(self):
|
||||||
"""Test detection of various common date/time formats f2b should understand
|
"""Test detection of various common date/time formats f2b should understand
|
||||||
"""
|
"""
|
||||||
date = [2005, 1, 23, 21, 59, 59, 1, 23, -1]
|
date = [2005, 1, 23, 21, 59, 59, 6, 23, -1]
|
||||||
dateUnix = 1106513999.0
|
dateUnix = 1106513999.0
|
||||||
|
|
||||||
for sdate in (
|
for sdate in (
|
||||||
"Jan 23 21:59:59",
|
"Jan 23 21:59:59",
|
||||||
|
"Sun Jan 23 21:59:59 2005",
|
||||||
|
"Sun Jan 23 21:59:59",
|
||||||
|
"2005/01/23 21:59:59",
|
||||||
"2005.01.23 21:59:59",
|
"2005.01.23 21:59:59",
|
||||||
"23/01/2005 21:59:59",
|
"23/01/2005 21:59:59",
|
||||||
|
"23/01/05 21:59:59",
|
||||||
|
"23/Jan/2005:21:59:59",
|
||||||
|
"01/23/2005:21:59:59",
|
||||||
|
"2005-01-23 21:59:59",
|
||||||
|
"23-Jan-2005 21:59:59",
|
||||||
|
"23-01-2005 21:59:59",
|
||||||
"01-23-2005 21:59:59.252", # reported on f2b, causes Feb29 fix to break
|
"01-23-2005 21:59:59.252", # reported on f2b, causes Feb29 fix to break
|
||||||
|
"@4000000041f4104f00000000", # TAI64N
|
||||||
|
"2005-01-23T21:59:59.252Z", #ISO 8601
|
||||||
|
"2005-01-23T21:59:59-05:00Z", #ISO 8601 with TZ
|
||||||
|
"<01/23/05@21:59:59>",
|
||||||
):
|
):
|
||||||
log = sdate + "[sshd] error: PAM: Authentication failure"
|
log = sdate + "[sshd] error: PAM: Authentication failure"
|
||||||
# exclude
|
# exclude
|
||||||
|
|
||||||
# TODO (Yarik is confused): figure out why for above it is
|
|
||||||
# "1" as day of the week which would be Tue, although it
|
|
||||||
# was Sun
|
|
||||||
self.assertEqual(self.__datedetector.getTime(log)[:6], date[:6])
|
self.assertEqual(self.__datedetector.getTime(log)[:6], date[:6])
|
||||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue