mirror of
https://github.com/certbot/certbot.git
synced 2026-06-08 08:12:15 -04:00
Merge branch 'apache-http-01' of github.com:certbot/certbot into apache-http-01
This commit is contained in:
commit
6dd724e1f4
2 changed files with 25 additions and 4 deletions
|
|
@ -2,6 +2,8 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
from certbot import errors
|
||||
|
||||
from certbot.plugins import common
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -79,9 +81,8 @@ class ApacheHttp01(common.TLSSNI01):
|
|||
if vh:
|
||||
self._set_up_include_directive(vh)
|
||||
else:
|
||||
for vh in self.configurator.vhosts:
|
||||
if not vh.ssl:
|
||||
self._set_up_include_directive(vh)
|
||||
for vh in self._relevant_vhosts():
|
||||
self._set_up_include_directive(vh)
|
||||
|
||||
self.configurator.reverter.register_file_creation(
|
||||
True, self.challenge_conf)
|
||||
|
|
@ -97,6 +98,19 @@ class ApacheHttp01(common.TLSSNI01):
|
|||
with open(self.challenge_conf, "w") as new_conf:
|
||||
new_conf.write(config_text)
|
||||
|
||||
def _relevant_vhosts(self):
|
||||
http01_port = str(self.configurator.config.http01_port)
|
||||
relevant_vhosts = []
|
||||
for vhost in self.configurator.vhosts:
|
||||
if any(a.is_wildcard() or a.get_port() == http01_port for a in vhost.addrs):
|
||||
if not vhost.ssl:
|
||||
relevant_vhosts.append(vhost)
|
||||
if not relevant_vhosts:
|
||||
raise errors.PluginError(
|
||||
"Unable to find a virtual host listening on port {0}."
|
||||
" Please add one.".format(http01_port))
|
||||
|
||||
return relevant_vhosts
|
||||
|
||||
def _set_up_challenges(self):
|
||||
if not os.path.isdir(self.challenge_dir):
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import unittest
|
|||
from acme import challenges
|
||||
|
||||
from certbot import achallenges
|
||||
from certbot import errors
|
||||
|
||||
from certbot.tests import acme_util
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ class ApacheHttp01Test(util.ApacheTest):
|
|||
self.achalls.append(
|
||||
achallenges.KeyAuthorizationAnnotatedChallenge(
|
||||
challb=acme_util.chall_to_challb(
|
||||
challenges.HTTP01(token=((chr(ord('a') + i) * 16))),
|
||||
challenges.HTTP01(token=((chr(ord('a') + i).encode() * 16))),
|
||||
"pending"),
|
||||
domain=domain, account_key=self.account_key))
|
||||
|
||||
|
|
@ -139,6 +140,12 @@ class ApacheHttp01Test(util.ApacheTest):
|
|||
domain="something.nonexistent", account_key=self.account_key)]
|
||||
self.common_perform_test(achalls, vhosts)
|
||||
|
||||
def test_no_vhost(self):
|
||||
for achall in self.achalls:
|
||||
self.http.add_chall(achall)
|
||||
self.config.config.http01_port = 12345
|
||||
self.assertRaises(errors.PluginError, self.http.perform)
|
||||
|
||||
def common_perform_test(self, achalls, vhosts):
|
||||
"""Tests perform with the given achalls."""
|
||||
challenge_dir = self.http.challenge_dir
|
||||
|
|
|
|||
Loading…
Reference in a new issue