- Bug fix: '-', '_' and '.' are valid as action file

- Added a pyunit test

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@266 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2006-08-06 21:56:01 +00:00
parent 6ff620e7a2
commit 8af85f5c40
3 changed files with 49 additions and 3 deletions

View File

@ -88,7 +88,7 @@ class JailReader(ConfigReader):
@staticmethod
def splitAction(action):
m = re.match("^(\w+)(?:\[(.*)\])?$", action)
m = re.match("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$", action)
d = dict()
if m.group(2) <> None:
for param in m.group(2).split(','):

View File

@ -33,10 +33,11 @@ import unittest, logging, sys
sys.path.insert(1, "/usr/lib/fail2ban")
from version import version
from testcases import banmanagertestcase
from testcases import clientreadertestcase
from testcases import failmanagertestcase
from testcases import filtertestcase
from testcases import servertestcase
from testcases import failmanagertestcase
from testcases import banmanagertestcase
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
@ -60,6 +61,8 @@ tests.addTest(unittest.makeSuite(filtertestcase.GetFailures))
tests.addTest(unittest.makeSuite(failmanagertestcase.AddFailure))
# BanManager
tests.addTest(unittest.makeSuite(banmanagertestcase.AddFailure))
# ClientReader
tests.addTest(unittest.makeSuite(clientreadertestcase.JailReaderTest))
# Tests runner
testRunner = unittest.TextTestRunner()

View File

@ -0,0 +1,43 @@
# 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
#
# $Revision: 253 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 253 $"
__date__ = "$Date: 2006-07-17 00:21:58 +0200 (Mon, 17 Jul 2006) $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
import unittest
from client.jailreader import JailReader
class JailReaderTest(unittest.TestCase):
def setUp(self):
"""Call before every test case."""
def tearDown(self):
"""Call after every test case."""
def testSplitAction(self):
action = "mail-whois[name=SSH]"
expected = ['mail-whois', {'name': 'SSH'}]
result = JailReader.splitAction(action)
self.assertEquals(expected, result)