TST+ENH: Move testcases to part of fail2ban module

This allows fail2ban-testcases to be run on an installed fail2ban
instance.
TODO: Fix tests requiring config files
pull/165/head
Steven Hiscocks 2013-04-01 11:22:40 +01:00
parent e53bfafd6a
commit e3bd2042eb
36 changed files with 45 additions and 35 deletions

View File

@ -42,20 +42,21 @@ fail2ban/server/banmanager.py
fail2ban/server/datetemplate.py fail2ban/server/datetemplate.py
fail2ban/server/mytime.py fail2ban/server/mytime.py
fail2ban/server/failregex.py fail2ban/server/failregex.py
testcases/files/testcase-usedns.log fail2ban/tests/banmanagertestcase.py
testcases/banmanagertestcase.py fail2ban/tests/failmanagertestcase.py
testcases/failmanagertestcase.py fail2ban/tests/clientreadertestcase.py
testcases/clientreadertestcase.py fail2ban/tests/filtertestcase.py
testcases/filtertestcase.py fail2ban/tests/__init__.py
testcases/__init__.py fail2ban/tests/datedetectortestcase.py
testcases/datedetectortestcase.py fail2ban/tests/actiontestcase.py
testcases/actiontestcase.py fail2ban/tests/servertestcase.py
testcases/servertestcase.py fail2ban/tests/sockettestcase.py
testcases/sockettestcase.py fail2ban/tests/utils.py
testcases/files/testcase01.log fail2ban/tests/files/testcase01.log
testcases/files/testcase02.log fail2ban/tests/files/testcase02.log
testcases/files/testcase03.log fail2ban/tests/files/testcase03.log
testcases/files/testcase04.log fail2ban/tests/files/testcase04.log
fail2ban/tests/files/testcase-usedns.log
setup.py setup.py
setup.cfg setup.cfg
fail2ban/__init__.py fail2ban/__init__.py

View File

@ -28,16 +28,16 @@ __license__ = "GPL"
import unittest, logging, sys, time, os import unittest, logging, sys, time, os
from fail2ban.version import version from fail2ban.version import version
from testcases import banmanagertestcase from fail2ban.tests import banmanagertestcase
from testcases import clientreadertestcase from fail2ban.tests import clientreadertestcase
from testcases import failmanagertestcase from fail2ban.tests import failmanagertestcase
from testcases import filtertestcase from fail2ban.tests import filtertestcase
from testcases import servertestcase from fail2ban.tests import servertestcase
from testcases import datedetectortestcase from fail2ban.tests import datedetectortestcase
from testcases import actiontestcase from fail2ban.tests import actiontestcase
from testcases import sockettestcase from fail2ban.tests import sockettestcase
from testcases.utils import FormatterWithTraceBack from fail2ban.tests.utils import FormatterWithTraceBack
from fail2ban.server.mytime import MyTime from fail2ban.server.mytime import MyTime
from optparse import OptionParser, Option from optparse import OptionParser, Option

View File

@ -35,6 +35,8 @@ from fail2ban.server.filter import FileFilter, DNSUtils
from fail2ban.server.failmanager import FailManager from fail2ban.server.failmanager import FailManager
from fail2ban.server.failmanager import FailManagerEmpty from fail2ban.server.failmanager import FailManagerEmpty
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
# #
# Useful helpers # Useful helpers
# #
@ -182,7 +184,7 @@ class IgnoreIP(unittest.TestCase):
class LogFile(unittest.TestCase): class LogFile(unittest.TestCase):
FILENAME = "testcases/files/testcase01.log" FILENAME = os.path.join(TEST_FILES_DIR, "testcase01.log")
def setUp(self): def setUp(self):
"""Call before every test case.""" """Call before every test case."""
@ -522,11 +524,11 @@ def get_monitor_failures_testcase(Filter_):
class GetFailures(unittest.TestCase): class GetFailures(unittest.TestCase):
FILENAME_01 = "testcases/files/testcase01.log" FILENAME_01 = os.path.join(TEST_FILES_DIR, "testcase01.log")
FILENAME_02 = "testcases/files/testcase02.log" FILENAME_02 = os.path.join(TEST_FILES_DIR, "testcase02.log")
FILENAME_03 = "testcases/files/testcase03.log" FILENAME_03 = os.path.join(TEST_FILES_DIR, "testcase03.log")
FILENAME_04 = "testcases/files/testcase04.log" FILENAME_04 = os.path.join(TEST_FILES_DIR, "testcase04.log")
FILENAME_USEDNS = "testcases/files/testcase-usedns.log" FILENAME_USEDNS = os.path.join(TEST_FILES_DIR, "testcase-usedns.log")
# so that they could be reused by other tests # so that they could be reused by other tests
FAILURES_01 = ('193.168.0.128', 3, 1124013599.0, FAILURES_01 = ('193.168.0.128', 3, 1124013599.0,

View File

@ -32,6 +32,8 @@ import unittest, socket, time, tempfile, os
from fail2ban.server.server import Server from fail2ban.server.server import Server
from fail2ban.exceptions import UnknownJailException from fail2ban.exceptions import UnknownJailException
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
class StartStop(unittest.TestCase): class StartStop(unittest.TestCase):
def setUp(self): def setUp(self):
@ -273,14 +275,14 @@ class Transmitter(TransmitterBase):
self.jailAddDelTest( self.jailAddDelTest(
"logpath", "logpath",
[ [
"testcases/files/testcase01.log", os.path.join(TEST_FILES_DIR, "testcase01.log"),
"testcases/files/testcase02.log", os.path.join(TEST_FILES_DIR, "testcase02.log"),
"testcases/files/testcase03.log", os.path.join(TEST_FILES_DIR, "testcase03.log"),
], ],
self.jailName self.jailName
) )
# Try duplicates # Try duplicates
value = "testcases/files/testcase04.log" value = os.path.join(TEST_FILES_DIR, "testcase04.log")
self.assertEqual( self.assertEqual(
self.transm.proceed(["set", self.jailName, "addlogpath", value]), self.transm.proceed(["set", self.jailName, "addlogpath", value]),
(0, [value])) (0, [value]))

View File

@ -49,13 +49,18 @@ setup(
scripts = [ scripts = [
'fail2ban-client', 'fail2ban-client',
'fail2ban-server', 'fail2ban-server',
'fail2ban-regex' 'fail2ban-regex',
'fail2ban-testcases',
], ],
packages = [ packages = [
'fail2ban', 'fail2ban',
'fail2ban.client', 'fail2ban.client',
'fail2ban.server' 'fail2ban.server',
'fail2ban.tests',
], ],
package_data = {
'fail2ban.tests': ['files/*.log'],
},
data_files = [ data_files = [
('/etc/fail2ban', ('/etc/fail2ban',
glob("config/*.conf") glob("config/*.conf")