1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-26 07:41:33 +03:00

certbot-ci: fix crash in and simplify manual_http_hooks (#9570)

There is a typo (`request` instead of `requests`) in the `auth.py` generated by this function:

d792d39813/certbot-ci/certbot_integration_tests/utils/misc.py (L184-L191)

that has [never ever succeeded](https://gist.github.com/alexzorin/ff2686b7123cea49f1e4107d1e7d95f5#file-master-log-L203-L208).

Moreover, this polling code is not necessary because `create_http_server` already polls until the HTTP server to come up, and the file we wrote to disk is guaranteed is immediately visible by the web server anyway.

* certbot-ci: fix crash in and simplify manual_http_hooks

* remove superfluous format argument

* remove unused argument
This commit is contained in:
alexzorin
2023-02-11 06:15:42 +11:00
committed by GitHub
parent 1bb09da270
commit 057524aa52
2 changed files with 3 additions and 17 deletions

View File

@@ -118,7 +118,7 @@ def test_http_01(context: IntegrationTestsContext) -> None:
def test_manual_http_auth(context: IntegrationTestsContext) -> None:
"""Test the HTTP-01 challenge using manual plugin."""
with misc.create_http_server(context.http_01_port) as webroot,\
misc.manual_http_hooks(webroot, context.http_01_port) as scripts:
misc.manual_http_hooks(webroot) as scripts:
certname = context.get_domain()
context.certbot([

View File

@@ -158,14 +158,12 @@ set -e
@contextlib.contextmanager
def manual_http_hooks(http_server_root: str,
http_port: int) -> Generator[Tuple[str, str], None, None]:
def manual_http_hooks(http_server_root: str) -> Generator[Tuple[str, str], None, None]:
"""
Generate suitable http-01 hooks command for test purpose in the given HTTP
server webroot directory. These hooks command use temporary python scripts
that are deleted upon context exit.
:param str http_server_root: path to the HTTP server configured to serve http-01 challenges
:param int http_port: HTTP port that the HTTP server listen on
:return (str, str): a tuple containing the authentication hook and cleanup hook commands
"""
tempdir = tempfile.mkdtemp()
@@ -175,24 +173,12 @@ def manual_http_hooks(http_server_root: str,
file_h.write('''\
#!/usr/bin/env python
import os
import requests
import time
import sys
challenge_dir = os.path.join('{0}', '.well-known', 'acme-challenge')
os.makedirs(challenge_dir)
challenge_file = os.path.join(challenge_dir, os.environ.get('CERTBOT_TOKEN'))
with open(challenge_file, 'w') as file_h:
file_h.write(os.environ.get('CERTBOT_VALIDATION'))
url = 'http://localhost:{1}/.well-known/acme-challenge/' + os.environ.get('CERTBOT_TOKEN')
for _ in range(0, 10):
time.sleep(1)
try:
if request.get(url).status_code == 200:
sys.exit(0)
except requests.exceptions.ConnectionError:
pass
raise ValueError('Error, url did not respond after 10 attempts: {{0}}'.format(url))
'''.format(http_server_root.replace('\\', '\\\\'), http_port))
'''.format(http_server_root.replace('\\', '\\\\')))
os.chmod(auth_script_path, 0o755)
cleanup_script_path = os.path.join(tempdir, 'cleanup.py')