From 8af85f5c401d652d564f521e9a5d25930f41c578 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 6 Aug 2006 21:56:01 +0000 Subject: [PATCH] - 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 --- client/jailreader.py | 2 +- fail2ban-testcases | 7 +++-- testcases/clientreadertestcase.py | 43 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 testcases/clientreadertestcase.py diff --git a/client/jailreader.py b/client/jailreader.py index 3b2fb0fb..0054b0d1 100644 --- a/client/jailreader.py +++ b/client/jailreader.py @@ -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(','): diff --git a/fail2ban-testcases b/fail2ban-testcases index cdbd2197..8391c3ca 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -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() diff --git a/testcases/clientreadertestcase.py b/testcases/clientreadertestcase.py new file mode 100644 index 00000000..c1b1eddf --- /dev/null +++ b/testcases/clientreadertestcase.py @@ -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) + \ No newline at end of file