mirror of
https://github.com/certbot/certbot.git
synced 2026-04-15 22:20:28 -04:00
Handle NoneType from Augeas better in Apache parser get_arg (#5135)
* Fix #4245 * Simpler, more accurate test * Do not add empty values to parser modules * Py26 fix
This commit is contained in:
parent
5f6b1378ec
commit
46052f826c
2 changed files with 26 additions and 4 deletions
|
|
@ -123,9 +123,14 @@ class ApacheParser(object):
|
|||
|
||||
for match_name, match_filename in six.moves.zip(
|
||||
iterator, iterator):
|
||||
self.modules.add(self.get_arg(match_name))
|
||||
self.modules.add(
|
||||
os.path.basename(self.get_arg(match_filename))[:-2] + "c")
|
||||
mod_name = self.get_arg(match_name)
|
||||
mod_filename = self.get_arg(match_filename)
|
||||
if mod_name and mod_filename:
|
||||
self.modules.add(mod_name)
|
||||
self.modules.add(os.path.basename(mod_filename)[:-2] + "c")
|
||||
else:
|
||||
logger.debug("Could not read LoadModule directive from " +
|
||||
"Augeas path: {0}".format(match_name[6:]))
|
||||
|
||||
def update_runtime_variables(self):
|
||||
""""
|
||||
|
|
@ -371,7 +376,10 @@ class ApacheParser(object):
|
|||
|
||||
# Note: normal argument may be a quoted variable
|
||||
# e.g. strip now, not later
|
||||
value = value.strip("'\"")
|
||||
if not value:
|
||||
return None
|
||||
else:
|
||||
value = value.strip("'\"")
|
||||
|
||||
variables = ApacheParser.arg_var_interpreter.findall(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ class BasicParserTest(util.ParserTest):
|
|||
for i, match in enumerate(matches):
|
||||
self.assertEqual(self.parser.aug.get(match), str(i + 1))
|
||||
|
||||
def test_empty_arg(self):
|
||||
self.assertEquals(None,
|
||||
self.parser.get_arg("/files/whatever/nonexistent"))
|
||||
|
||||
def test_add_dir_to_ifmodssl(self):
|
||||
"""test add_dir_to_ifmodssl.
|
||||
|
||||
|
|
@ -114,6 +118,16 @@ class BasicParserTest(util.ParserTest):
|
|||
self.assertEqual(results["default"], results["listen"])
|
||||
self.assertEqual(results["default"], results["name"])
|
||||
|
||||
@mock.patch("certbot_apache.parser.ApacheParser.find_dir")
|
||||
@mock.patch("certbot_apache.parser.ApacheParser.get_arg")
|
||||
def test_init_modules_bad_syntax(self, mock_arg, mock_find):
|
||||
mock_find.return_value = ["1", "2", "3", "4", "5", "6", "7", "8"]
|
||||
mock_arg.return_value = None
|
||||
with mock.patch("certbot_apache.parser.logger") as mock_logger:
|
||||
self.parser.init_modules()
|
||||
# Make sure that we got None return value and logged the file
|
||||
self.assertTrue(mock_logger.debug.called)
|
||||
|
||||
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg")
|
||||
def test_update_runtime_variables(self, mock_cfg):
|
||||
mock_cfg.return_value = (
|
||||
|
|
|
|||
Loading…
Reference in a new issue