From b30a5e5b738f812c23937ea63eedb6443f7b98fd Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Wed, 27 Mar 2019 19:10:52 +0200 Subject: [PATCH] Add a test to ensure test coverage regardless of the vhost order (#6873) Add a new test to make sure that we are covering all the branches of get_virtual_hosts() regardless of the order that Augeas returns the found VirtualHost paths. Fixes: #6813 * Add a test to ensure test coverage regardless of the order of returned vhosts * Use deepcopy instead, and increase coverage requirement back to 100% --- .../certbot_apache/tests/configurator_test.py | 24 +++++++++++++++++++ tox.cover.py | 5 +--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/certbot-apache/certbot_apache/tests/configurator_test.py b/certbot-apache/certbot_apache/tests/configurator_test.py index a8d5dd96e..884e82cb3 100644 --- a/certbot-apache/certbot_apache/tests/configurator_test.py +++ b/certbot-apache/certbot_apache/tests/configurator_test.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-public-methods,too-many-lines """Test for certbot_apache.configurator.""" +import copy import os import shutil import socket @@ -1512,6 +1513,29 @@ class MultipleVhostsTest(util.ApacheTest): second_id = self.config.add_vhost_id(self.vh_truth[0]) self.assertEqual(first_id, second_id) + def test_realpath_replaces_symlink(self): + orig_match = self.config.aug.match + mock_vhost = copy.deepcopy(self.vh_truth[0]) + mock_vhost.filep = mock_vhost.filep.replace('sites-enabled', u'sites-available') + mock_vhost.path = mock_vhost.path.replace('sites-enabled', 'sites-available') + mock_vhost.enabled = False + self.config.parser.parse_file(mock_vhost.filep) + + def mock_match(aug_expr): + """Return a mocked match list of VirtualHosts""" + if "/mocked/path" in aug_expr: + return [self.vh_truth[1].path, self.vh_truth[0].path, mock_vhost.path] + return orig_match(aug_expr) + + self.config.parser.parser_paths = ["/mocked/path"] + self.config.aug.match = mock_match + vhs = self.config.get_virtual_hosts() + self.assertEqual(len(vhs), 2) + self.assertTrue(vhs[0] == self.vh_truth[1]) + # mock_vhost should have replaced the vh_truth[0], because its filepath + # isn't a symlink + self.assertTrue(vhs[1] == mock_vhost) + class AugeasVhostsTest(util.ApacheTest): """Test vhosts with illegal names dependent on augeas version.""" diff --git a/tox.cover.py b/tox.cover.py index 6f5392b71..d0f97626a 100755 --- a/tox.cover.py +++ b/tox.cover.py @@ -14,10 +14,7 @@ DEFAULT_PACKAGES = [ COVER_THRESHOLDS = { 'certbot': {'linux': 98, 'windows': 93}, 'acme': {'linux': 100, 'windows': 99}, - # certbot_apache coverage not being at 100% is a workaround for - # https://github.com/certbot/certbot/issues/6813. We should increase - # the minimum coverage back to 100% when this issue is resolved. - 'certbot_apache': {'linux': 99, 'windows': 99}, + 'certbot_apache': {'linux': 100, 'windows': 100}, 'certbot_dns_cloudflare': {'linux': 98, 'windows': 98}, 'certbot_dns_cloudxns': {'linux': 99, 'windows': 99}, 'certbot_dns_digitalocean': {'linux': 98, 'windows': 98},