ENH: issue a warning if jail name is longer than 19 symbols (Close #222)

pull/227/head
Yaroslav Halchenko 2013-05-12 22:19:17 -04:00
parent 90b8433ac5
commit 571ff33fde
3 changed files with 16 additions and 1 deletions

View File

@ -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))

View File

@ -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):

View File

@ -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)