mirror of https://github.com/fail2ban/fail2ban
ENH: FilterReader - use the set methods (improve coverage), test getters, use os.path.join
parent
0141a6dbe7
commit
4e165c9692
|
@ -24,6 +24,7 @@ __author__ = "Cyril Jaquier"
|
|||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||
__license__ = "GPL"
|
||||
|
||||
import os
|
||||
import logging
|
||||
from configreader import ConfigReader
|
||||
|
||||
|
@ -34,11 +35,14 @@ class FilterReader(ConfigReader):
|
|||
|
||||
def __init__(self, fileName, name, **kwargs):
|
||||
ConfigReader.__init__(self, **kwargs)
|
||||
self.__file = fileName
|
||||
self.__name = name
|
||||
# Defer initialization to the set Methods
|
||||
self.__file = self.__name = self.__opts = None
|
||||
self.setFile(fileName)
|
||||
self.setName(name)
|
||||
|
||||
def setFile(self, fileName):
|
||||
self.__file = fileName
|
||||
self.__opts = None
|
||||
|
||||
def getFile(self):
|
||||
return self.__file
|
||||
|
@ -50,7 +54,7 @@ class FilterReader(ConfigReader):
|
|||
return self.__name
|
||||
|
||||
def read(self):
|
||||
return ConfigReader.read(self, "filter.d/" + self.__file)
|
||||
return ConfigReader.read(self, os.path.join("filter.d", self.__file))
|
||||
|
||||
def getOptions(self, pOpts):
|
||||
opts = [["string", "ignoreregex", ""],
|
||||
|
|
|
@ -60,6 +60,8 @@ def testSampleRegexsFactory(name):
|
|||
|
||||
# Check filter exists
|
||||
filterConf = FilterReader(name, "jail", basedir=CONFIG_DIR)
|
||||
self.assertEqual(filterConf.getFile(), name)
|
||||
self.assertEqual(filterConf.getName(), "jail")
|
||||
filterConf.read()
|
||||
filterConf.getOptions({})
|
||||
|
||||
|
|
Loading…
Reference in New Issue