mirror of https://github.com/fail2ban/fail2ban
test case for generic common moved to `./fail2ban/tests/config/filter.d/zzz-generic-example.conf` to prevent shipping it with fail2ban installations
parent
cb4f9be8b2
commit
25af11215b
|
@ -600,10 +600,9 @@ class JailsReaderTest(LogCaptureTestCase):
|
||||||
self.assertTrue(jails.read()) # opens fine
|
self.assertTrue(jails.read()) # opens fine
|
||||||
self.assertTrue(jails.getOptions()) # reads fine
|
self.assertTrue(jails.getOptions()) # reads fine
|
||||||
# grab all filter names
|
# grab all filter names
|
||||||
filters = (os.path.splitext(os.path.split(flt)[1])[0]
|
filters = set(os.path.splitext(os.path.split(a)[1])[0]
|
||||||
for flt in glob.glob(os.path.join('config', 'filter.d', '*.conf'))
|
for a in glob.glob(os.path.join('config', 'filter.d', '*.conf'))
|
||||||
if not flt.endswith('common.conf'))
|
if not a.endswith('common.conf'))
|
||||||
filters = set(filter(lambda flt: not flt.startswith('zzz-'), filters))
|
|
||||||
# get filters of all jails (filter names without options inside filter[...])
|
# get filters of all jails (filter names without options inside filter[...])
|
||||||
filters_jail = set(
|
filters_jail = set(
|
||||||
JailReader.extractOptions(jail.options['filter'])[0] for jail in jails.jails
|
JailReader.extractOptions(jail.options['filter'])[0] for jail in jails.jails
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
# Read common prefixes. If any customizations available -- read them from
|
# Read common prefixes. If any customizations available -- read them from
|
||||||
# common.local
|
# common.local
|
||||||
before = common.conf
|
before = ../../../../config/filter.d/common.conf
|
||||||
|
|
||||||
[Definition]
|
[Definition]
|
||||||
|
|
|
@ -35,6 +35,7 @@ from ..server.filter import Filter
|
||||||
from ..client.filterreader import FilterReader
|
from ..client.filterreader import FilterReader
|
||||||
from .utils import setUpMyTime, tearDownMyTime, CONFIG_DIR
|
from .utils import setUpMyTime, tearDownMyTime, CONFIG_DIR
|
||||||
|
|
||||||
|
TEST_CONFIG_DIR = os.path.join(os.path.dirname(__file__), "config")
|
||||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
|
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,11 +61,11 @@ class FilterSamplesRegex(unittest.TestCase):
|
||||||
"Expected more FilterSampleRegexs tests")
|
"Expected more FilterSampleRegexs tests")
|
||||||
|
|
||||||
|
|
||||||
def testSampleRegexsFactory(name):
|
def testSampleRegexsFactory(name, basedir):
|
||||||
def testFilter(self):
|
def testFilter(self):
|
||||||
|
|
||||||
# Check filter exists
|
# Check filter exists
|
||||||
filterConf = FilterReader(name, "jail", {}, basedir=CONFIG_DIR)
|
filterConf = FilterReader(name, "jail", {}, basedir=basedir)
|
||||||
self.assertEqual(filterConf.getFile(), name)
|
self.assertEqual(filterConf.getFile(), name)
|
||||||
self.assertEqual(filterConf.getJailName(), "jail")
|
self.assertEqual(filterConf.getJailName(), "jail")
|
||||||
filterConf.read()
|
filterConf.read()
|
||||||
|
@ -147,11 +148,15 @@ def testSampleRegexsFactory(name):
|
||||||
|
|
||||||
return testFilter
|
return testFilter
|
||||||
|
|
||||||
for filter_ in filter(lambda x: not x.endswith('common.conf') and x.endswith('.conf'),
|
for basedir_, filter_ in (
|
||||||
os.listdir(os.path.join(CONFIG_DIR, "filter.d"))):
|
(CONFIG_DIR, lambda x: not x.endswith('common.conf') and x.endswith('.conf')),
|
||||||
filterName = filter_.rpartition(".")[0]
|
(TEST_CONFIG_DIR, lambda x: x.startswith('zzz-') and x.endswith('.conf')),
|
||||||
if not filterName.startswith('.'):
|
):
|
||||||
setattr(
|
for filter_ in filter(filter_,
|
||||||
FilterSamplesRegex,
|
os.listdir(os.path.join(basedir_, "filter.d"))):
|
||||||
"testSampleRegexs%s" % filterName.upper(),
|
filterName = filter_.rpartition(".")[0]
|
||||||
testSampleRegexsFactory(filterName))
|
if not filterName.startswith('.'):
|
||||||
|
setattr(
|
||||||
|
FilterSamplesRegex,
|
||||||
|
"testSampleRegexs%s" % filterName.upper(),
|
||||||
|
testSampleRegexsFactory(filterName, basedir_))
|
||||||
|
|
Loading…
Reference in New Issue