mirror of https://github.com/fail2ban/fail2ban
TST: Added some more tests for Python actions
parent
69a850d226
commit
cfcf841ae4
|
@ -55,6 +55,10 @@ class ExecuteActions(LogCaptureTestCase):
|
||||||
self.__ip.actioncheck = 'echo ip check <ip> >> "%s"' % self.__tmpfilename
|
self.__ip.actioncheck = 'echo ip check <ip> >> "%s"' % self.__tmpfilename
|
||||||
self.__ip.actionstop = 'echo ip stop >> "%s"' % self.__tmpfilename
|
self.__ip.actionstop = 'echo ip stop >> "%s"' % self.__tmpfilename
|
||||||
|
|
||||||
|
def testActionsAddDuplicateName(self):
|
||||||
|
self.__actions.add('test')
|
||||||
|
self.assertRaises(ValueError, self.__actions.add, 'test')
|
||||||
|
|
||||||
def testActionsManipulation(self):
|
def testActionsManipulation(self):
|
||||||
self.__actions.add('test')
|
self.__actions.add('test')
|
||||||
self.assertTrue(self.__actions['test'])
|
self.assertTrue(self.__actions['test'])
|
||||||
|
@ -115,3 +119,23 @@ class ExecuteActions(LogCaptureTestCase):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
TypeError, self.__actions.add, "Action5",
|
TypeError, self.__actions.add, "Action5",
|
||||||
os.path.join(TEST_FILES_DIR, "action.d/action.py"), {})
|
os.path.join(TEST_FILES_DIR, "action.d/action.py"), {})
|
||||||
|
|
||||||
|
def testAddPythonActionNOK(self):
|
||||||
|
self.assertRaises(RuntimeError, self.__actions.add,
|
||||||
|
"Action", os.path.join(TEST_FILES_DIR,
|
||||||
|
"action.d/action_noAction.py"),
|
||||||
|
{})
|
||||||
|
self.assertRaises(RuntimeError, self.__actions.add,
|
||||||
|
"Action", os.path.join(TEST_FILES_DIR,
|
||||||
|
"action.d/action_nomethod.py"),
|
||||||
|
{})
|
||||||
|
self.__actions.add(
|
||||||
|
"Action", os.path.join(TEST_FILES_DIR,
|
||||||
|
"action.d/action_errors.py"),
|
||||||
|
{})
|
||||||
|
self.__actions.start()
|
||||||
|
time.sleep(3)
|
||||||
|
self.assertTrue(self._is_logged("Failed to start"))
|
||||||
|
self.__actions.stop()
|
||||||
|
self.__actions.join()
|
||||||
|
self.assertTrue(self._is_logged("Failed to stop"))
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
from fail2ban.server.action import ActionBase
|
||||||
|
|
||||||
|
class TestAction(ActionBase):
|
||||||
|
|
||||||
|
def __init__(self, jail, name):
|
||||||
|
super(TestAction, self).__init__(jail, name)
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
def ban(self):
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
def unban(self):
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
Action = TestAction
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
from fail2ban.server.action import ActionBase
|
||||||
|
|
||||||
|
class TestAction(ActionBase):
|
||||||
|
pass
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
from fail2ban.server.action import ActionBase
|
||||||
|
|
||||||
|
class TestAction():
|
||||||
|
|
||||||
|
def __init__(self, jail, name):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
Action = TestAction
|
Loading…
Reference in New Issue