2007-01-21 22:19:57 +00:00
|
|
|
#!/usr/bin/python
|
2011-10-07 19:47:50 +00:00
|
|
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
# vi: set ft=python sts=4 ts=4 sw=4 noet :
|
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
# This file is part of Fail2Ban.
|
|
|
|
#
|
|
|
|
# Fail2Ban is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Fail2Ban is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Fail2Ban; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
# Author: Cyril Jaquier
|
|
|
|
#
|
2006-07-16 22:21:58 +00:00
|
|
|
# $Revision$
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
__author__ = "Cyril Jaquier"
|
2006-07-16 22:21:58 +00:00
|
|
|
__version__ = "$Revision$"
|
|
|
|
__date__ = "$Date$"
|
2006-06-26 20:05:00 +00:00
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
|
|
|
|
2011-10-07 19:14:13 +00:00
|
|
|
import unittest, logging, sys, time, os
|
2006-06-26 20:05:00 +00:00
|
|
|
|
2006-11-16 21:07:42 +00:00
|
|
|
from common.version import version
|
2006-08-06 21:56:01 +00:00
|
|
|
from testcases import banmanagertestcase
|
|
|
|
from testcases import clientreadertestcase
|
|
|
|
from testcases import failmanagertestcase
|
2006-06-26 20:05:00 +00:00
|
|
|
from testcases import filtertestcase
|
|
|
|
from testcases import servertestcase
|
2006-09-05 21:16:28 +00:00
|
|
|
from testcases import datedetectortestcase
|
2006-10-23 20:13:21 +00:00
|
|
|
from testcases import actiontestcase
|
2006-10-18 22:35:32 +00:00
|
|
|
from server.mytime import MyTime
|
|
|
|
|
|
|
|
# Set the time to a fixed, known value
|
|
|
|
# Sun Aug 14 12:00:00 CEST 2005
|
2011-10-07 19:14:13 +00:00
|
|
|
|
|
|
|
# yoh: we need to adjust TZ to match the one used by Cyril so all the timestamps match
|
|
|
|
old_TZ = os.environ.get('TZ', None)
|
|
|
|
os.environ['TZ'] = 'Europe/Zurich'
|
|
|
|
time.tzset()
|
2006-10-18 22:35:32 +00:00
|
|
|
MyTime.setTime(1124013600)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
logSys = logging.getLogger("fail2ban")
|
|
|
|
# Add the default logging handler
|
|
|
|
stdout = logging.StreamHandler(sys.stdout)
|
|
|
|
logSys.addHandler(stdout)
|
|
|
|
logSys.setLevel(logging.FATAL)
|
|
|
|
|
2006-07-08 16:51:14 +00:00
|
|
|
print "Fail2ban " + version + " test suite. Please wait..."
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
tests = unittest.TestSuite()
|
|
|
|
|
|
|
|
# Filter
|
|
|
|
tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP))
|
|
|
|
tests.addTest(unittest.makeSuite(filtertestcase.LogFile))
|
2006-10-18 22:35:32 +00:00
|
|
|
tests.addTest(unittest.makeSuite(filtertestcase.GetFailures))
|
2009-02-04 20:38:37 +00:00
|
|
|
tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests))
|
2006-06-26 20:05:00 +00:00
|
|
|
# Server
|
|
|
|
#tests.addTest(unittest.makeSuite(servertestcase.StartStop))
|
|
|
|
#tests.addTest(unittest.makeSuite(servertestcase.Transmitter))
|
2006-10-23 20:13:21 +00:00
|
|
|
tests.addTest(unittest.makeSuite(actiontestcase.ExecuteAction))
|
2006-06-26 20:05:00 +00:00
|
|
|
# FailManager
|
|
|
|
tests.addTest(unittest.makeSuite(failmanagertestcase.AddFailure))
|
|
|
|
# BanManager
|
|
|
|
tests.addTest(unittest.makeSuite(banmanagertestcase.AddFailure))
|
2006-08-06 21:56:01 +00:00
|
|
|
# ClientReader
|
|
|
|
tests.addTest(unittest.makeSuite(clientreadertestcase.JailReaderTest))
|
2006-09-05 21:16:28 +00:00
|
|
|
# DateDetector
|
|
|
|
tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest))
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
# Tests runner
|
|
|
|
testRunner = unittest.TextTestRunner()
|
|
|
|
testRunner.run(tests)
|
2011-10-07 19:14:13 +00:00
|
|
|
|
|
|
|
# Just for the sake of it reset the TZ
|
|
|
|
# yoh is planing to move all this into setup/teardown methods within tests
|
|
|
|
os.environ.pop('TZ')
|
|
|
|
if old_TZ:
|
2011-10-07 19:47:50 +00:00
|
|
|
os.environ['TZ'] = old_TZ
|
2011-10-07 19:14:13 +00:00
|
|
|
time.tzset()
|