mirror of https://github.com/fail2ban/fail2ban
fix: fail2ban-regex with filter file failed (after merging #824, because test case missing);
test case for 'readexplicit' added;pull/830/head
parent
e2f49b7334
commit
0b0ea41f87
|
@ -267,7 +267,9 @@ class DefinitionInitConfigReader(ConfigReader):
|
||||||
|
|
||||||
# needed for fail2ban-regex that doesn't need fancy directories
|
# needed for fail2ban-regex that doesn't need fancy directories
|
||||||
def readexplicit(self):
|
def readexplicit(self):
|
||||||
return SafeConfigParserWithIncludes.read(self, self._file)
|
if not self._cfg:
|
||||||
|
self.touch(self._file)
|
||||||
|
return SafeConfigParserWithIncludes.read(self._cfg, self._file)
|
||||||
|
|
||||||
def getOptions(self, pOpts):
|
def getOptions(self, pOpts):
|
||||||
self._opts = ConfigReader.getOptions(
|
self._opts = ConfigReader.getOptions(
|
||||||
|
|
|
@ -334,6 +334,22 @@ class FilterReaderTest(unittest.TestCase):
|
||||||
filterReader.getOptions(None)
|
filterReader.getOptions(None)
|
||||||
self.assertRaises(ValueError, FilterReader.convert, filterReader)
|
self.assertRaises(ValueError, FilterReader.convert, filterReader)
|
||||||
|
|
||||||
|
def testFilterReaderExplicit(self):
|
||||||
|
# read explicit uses absolute path:
|
||||||
|
path_ = os.path.abspath(os.path.join(TEST_FILES_DIR, "filter.d"))
|
||||||
|
filterReader = FilterReader(os.path.join(path_, "testcase01.conf"), "testcase01", {})
|
||||||
|
self.assertEqual(filterReader.readexplicit(),
|
||||||
|
[os.path.join(path_, "testcase-common.conf"), os.path.join(path_, "testcase01.conf")]
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
filterReader.getOptions(None)
|
||||||
|
# from included common
|
||||||
|
filterReader.get('Definition', '__prefix_line')
|
||||||
|
# from testcase01
|
||||||
|
filterReader.get('Definition', 'failregex')
|
||||||
|
filterReader.get('Definition', 'ignoreregex')
|
||||||
|
except Exception, e:
|
||||||
|
self.fail('unexpected options after readexplicit: %s' % (e))
|
||||||
|
|
||||||
class JailsReaderTestCache(LogCaptureTestCase):
|
class JailsReaderTestCache(LogCaptureTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue