Skip to content

Commit

Permalink
BF: fixing up for handling of TAI64N timestamps and adding some unitt…
Browse files Browse the repository at this point in the history
…est for prev commit (not effective much though)
  • Loading branch information
yarikoptic committed Mar 25, 2013
1 parent 7813340 commit 3b4084d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/datetemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setName(self, name):
def getName(self):
return self.__name

def setRegex(self, regex, wordBegin = True):
def setRegex(self, regex, wordBegin=True):
regex = regex.strip()
if (wordBegin and not re.search(r'^\^', regex)):
regex = r'\b' + regex
Expand Down Expand Up @@ -186,7 +186,8 @@ class DateTai64n(DateTemplate):
def __init__(self):
DateTemplate.__init__(self)
# We already know the format for TAI64N
self.setRegex("@[0-9a-f]{24}")
# yoh: we should not add an additional front anchor
self.setRegex("@[0-9a-f]{24}", wordBegin=False)

def getDate(self, line):
date = None
Expand Down
21 changes: 21 additions & 0 deletions testcases/datedetectortestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ def testAllUniqueTemplateNames(self):
self.assertRaises(ValueError, self.__datedetector._appendTemplate,
self.__datedetector.getTemplates()[0])

def testFullYearMatch_gh130(self):
# see https://github.com/fail2ban/fail2ban/pull/130
# yoh: unfortunately this test is not really effective to reproduce the
# situation but left in place to assure consistent behavior
m1 = [2012, 10, 11, 2, 37, 17]
self.assertEqual(
self.__datedetector.getTime('2012/10/11 02:37:17 [error] 18434#0')[:6],
m1)
self.__datedetector.sortTemplate()
# confuse it with year being at the end
for i in xrange(10):
self.assertEqual(
self.__datedetector.getTime('11/10/2012 02:37:17 [error] 18434#0')[:6],
m1)
self.__datedetector.sortTemplate()
# and now back to the original
self.assertEqual(
self.__datedetector.getTime('2012/10/11 02:37:17 [error] 18434#0')[:6],
m1)


# def testDefaultTempate(self):
# self.__datedetector.setDefaultRegex("^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}")
# self.__datedetector.setDefaultPattern("%b %d %H:%M:%S")
Expand Down

0 comments on commit 3b4084d

Please sign in to comment.