From 7a29a952c133ab54ae69159636b291b70f2ae846 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 25 Apr 2013 22:29:50 +0100 Subject: [PATCH] TST: Add test case for jails with multiple of the same action --- fail2ban/tests/clientreadertestcase.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 62d994c8..1f766fc6 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -302,3 +302,26 @@ class JailsReaderTest(unittest.TestCase): configurator._Configurator__jails.setBaseDir('/tmp') self.assertEqual(configurator._Configurator__jails.getBaseDir(), '/tmp') self.assertEqual(configurator.getBaseDir(), CONFIG_DIR) + + def testMultipleSameAction(self): + basedir = tempfile.mkdtemp("fail2ban_conf") + os.mkdir(os.path.join(basedir, "filter.d")) + os.mkdir(os.path.join(basedir, "action.d")) + open(os.path.join(basedir, "action.d", "testaction1.conf"), 'w').close() + open(os.path.join(basedir, "filter.d", "testfilter1.conf"), 'w').close() + jailfd = open(os.path.join(basedir, "jail.conf"), 'w') + jailfd.write(""" +[testjail1] +action = testaction1[name=test1] + testaction1[name=test2] +filter = testfilter1 +""") + jailfd.close() + jails = JailsReader(basedir=basedir) + self.assertTrue(jails.read()) + self.assertTrue(jails.getOptions()) + comm_commands = jails.convert() + + action_names = [comm[-1] for comm in comm_commands if comm[:3] == ['set', 'testjail1', 'addaction']] + + self.assertNotEqual(len(set(action_names)), 1)