mirror of
https://github.com/certbot/certbot.git
synced 2026-08-04 08:03:44 +02:00
100% unittests for apache plugin
This commit is contained in:
@@ -114,7 +114,7 @@ class ApacheDvsni(common.Dvsni):
|
|||||||
|
|
||||||
# TODO: Checkout _default_ rules.
|
# TODO: Checkout _default_ rules.
|
||||||
dvsni_addrs = set()
|
dvsni_addrs = set()
|
||||||
default_addr = obj.Addr(("*", self.configurator.config.dvsni_port))
|
default_addr = obj.Addr(("*", str(self.configurator.config.dvsni_port)))
|
||||||
|
|
||||||
for addr in vhost.addrs:
|
for addr in vhost.addrs:
|
||||||
if "_default_" == addr.get_addr():
|
if "_default_" == addr.get_addr():
|
||||||
|
|||||||
@@ -118,11 +118,6 @@ class VirtualHost(object): # pylint: disable=too-few-public-methods
|
|||||||
self.ssl = ssl
|
self.ssl = ssl
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
|
|
||||||
def add_names(self, servername, serveralias):
|
|
||||||
"""Add name to vhost."""
|
|
||||||
self.name = servername
|
|
||||||
self.aliases = serveralias
|
|
||||||
|
|
||||||
def get_names(self):
|
def get_names(self):
|
||||||
"""Return a set of all names."""
|
"""Return a set of all names."""
|
||||||
all_names = set()
|
all_names = set()
|
||||||
|
|||||||
@@ -396,6 +396,9 @@ class ApacheParser(object):
|
|||||||
arg = os.path.normpath(os.path.join(self.root, arg))
|
arg = os.path.normpath(os.path.join(self.root, arg))
|
||||||
|
|
||||||
# Attempts to add a transform to the file if one does not already exist
|
# Attempts to add a transform to the file if one does not already exist
|
||||||
|
if os.path.isdir(arg):
|
||||||
|
self._parse_file(os.path.join(arg, "*"))
|
||||||
|
else:
|
||||||
self._parse_file(arg)
|
self._parse_file(arg)
|
||||||
|
|
||||||
# Argument represents an fnmatch regular expression, convert it
|
# Argument represents an fnmatch regular expression, convert it
|
||||||
@@ -409,11 +412,9 @@ class ApacheParser(object):
|
|||||||
split_arg[idx] = ("* [label()=~regexp('%s')]" %
|
split_arg[idx] = ("* [label()=~regexp('%s')]" %
|
||||||
self.fnmatch_to_re(split))
|
self.fnmatch_to_re(split))
|
||||||
# Reassemble the argument
|
# Reassemble the argument
|
||||||
|
# Note: This also normalizes the argument /serverroot/ -> /serverroot
|
||||||
arg = "/".join(split_arg)
|
arg = "/".join(split_arg)
|
||||||
|
|
||||||
# If the include is a directory, just return the directory as a file
|
|
||||||
if arg.endswith("/"):
|
|
||||||
return get_aug_path(arg[:-1])
|
|
||||||
return get_aug_path(arg)
|
return get_aug_path(arg)
|
||||||
|
|
||||||
def fnmatch_to_re(self, clean_fn_match): # pylint: disable=no-self-use
|
def fnmatch_to_re(self, clean_fn_match): # pylint: disable=no-self-use
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class ComplexParserTest(util.ParserTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_filter_args_num(self):
|
def test_filter_args_num(self):
|
||||||
|
"""Note: This may also fail do to Include conf-enabled/ syntax."""
|
||||||
matches = self.parser.find_dir("TestArgsDirective")
|
matches = self.parser.find_dir("TestArgsDirective")
|
||||||
|
|
||||||
self.assertEqual(len(self.parser.filter_args_num(matches, 1)), 3)
|
self.assertEqual(len(self.parser.filter_args_num(matches, 1)), 3)
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ import unittest
|
|||||||
import mock
|
import mock
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
from letsencrypt_apache.tests import util
|
|
||||||
|
|
||||||
from letsencrypt.display import util as display_util
|
from letsencrypt.display import util as display_util
|
||||||
|
|
||||||
|
from letsencrypt_apache import obj
|
||||||
|
|
||||||
|
from letsencrypt_apache.tests import util
|
||||||
|
|
||||||
|
|
||||||
class SelectVhostTest(unittest.TestCase):
|
class SelectVhostTest(unittest.TestCase):
|
||||||
"""Tests for letsencrypt_apache.display_ops.select_vhost."""
|
"""Tests for letsencrypt_apache.display_ops.select_vhost."""
|
||||||
@@ -53,6 +55,18 @@ class SelectVhostTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(mock_logger.debug.call_count, 1)
|
self.assertEqual(mock_logger.debug.call_count, 1)
|
||||||
|
|
||||||
|
@mock.patch("letsencrypt_apache.display_ops.zope.component.getUtility")
|
||||||
|
def test_multiple_names(self, mock_util):
|
||||||
|
mock_util().menu.return_value = (display_util.OK, 4)
|
||||||
|
|
||||||
|
self.vhosts.append(
|
||||||
|
obj.VirtualHost(
|
||||||
|
"path", "aug_path", set([obj.Addr.fromstring("*:80")]),
|
||||||
|
False, False,
|
||||||
|
"wildcard.com", set(["*.wildcard.com"])))
|
||||||
|
|
||||||
|
self.assertEqual(self.vhosts[4], self._call(self.vhosts))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main() # pragma: no cover
|
unittest.main() # pragma: no cover
|
||||||
|
|||||||
@@ -114,6 +114,17 @@ class DvsniPerformTest(util.ApacheTest):
|
|||||||
names == set([self.achalls[0].nonce_domain]) or
|
names == set([self.achalls[0].nonce_domain]) or
|
||||||
names == set([self.achalls[1].nonce_domain]))
|
names == set([self.achalls[1].nonce_domain]))
|
||||||
|
|
||||||
|
def test_get_dvsni_addrs_default(self):
|
||||||
|
self.sni.configurator.choose_vhost = mock.Mock(
|
||||||
|
return_value=obj.VirtualHost(
|
||||||
|
"path", "aug_path", set([obj.Addr.fromstring("_default_:443")]),
|
||||||
|
False, False)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
set([obj.Addr.fromstring("*:443")]),
|
||||||
|
self.sni.get_dvsni_addrs(self.achalls[0]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main() # pragma: no cover
|
unittest.main() # pragma: no cover
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ class BasicParserTest(util.ParserTest):
|
|||||||
shutil.rmtree(self.config_dir)
|
shutil.rmtree(self.config_dir)
|
||||||
shutil.rmtree(self.work_dir)
|
shutil.rmtree(self.work_dir)
|
||||||
|
|
||||||
|
def test_find_config_root_no_root(self):
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
os.remove(self.parser.loc["root"])
|
||||||
|
self.assertRaises(
|
||||||
|
errors.NoInstallationError, self.parser._find_config_root)
|
||||||
|
|
||||||
def test_parse_file(self):
|
def test_parse_file(self):
|
||||||
"""Test parse_file.
|
"""Test parse_file.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ IncludeOptional mods-enabled/*.conf
|
|||||||
</Directory>
|
</Directory>
|
||||||
|
|
||||||
# Include generic snippets of statements
|
# Include generic snippets of statements
|
||||||
IncludeOptional conf-enabled/*.conf
|
IncludeOptional conf-enabled/
|
||||||
|
|
||||||
# Include the virtual host configurations:
|
# Include the virtual host configurations:
|
||||||
IncludeOptional sites-enabled/*.conf
|
IncludeOptional sites-enabled/*.conf
|
||||||
|
|||||||
Reference in New Issue
Block a user