mirror of
https://github.com/certbot/certbot.git
synced 2026-07-27 00:00:44 +02:00
Modifications needed for merging to master
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
""" apacheconfig implementation of the ParserNode interfaces """
|
||||
|
||||
from certbot_apache import assertions
|
||||
from certbot_apache import interfaces
|
||||
from certbot_apache import parsernode_util as util
|
||||
from certbot_apache._internal import assertions
|
||||
from certbot_apache._internal import interfaces
|
||||
from certbot_apache._internal import parsernode_util as util
|
||||
|
||||
|
||||
class ApacheParserNode(interfaces.ParserNode):
|
||||
@@ -73,9 +73,9 @@ class ApacheDirectiveNode(ApacheParserNode):
|
||||
self.metadata == other.metadata)
|
||||
return False
|
||||
|
||||
def set_parameters(self, parameters):
|
||||
def set_parameters(self, _parameters):
|
||||
"""Sets the parameters for DirectiveNode"""
|
||||
pass
|
||||
return
|
||||
|
||||
|
||||
class ApacheBlockNode(ApacheDirectiveNode):
|
||||
@@ -153,7 +153,7 @@ class ApacheBlockNode(ApacheDirectiveNode):
|
||||
|
||||
def delete_child(self, child): # pragma: no cover
|
||||
"""Deletes a ParserNode from the sequence of children"""
|
||||
pass
|
||||
return
|
||||
|
||||
def unsaved_files(self): # pragma: no cover
|
||||
"""Returns a list of unsaved filepaths"""
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Dual parser node assertions"""
|
||||
import fnmatch
|
||||
|
||||
from certbot_apache import interfaces
|
||||
from certbot_apache._internal import interfaces
|
||||
|
||||
|
||||
PASS = "CERTBOT_PASS_ASSERT"
|
||||
@@ -36,8 +36,8 @@ def assertEqualComment(first, second): # pragma: no cover
|
||||
assert isinstance(first, interfaces.CommentNode)
|
||||
assert isinstance(second, interfaces.CommentNode)
|
||||
|
||||
if not isPass(first.comment) and not isPass(second.comment):
|
||||
assert first.comment == second.comment
|
||||
if not isPass(first.comment) and not isPass(second.comment): # type: ignore
|
||||
assert first.comment == second.comment # type: ignore
|
||||
|
||||
def _assertEqualDirectiveComponents(first, second): # pragma: no cover
|
||||
""" Handles assertion for instance variables for DirectiveNode and BlockNode"""
|
||||
|
||||
@@ -68,11 +68,11 @@ from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-m
|
||||
from certbot import errors
|
||||
from certbot.compat import os
|
||||
|
||||
from certbot_apache import apache_util
|
||||
from certbot_apache import assertions
|
||||
from certbot_apache import interfaces
|
||||
from certbot_apache import parser
|
||||
from certbot_apache import parsernode_util as util
|
||||
from certbot_apache._internal import apache_util
|
||||
from certbot_apache._internal import assertions
|
||||
from certbot_apache._internal import interfaces
|
||||
from certbot_apache._internal import parser
|
||||
from certbot_apache._internal import parsernode_util as util
|
||||
|
||||
|
||||
class AugeasParserNode(interfaces.ParserNode):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
""" Dual ParserNode implementation """
|
||||
from certbot_apache import assertions
|
||||
from certbot_apache import augeasparser
|
||||
from certbot_apache import apacheparser
|
||||
from certbot_apache._internal import assertions
|
||||
from certbot_apache._internal import augeasparser
|
||||
from certbot_apache._internal import apacheparser
|
||||
|
||||
|
||||
class DualNodeBase(object):
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"""Tests for AugeasParserNode classes"""
|
||||
import mock
|
||||
|
||||
import util
|
||||
|
||||
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
|
||||
from certbot import errors
|
||||
|
||||
from certbot_apache import assertions
|
||||
from certbot_apache._internal import assertions
|
||||
|
||||
from certbot_apache.tests import util
|
||||
|
||||
|
||||
class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods
|
||||
@@ -21,19 +22,19 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
|
||||
self.temp_dir, "debian_apache_2_4/multiple_vhosts")
|
||||
|
||||
def test_save(self):
|
||||
with mock.patch('certbot_apache.parser.ApacheParser.save') as mock_save:
|
||||
with mock.patch('certbot_apache._internal.parser.ApacheParser.save') as mock_save:
|
||||
self.config.parser_root.save("A save message")
|
||||
self.assertTrue(mock_save.called)
|
||||
self.assertEqual(mock_save.call_args[0][0], "A save message")
|
||||
|
||||
def test_unsaved_files(self):
|
||||
with mock.patch('certbot_apache.parser.ApacheParser.unsaved_files') as mock_uf:
|
||||
with mock.patch('certbot_apache._internal.parser.ApacheParser.unsaved_files') as mock_uf:
|
||||
mock_uf.return_value = ["first", "second"]
|
||||
files = self.config.parser_root.unsaved_files()
|
||||
self.assertEqual(files, ["first", "second"])
|
||||
|
||||
def test_get_block_node_name(self):
|
||||
from certbot_apache.augeasparser import AugeasBlockNode
|
||||
from certbot_apache._internal.augeasparser import AugeasBlockNode
|
||||
block = AugeasBlockNode(
|
||||
name=assertions.PASS,
|
||||
ancestor=None,
|
||||
@@ -102,9 +103,9 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
|
||||
self.assertTrue("going_to_set_this" in names)
|
||||
|
||||
def test_set_parameters_atinit(self):
|
||||
from certbot_apache.augeasparser import AugeasDirectiveNode
|
||||
from certbot_apache._internal.augeasparser import AugeasDirectiveNode
|
||||
servernames = self.config.parser_root.find_directives("servername")
|
||||
setparam = "certbot_apache.augeasparser.AugeasDirectiveNode.set_parameters"
|
||||
setparam = "certbot_apache._internal.augeasparser.AugeasDirectiveNode.set_parameters"
|
||||
with mock.patch(setparam) as mock_set:
|
||||
AugeasDirectiveNode(
|
||||
name=servernames[0].name,
|
||||
@@ -241,7 +242,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
|
||||
self.assertTrue(vh.primary.metadata["augeaspath"].endswith("VirtualHost[2]"))
|
||||
|
||||
def test_node_init_error_bad_augeaspath(self):
|
||||
from certbot_apache.augeasparser import AugeasBlockNode
|
||||
from certbot_apache._internal.augeasparser import AugeasBlockNode
|
||||
parameters = {
|
||||
"name": assertions.PASS,
|
||||
"ancestor": None,
|
||||
@@ -258,7 +259,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
|
||||
)
|
||||
|
||||
def test_node_init_error_missing_augeaspath(self):
|
||||
from certbot_apache.augeasparser import AugeasBlockNode
|
||||
from certbot_apache._internal.augeasparser import AugeasBlockNode
|
||||
parameters = {
|
||||
"name": assertions.PASS,
|
||||
"ancestor": None,
|
||||
|
||||
@@ -106,7 +106,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
|
||||
def test_get_parser(self):
|
||||
self.assertIsInstance(self.config.parser, override_centos.CentOSParser)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
|
||||
define_val = (
|
||||
'Define: TEST1\n'
|
||||
@@ -155,7 +155,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
|
||||
raise Exception("Missed: %s" % vhost) # pragma: no cover
|
||||
self.assertEqual(found, 2)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_get_sysconfig_vars(self, mock_cfg):
|
||||
"""Make sure we read the sysconfig OPTIONS variable correctly"""
|
||||
# Return nothing for the process calls
|
||||
|
||||
@@ -76,7 +76,7 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser")
|
||||
@mock.patch("certbot_apache._internal.configurator.util.exe_exists")
|
||||
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.get_parsernode_root")
|
||||
def _test_prepare_locked(self, unused_parser, unused_exe_exists):
|
||||
def _test_prepare_locked(self, _node, _exists, _parser):
|
||||
try:
|
||||
self.config.prepare()
|
||||
except errors.PluginError as err:
|
||||
@@ -800,7 +800,7 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
self.assertEqual(mock_restart.call_count, 1)
|
||||
|
||||
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_cleanup(self, mock_cfg, mock_restart):
|
||||
mock_cfg.return_value = ""
|
||||
_, achalls = self.get_key_and_achalls()
|
||||
@@ -816,7 +816,7 @@ class MultipleVhostsTest(util.ApacheTest):
|
||||
self.assertFalse(mock_restart.called)
|
||||
|
||||
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_cleanup_no_errors(self, mock_cfg, mock_restart):
|
||||
mock_cfg.return_value = ""
|
||||
_, achalls = self.get_key_and_achalls()
|
||||
|
||||
@@ -46,7 +46,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
|
||||
|
||||
@mock.patch("certbot.util.run_script")
|
||||
@mock.patch("certbot.util.exe_exists")
|
||||
@mock.patch("certbot_apache._internal.parser.subprocess.Popen")
|
||||
@mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
|
||||
def test_enable_mod(self, mock_popen, mock_exe_exists, mock_run_script):
|
||||
mock_popen().communicate.return_value = ("Define: DUMP_RUN_CFG", "")
|
||||
mock_popen().returncode = 0
|
||||
|
||||
@@ -3,9 +3,9 @@ import unittest
|
||||
|
||||
import mock
|
||||
|
||||
from certbot_apache import assertions
|
||||
from certbot_apache import augeasparser
|
||||
from certbot_apache import dualparser
|
||||
from certbot_apache._internal import assertions
|
||||
from certbot_apache._internal import augeasparser
|
||||
from certbot_apache._internal import dualparser
|
||||
|
||||
|
||||
class DualParserNodeTest(unittest.TestCase): # pylint: disable=too-many-public-methods
|
||||
|
||||
@@ -100,7 +100,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
|
||||
def test_get_parser(self):
|
||||
self.assertIsInstance(self.config.parser, override_fedora.FedoraParser)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
|
||||
define_val = (
|
||||
'Define: TEST1\n'
|
||||
@@ -155,7 +155,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
|
||||
raise Exception("Missed: %s" % vhost) # pragma: no cover
|
||||
self.assertEqual(found, 2)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_get_sysconfig_vars(self, mock_cfg):
|
||||
"""Make sure we read the sysconfig OPTIONS variable correctly"""
|
||||
# Return nothing for the process calls
|
||||
|
||||
@@ -90,7 +90,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
|
||||
for define in defines:
|
||||
self.assertTrue(define in self.config.parser.variables.keys())
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser.parse_from_subprocess")
|
||||
@mock.patch("certbot_apache._internal.apache_util.parse_from_subprocess")
|
||||
def test_no_binary_configdump(self, mock_subprocess):
|
||||
"""Make sure we don't call binary dumps other than modules from Apache
|
||||
as this is not supported in Gentoo currently"""
|
||||
@@ -104,7 +104,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
|
||||
self.config.parser.reset_modules()
|
||||
self.assertTrue(mock_subprocess.called)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
|
||||
mod_val = (
|
||||
'Loaded Modules:\n'
|
||||
|
||||
@@ -165,7 +165,7 @@ class BasicParserTest(util.ParserTest):
|
||||
self.assertTrue(mock_logger.debug.called)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_update_runtime_variables(self, mock_cfg, _):
|
||||
define_val = (
|
||||
'ServerRoot: "/etc/apache2"\n'
|
||||
@@ -271,7 +271,7 @@ class BasicParserTest(util.ParserTest):
|
||||
self.assertEqual(mock_parse.call_count, 25)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_update_runtime_variables_alt_values(self, mock_cfg, _):
|
||||
inc_val = (
|
||||
'Included configuration files:\n'
|
||||
@@ -293,7 +293,7 @@ class BasicParserTest(util.ParserTest):
|
||||
# path derived from root configuration Include statements
|
||||
self.assertEqual(mock_parse.call_count, 1)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_update_runtime_vars_bad_output(self, mock_cfg):
|
||||
mock_cfg.return_value = "Define: TLS=443=24"
|
||||
self.parser.update_runtime_variables()
|
||||
@@ -303,7 +303,7 @@ class BasicParserTest(util.ParserTest):
|
||||
errors.PluginError, self.parser.update_runtime_variables)
|
||||
|
||||
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.option")
|
||||
@mock.patch("certbot_apache._internal.parser.subprocess.Popen")
|
||||
@mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
|
||||
def test_update_runtime_vars_bad_ctl(self, mock_popen, mock_opt):
|
||||
mock_popen.side_effect = OSError
|
||||
mock_opt.return_value = "nonexistent"
|
||||
@@ -311,7 +311,7 @@ class BasicParserTest(util.ParserTest):
|
||||
errors.MisconfigurationError,
|
||||
self.parser.update_runtime_variables)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.subprocess.Popen")
|
||||
@mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
|
||||
def test_update_runtime_vars_bad_exit(self, mock_popen):
|
||||
mock_popen().communicate.return_value = ("", "")
|
||||
mock_popen.returncode = -1
|
||||
@@ -355,7 +355,7 @@ class ParserInitTest(util.ApacheTest):
|
||||
ApacheParser, os.path.relpath(self.config_path),
|
||||
"/dummy/vhostpath", version=(2, 4, 22), configurator=self.config)
|
||||
|
||||
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
|
||||
@mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
|
||||
def test_unparseable(self, mock_cfg):
|
||||
from certbot_apache._internal.parser import ApacheParser
|
||||
mock_cfg.return_value = ('Define: TEST')
|
||||
|
||||
@@ -3,7 +3,7 @@ import unittest
|
||||
|
||||
import mock
|
||||
|
||||
from certbot_apache.tests import util
|
||||
import util
|
||||
|
||||
|
||||
class ConfiguratorParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from certbot_apache import interfaces
|
||||
from certbot_apache import parsernode_util as util
|
||||
from certbot_apache._internal import interfaces
|
||||
from certbot_apache._internal import parsernode_util as util
|
||||
|
||||
|
||||
class DummyParserNode(interfaces.ParserNode):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
""" Tests for ParserNode utils """
|
||||
import unittest
|
||||
|
||||
from certbot_apache import parsernode_util as util
|
||||
from certbot_apache._internal import parsernode_util as util
|
||||
|
||||
|
||||
class ParserNodeUtilTest(unittest.TestCase):
|
||||
|
||||
@@ -111,7 +111,7 @@ def get_apache_configurator(
|
||||
mock_exe_exists.return_value = True
|
||||
with mock.patch("certbot_apache._internal.parser.ApacheParser."
|
||||
"update_runtime_variables"):
|
||||
with mock.patch("certbot_apache.apache_util.parse_from_subprocess") as mock_sp:
|
||||
with mock.patch("certbot_apache._internal.apache_util.parse_from_subprocess") as mock_sp:
|
||||
mock_sp.return_value = []
|
||||
try:
|
||||
config_class = entrypoint.OVERRIDE_CLASSES[os_info]
|
||||
|
||||
Reference in New Issue
Block a user