Compare commits

...

5 Commits

Author SHA1 Message Date
Brad Warren
35727b3ccc fix type 2018-01-17 09:36:28 -08:00
Brad Warren
3864153db0 fix typo 2018-01-17 09:32:44 -08:00
Brad Warren
613d5eea05 fix typo 2018-01-17 09:30:53 -08:00
Brad Warren
d87cd3bca6 fix typo 2018-01-17 09:29:01 -08:00
Brad Warren
71d2e46f0d error with no vhost 2018-01-17 09:27:36 -08:00
2 changed files with 25 additions and 4 deletions

View File

@@ -2,6 +2,8 @@
import logging import logging
import os import os
from certbot import errors
from certbot.plugins import common from certbot.plugins import common
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -79,9 +81,8 @@ class ApacheHttp01(common.TLSSNI01):
if vh: if vh:
self._set_up_include_directive(vh) self._set_up_include_directive(vh)
else: else:
for vh in self.configurator.vhosts: for vh in self._relevant_vhosts():
if not vh.ssl: self._set_up_include_directive(vh)
self._set_up_include_directive(vh)
self.configurator.reverter.register_file_creation( self.configurator.reverter.register_file_creation(
True, self.challenge_conf) True, self.challenge_conf)
@@ -97,6 +98,19 @@ class ApacheHttp01(common.TLSSNI01):
with open(self.challenge_conf, "w") as new_conf: with open(self.challenge_conf, "w") as new_conf:
new_conf.write(config_text) 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): def _set_up_challenges(self):
if not os.path.isdir(self.challenge_dir): if not os.path.isdir(self.challenge_dir):

View File

@@ -6,6 +6,7 @@ import unittest
from acme import challenges from acme import challenges
from certbot import achallenges from certbot import achallenges
from certbot import errors
from certbot.tests import acme_util from certbot.tests import acme_util
@@ -63,7 +64,7 @@ class ApacheHttp01Test(util.ApacheTest):
self.achalls.append( self.achalls.append(
achallenges.KeyAuthorizationAnnotatedChallenge( achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb( challb=acme_util.chall_to_challb(
challenges.HTTP01(token=((chr(ord('a') + i) * 16))), challenges.HTTP01(token=((chr(ord('a') + i).encode() * 16))),
"pending"), "pending"),
domain=domain, account_key=self.account_key)) domain=domain, account_key=self.account_key))
@@ -139,6 +140,12 @@ class ApacheHttp01Test(util.ApacheTest):
domain="something.nonexistent", account_key=self.account_key)] domain="something.nonexistent", account_key=self.account_key)]
self.common_perform_test(achalls, vhosts) 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): def common_perform_test(self, achalls, vhosts):
"""Tests perform with the given achalls.""" """Tests perform with the given achalls."""
challenge_dir = self.http.challenge_dir challenge_dir = self.http.challenge_dir