mirror of https://github.com/fail2ban/fail2ban
ENH: made log messages while parsing files more informative + test for inaccessible file (Closes: gh-24)
parent
5c9a9b1129
commit
2312b1d950
|
@ -56,7 +56,7 @@ class ConfigReader(SafeConfigParserWithIncludes):
|
|||
|
||||
def read(self, filename):
|
||||
basename = os.path.join(self._basedir, filename)
|
||||
logSys.debug("Reading " + basename)
|
||||
logSys.debug("Reading configs for %s under %s " % (basename, self._basedir))
|
||||
config_files = [ basename + ".conf",
|
||||
basename + ".local" ]
|
||||
|
||||
|
@ -88,7 +88,7 @@ class ConfigReader(SafeConfigParserWithIncludes):
|
|||
return True
|
||||
else:
|
||||
logSys.error("Found no accessible config files for %r " % filename
|
||||
+ (["",
|
||||
+ (["under %s" % self.getBaseDir(),
|
||||
"among existing ones: " + ', '.join(config_files)][bool(len(config_files))]))
|
||||
|
||||
return False
|
||||
|
|
|
@ -39,7 +39,6 @@ class ConfigReaderTest(unittest.TestCase):
|
|||
self.d = tempfile.mkdtemp(prefix="f2b-temp")
|
||||
self.c = ConfigReader(basedir=self.d)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
"""Call after every test case."""
|
||||
shutil.rmtree(self.d)
|
||||
|
@ -61,10 +60,19 @@ option = %s
|
|||
self.assertTrue(self.c.read('c')) # we still should have some
|
||||
|
||||
|
||||
def _getoption(self):
|
||||
self.assertTrue(self.c.read('c')) # we got some now
|
||||
def _getoption(self, f='c'):
|
||||
self.assertTrue(self.c.read(f)) # we got some now
|
||||
return self.c.getOptions('section', [("int", 'option')])['option']
|
||||
|
||||
|
||||
def testInaccessibleFile(self):
|
||||
f = os.path.join(self.d, "d.conf") # inaccessible file
|
||||
self._write('d.conf', 0)
|
||||
self.assertEqual(self._getoption('d'), 0)
|
||||
os.chmod(f, 0)
|
||||
self.assertFalse(self.c.read('d')) # should not be readable BUT present
|
||||
|
||||
|
||||
def testOptionalDotDDir(self):
|
||||
self.assertFalse(self.c.read('c')) # nothing is there yet
|
||||
self._write("c.conf", "1")
|
||||
|
|
Loading…
Reference in New Issue