mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
error with no vhost
This commit is contained in:
parent
b8f288a372
commit
71d2e46f0d
2 changed files with 22 additions and 3 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 vhost 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 = self.configurator.config.http01_port
|
||||
relevant_vhosts = []
|
||||
for vhost in self.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
|
||||
|
||||
|
|
@ -139,6 +140,10 @@ class ApacheHttp01Test(util.ApacheTest):
|
|||
domain="something.nonexistent", account_key=self.account_key)]
|
||||
self.common_perform_test(achalls, vhosts)
|
||||
|
||||
def test_no_vhost(self):
|
||||
self.config.config.http01_port = 12345
|
||||
self.assertRaises(errors.PluginError, self.http.perform, self.achalls)
|
||||
|
||||
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