From 414c5e1146cc2427cbefeb1d7a66f26169d7b5c9 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 2 Jan 2014 15:51:30 +0000 Subject: [PATCH] BF: Stop actName being passed to python actions --- fail2ban/client/jailreader.py | 2 +- fail2ban/tests/clientreadertestcase.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fail2ban/client/jailreader.py b/fail2ban/client/jailreader.py index ab3e0aee..c6248fb9 100644 --- a/fail2ban/client/jailreader.py +++ b/fail2ban/client/jailreader.py @@ -126,7 +126,7 @@ class JailReader(ConfigReader): "set", self.__name, "addaction", - actOpt.get("actname", os.path.splitext(actName)[0]), + actOpt.pop("actname", os.path.splitext(actName)[0]), os.path.join( self.getBaseDir(), "action.d", actName), json.dumps(actOpt), diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 647b9f86..99cb3379 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -539,6 +539,8 @@ class JailsReaderTest(LogCaptureTestCase): [testjail1] action = testaction1[actname=test1] testaction1[actname=test2] + testaction.py + testaction.py[actname=test3] filter = testfilter1 """) jailfd.close() @@ -547,8 +549,12 @@ filter = testfilter1 self.assertTrue(jails.getOptions()) comm_commands = jails.convert(allow_no_files=True) - action_names = [comm[-1] for comm in comm_commands if comm[:3] == ['set', 'testjail1', 'addaction']] + add_actions = [comm[3:] for comm in comm_commands + if comm[:3] == ['set', 'testjail1', 'addaction']] - self.assertNotEqual(len(set(action_names)), 1) + self.assertEqual(len(set(action[0] for action in add_actions)), 4) + + # Python actions should not be passed `actname` + self.assertEqual(add_actions[-1][-1], "{}") shutil.rmtree(basedir)