Skip to content

Commit

Permalink
Enable Apache VirtualHost for HTTP challenge validation if not enable…
Browse files Browse the repository at this point in the history
…d already (#6268)

If user provides a custom --apache-vhost-root path that's not parsed by Apache per default, Certbot fails the challenge validation. While the VirtualHost on custom path is correctly found, and edited, it's still not seen by Apache. This PR adds a temporary Include directive to the root Apache configuration when writing the challenge tokens to the VirtualHost.
  • Loading branch information
joohoi authored and bmw committed Aug 1, 2018
1 parent f2bc876 commit f6219dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions certbot-apache/certbot_apache/http_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from certbot import errors
from certbot.plugins import common
from certbot_apache.obj import VirtualHost # pylint: disable=unused-import
from certbot_apache.parser import get_aug_path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -172,4 +173,9 @@ def _set_up_include_directives(self, vhost):
self.configurator.parser.add_dir(
vhost.path, "Include", self.challenge_conf_post)

if not vhost.enabled:
self.configurator.parser.add_dir(
get_aug_path(self.configurator.parser.loc["default"]),
"Include", vhost.filep)

self.moded_vhosts.add(vhost)
16 changes: 16 additions & 0 deletions certbot-apache/certbot_apache/tests/http_01_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from certbot import errors

from certbot.tests import acme_util
from certbot_apache.parser import get_aug_path
from certbot_apache.tests import util


Expand Down Expand Up @@ -134,6 +135,21 @@ def test_perform_3_achall_apache_2_2(self):
def test_perform_3_achall_apache_2_4(self):
self.combinations_perform_test(num_achalls=3, minor_version=4)

def test_activate_disabled_vhost(self):
vhosts = [v for v in self.config.vhosts if v.name == "certbot.demo"]
achalls = [
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(token=((b'a' * 16))),
"pending"),
domain="certbot.demo", account_key=self.account_key)]
vhosts[0].enabled = False
self.common_perform_test(achalls, vhosts)
matches = self.config.parser.find_dir(
"Include", vhosts[0].filep,
get_aug_path(self.config.parser.loc["default"]))
self.assertEqual(len(matches), 1)

def combinations_perform_test(self, num_achalls, minor_version):
"""Test perform with the given achall count and Apache version."""
achalls = self.achalls[:num_achalls]
Expand Down

0 comments on commit f6219dd

Please sign in to comment.