From 571ff33fde2c43b47c9a22ebdff020bdf77a3c17 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 12 May 2013 22:19:17 -0400 Subject: [PATCH] ENH: issue a warning if jail name is longer than 19 symbols (Close #222) --- fail2ban-testcases | 1 + server/jail.py | 6 +++++- testcases/servertestcase.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 5ad7494e..0bd70259 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -140,6 +140,7 @@ else: # pragma: no cover # Server #tests.addTest(unittest.makeSuite(servertestcase.StartStop)) tests.addTest(unittest.makeSuite(servertestcase.Transmitter)) +tests.addTest(unittest.makeSuite(servertestcase.JailTests)) tests.addTest(unittest.makeSuite(actiontestcase.ExecuteAction)) # FailManager tests.addTest(unittest.makeSuite(failmanagertestcase.AddFailure)) diff --git a/server/jail.py b/server/jail.py index dee64e7f..5e60ec7f 100644 --- a/server/jail.py +++ b/server/jail.py @@ -38,7 +38,7 @@ class Jail: _BACKENDS = ['pyinotify', 'gamin', 'polling'] def __init__(self, name, backend = "auto"): - self.__name = name + self.setName(name) self.__queue = Queue.Queue() self.__filter = None logSys.info("Creating new jail '%s'" % self.__name) @@ -102,6 +102,10 @@ class Jail: self.__filter = FilterPyinotify(self) def setName(self, name): + if len(name) >= 20: + logSys.warning("Jail name %r might be too long and some commands " + "might not function correctly. Please shorten" + % name) self.__name = name def getName(self): diff --git a/testcases/servertestcase.py b/testcases/servertestcase.py index ff3f2e88..0a5593e3 100644 --- a/testcases/servertestcase.py +++ b/testcases/servertestcase.py @@ -26,6 +26,7 @@ __license__ = "GPL" import unittest, socket, time, tempfile, os from server.server import Server +from server.jail import Jail from common.exceptions import UnknownJailException class StartStop(unittest.TestCase): @@ -507,3 +508,12 @@ class TransmitterLogging(TransmitterBase): self.setGetTest("loglevel", "-1", -1) self.setGetTest("loglevel", "0", 0) self.setGetTestNOK("loglevel", "Bird") + + +class JailTests(unittest.TestCase): + + def testLongName(self): + # Just a smoke test for now + longname = "veryveryverylongname" + jail = Jail(longname) + self.assertEqual(jail.getName(), longname)