diff --git a/fail2ban/server/ticket.py b/fail2ban/server/ticket.py index 3883f0c8..6d856be3 100644 --- a/fail2ban/server/ticket.py +++ b/fail2ban/server/ticket.py @@ -46,9 +46,17 @@ class Ticket: self.__matches = matches or [] def __str__(self): - return "%s: ip=%s time=%s #attempts=%d" % \ - (self.__class__.__name__.split('.')[-1], self.__ip, self.__time, self.__attempt) - + return "%s: ip=%s time=%s #attempts=%d matches=%r" % \ + (self.__class__.__name__.split('.')[-1], self.__ip, self.__time, self.__attempt, self.__matches) + + def __repr__(self): + return str(self) + + def __eq__(self, other): + return self.__ip == other.__ip and \ + round(self.__time,2) == round(other.__time,2) and \ + self.__attempt == other.__attempt and \ + self.__matches == other.__matches def setIP(self, value): if isinstance(value, basestring): diff --git a/fail2ban/tests/failmanagertestcase.py b/fail2ban/tests/failmanagertestcase.py index 00ed603d..ee58d1b9 100644 --- a/fail2ban/tests/failmanagertestcase.py +++ b/fail2ban/tests/failmanagertestcase.py @@ -95,14 +95,14 @@ class AddFailure(unittest.TestCase): ticket_str = str(ticket) self.assertEqual( ticket_str, - 'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5') + 'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5 matches=[]') # and some get/set-ers otherwise not tested ticket.setTime(1000002000.0) self.assertEqual(ticket.getTime(), 1000002000.0) # and str() adjusted correspondingly self.assertEqual( str(ticket), - 'FailTicket: ip=193.168.0.128 time=1000002000.0 #attempts=5') + 'FailTicket: ip=193.168.0.128 time=1000002000.0 #attempts=5 matches=[]') def testbanNOK(self): self.__failManager.setMaxRetry(10)