mirror of https://github.com/fail2ban/fail2ban
- Updated testcases to fix the time using MyTime
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@419 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
af41290fc6
commit
ee86212435
|
@ -16,6 +16,7 @@ ver. 0.7.4 (2006/??/??) - beta
|
|||
option in "fail2ban.conf"
|
||||
- Added "backend" option in "jail.conf"
|
||||
- Added more filters/actions and jail samples
|
||||
- Improved testing framework
|
||||
|
||||
ver. 0.7.3 (2006/09/28) - beta
|
||||
----------
|
||||
|
|
|
@ -39,6 +39,11 @@ from testcases import failmanagertestcase
|
|||
from testcases import filtertestcase
|
||||
from testcases import servertestcase
|
||||
from testcases import datedetectortestcase
|
||||
from server.mytime import MyTime
|
||||
|
||||
# Set the time to a fixed, known value
|
||||
# Sun Aug 14 12:00:00 CEST 2005
|
||||
MyTime.setTime(1124013600)
|
||||
|
||||
# Gets the instance of the logger.
|
||||
logSys = logging.getLogger("fail2ban")
|
||||
|
@ -54,7 +59,7 @@ tests = unittest.TestSuite()
|
|||
# Filter
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP))
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.LogFile))
|
||||
#tests.addTest(unittest.makeSuite(filtertestcase.GetFailures))
|
||||
tests.addTest(unittest.makeSuite(filtertestcase.GetFailures))
|
||||
# Server
|
||||
#tests.addTest(unittest.makeSuite(servertestcase.StartStop))
|
||||
#tests.addTest(unittest.makeSuite(servertestcase.Transmitter))
|
||||
|
|
|
@ -48,13 +48,9 @@ class DateDetectorTest(unittest.TestCase):
|
|||
|
||||
def testGetTime(self):
|
||||
log = "Jan 23 21:59:59 [sshd] error: PAM: Authentication failure"
|
||||
date = [2006, 1, 23, 21, 59, 59, 1, 23, -1]
|
||||
dateUnix = 1138049999.0
|
||||
date = [2005, 1, 23, 21, 59, 59, 1, 23, -1]
|
||||
dateUnix = 1106513999.0
|
||||
|
||||
self.assertEqual(self.__datedetector.getTime(log), date)
|
||||
self.assertEqual(self.__datedetector.getTime(log), date)
|
||||
self.assertEqual(self.__datedetector.getTime(log), date)
|
||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
|
||||
|
|
@ -1,18 +1,19 @@
|
|||
Déc 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Déc 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Déc 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dez 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dez 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dez 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Dec 31 23:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Déc 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Déc 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Déc 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from failed.dns.ch
|
||||
Dez 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dez 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dez 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
De 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Aug 14 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 193.168.0.128
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10
|
||||
|
|
|
@ -8,3 +8,6 @@ Mar 16 10:34:01 i60p295 sshd[12365]: Postponed keyboard-interactive/pam for roeh
|
|||
Mar 16 10:34:01 i60p295 sshd[12365]: Accepted keyboard-interactive/pam for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
Mär 16 10:33:59 i60p295 sshd[12365]: Failed publickey for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
Mär 16 10:33:59 i60p295 sshd[12365]: Failed publickey for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
Mar 16 10:35:01 i60p295 sshd[12365]: Accepted keyboard-interactive/pam for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
Mar 16 10:36:01 i60p295 sshd[12365]: Accepted keyboard-interactive/pam for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
Mar 16 10:37:01 i60p295 sshd[12365]: Accepted keyboard-interactive/pam for roehl from ::ffff:141.3.81.106 port 51332 ssh2
|
||||
|
|
|
@ -26,13 +26,14 @@ __license__ = "GPL"
|
|||
|
||||
import unittest, socket
|
||||
from server.filterpoll import FilterPoll
|
||||
from server.filter import Filter
|
||||
from server.failmanager import FailManager
|
||||
|
||||
class IgnoreIP(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Call before every test case."""
|
||||
self.__filter = FilterPoll(None)
|
||||
self.__filter = Filter(None)
|
||||
|
||||
def tearDown(self):
|
||||
"""Call after every test case."""
|
||||
|
@ -77,29 +78,30 @@ class LogFile(unittest.TestCase):
|
|||
|
||||
class GetFailures(unittest.TestCase):
|
||||
|
||||
FILENAME = "testcases/files/testcase01.log"
|
||||
|
||||
def setUp(self):
|
||||
"""Call before every test case."""
|
||||
self.__filter = FilterPoll(None)
|
||||
self.__filter.addLogPath("testcases/files/testcase01.log")
|
||||
self.__filter.setTimeRegex("\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}")
|
||||
self.__filter.setTimePattern("%b %d %H:%M:%S")
|
||||
self.__filter = Filter(None)
|
||||
self.__filter.addLogPath(FILENAME)
|
||||
#self.__filter.setTimeRegex("\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}")
|
||||
#self.__filter.setTimePattern("%b %d %H:%M:%S")
|
||||
self.__filter.setFailRegex("(?:(?:Authentication failure|Failed [-/\w+]+) for(?: [iI](?:llegal|nvalid) user)?|[Ii](?:llegal|nvalid) user|ROOT LOGIN REFUSED) .*(?: from|FROM) (?:::f{4,6}:)?(?P<host>\S*)")
|
||||
|
||||
def tearDown(self):
|
||||
"""Call after every test case."""
|
||||
|
||||
def testGetFailures(self):
|
||||
output = [('87.142.124.10', 3, 1167605999.0),
|
||||
('193.168.0.128', 3, 1167605999.0)]
|
||||
output = ('193.168.0.128', 3, 1124013599.0)
|
||||
|
||||
self.__filter.openLogFile()
|
||||
self.__filter.getFailures()
|
||||
self.__filter.getFailures(FILENAME)
|
||||
|
||||
ticket = self.__filter.failManager.toBan()
|
||||
|
||||
attempts = ticket.getAttempt()
|
||||
date = ticket.getTime()
|
||||
ip = ticket.getIP()
|
||||
found = (ip, attempts, date)
|
||||
|
||||
found = []
|
||||
for ip in self.__filter.failManager.failList:
|
||||
fData = self.__filter.failManager.failList[ip]
|
||||
retry = fData.getRetry()
|
||||
lTime = fData.getLastTime()
|
||||
found.append((ip, retry, lTime))
|
||||
self.assertEqual(found, output)
|
||||
|
Loading…
Reference in New Issue