mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
100% unittests for apache plugin
This commit is contained in:
parent
1ff899ae33
commit
ab42f7fdfe
8 changed files with 41 additions and 13 deletions
|
|
@ -114,7 +114,7 @@ class ApacheDvsni(common.Dvsni):
|
|||
|
||||
# TODO: Checkout _default_ rules.
|
||||
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:
|
||||
if "_default_" == addr.get_addr():
|
||||
|
|
|
|||
|
|
@ -118,11 +118,6 @@ class VirtualHost(object): # pylint: disable=too-few-public-methods
|
|||
self.ssl = ssl
|
||||
self.enabled = enabled
|
||||
|
||||
def add_names(self, servername, serveralias):
|
||||
"""Add name to vhost."""
|
||||
self.name = servername
|
||||
self.aliases = serveralias
|
||||
|
||||
def get_names(self):
|
||||
"""Return a set of all names."""
|
||||
all_names = set()
|
||||
|
|
|
|||
|
|
@ -396,7 +396,10 @@ class ApacheParser(object):
|
|||
arg = os.path.normpath(os.path.join(self.root, arg))
|
||||
|
||||
# Attempts to add a transform to the file if one does not already exist
|
||||
self._parse_file(arg)
|
||||
if os.path.isdir(arg):
|
||||
self._parse_file(os.path.join(arg, "*"))
|
||||
else:
|
||||
self._parse_file(arg)
|
||||
|
||||
# Argument represents an fnmatch regular expression, convert it
|
||||
# Split up the path and convert each into an Augeas accepted regex
|
||||
|
|
@ -409,11 +412,9 @@ class ApacheParser(object):
|
|||
split_arg[idx] = ("* [label()=~regexp('%s')]" %
|
||||
self.fnmatch_to_re(split))
|
||||
# Reassemble the argument
|
||||
# Note: This also normalizes the argument /serverroot/ -> /serverroot
|
||||
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)
|
||||
|
||||
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):
|
||||
"""Note: This may also fail do to Include conf-enabled/ syntax."""
|
||||
matches = self.parser.find_dir("TestArgsDirective")
|
||||
|
||||
self.assertEqual(len(self.parser.filter_args_num(matches, 1)), 3)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import unittest
|
|||
import mock
|
||||
import zope.component
|
||||
|
||||
from letsencrypt_apache.tests import util
|
||||
|
||||
from letsencrypt.display import util as display_util
|
||||
|
||||
from letsencrypt_apache import obj
|
||||
|
||||
from letsencrypt_apache.tests import util
|
||||
|
||||
|
||||
class SelectVhostTest(unittest.TestCase):
|
||||
"""Tests for letsencrypt_apache.display_ops.select_vhost."""
|
||||
|
|
@ -53,6 +55,18 @@ class SelectVhostTest(unittest.TestCase):
|
|||
|
||||
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__":
|
||||
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[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__":
|
||||
unittest.main() # pragma: no cover
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ class BasicParserTest(util.ParserTest):
|
|||
shutil.rmtree(self.config_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):
|
||||
"""Test parse_file.
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ IncludeOptional mods-enabled/*.conf
|
|||
</Directory>
|
||||
|
||||
# Include generic snippets of statements
|
||||
IncludeOptional conf-enabled/*.conf
|
||||
IncludeOptional conf-enabled/
|
||||
|
||||
# Include the virtual host configurations:
|
||||
IncludeOptional sites-enabled/*.conf
|
||||
|
|
|
|||
Loading…
Reference in a new issue