diff --git a/certbot-ci/src/certbot_integration_tests/nginx_tests/nginx_config.py b/certbot-ci/src/certbot_integration_tests/nginx_tests/nginx_config.py index d8b195f81..291414c4e 100644 --- a/certbot-ci/src/certbot_integration_tests/nginx_tests/nginx_config.py +++ b/certbot-ci/src/certbot_integration_tests/nginx_tests/nginx_config.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """General purpose nginx test configuration generator.""" import atexit -import getpass import importlib.resources from contextlib import ExitStack from typing import Optional @@ -49,7 +48,6 @@ error_log {nginx_root}/error.log; # The pidfile will be written to /var/run unless this is set. pid {nginx_root}/nginx.pid; -user {user}; worker_processes 1; events {{ @@ -136,7 +134,7 @@ http {{ ssl_certificate_key {key_path}; }} }} -'''.format(nginx_root=nginx_root, nginx_webroot=nginx_webroot, user=getpass.getuser(), +'''.format(nginx_root=nginx_root, nginx_webroot=nginx_webroot, http_port=http_port, https_port=https_port, other_port=other_port, default_server='default_server' if default_server else '', wtf_prefix=wtf_prefix, key_path=key_path, cert_path=cert_path) diff --git a/certbot-ci/src/certbot_integration_tests/utils/certbot_call.py b/certbot-ci/src/certbot_integration_tests/utils/certbot_call.py index 7edf12a51..a879dd3ef 100755 --- a/certbot-ci/src/certbot_integration_tests/utils/certbot_call.py +++ b/certbot-ci/src/certbot_integration_tests/utils/certbot_call.py @@ -1,6 +1,7 @@ #!/usr/bin/env python """Module to call certbot in test mode""" +import configparser import os import subprocess import sys @@ -77,6 +78,38 @@ def _prepare_environ(workspace: str) -> dict[str, str]: ] new_environ['PYTHONPATH'] = ':'.join(python_paths) + # Pytest finds its ini file by doing the following: + # Determine the common ancestor directory for the specified args that are recognised as paths + # that exist in the file system. If no such paths are found, the common ancestor directory is + # set to the current working directory. + # + # Look for pytest.toml, .pytest.toml, pytest.ini, .pytest.ini, pyproject.toml, tox.ini, and + # setup.cfg files in the ancestor directory and upwards. If one is matched, it becomes the + # configfile and its directory becomes the rootdir. + # source: https://docs.pytest.org/en/stable/reference/customize.html#finding-the-rootdir + # + # Certbot's is located in its root directory. Let's just walk up the tree from this file. + # In case we can't find it, we still do want to error, so add a default. It's fine to have + # error in there twice. Also, ignore the unverified HTTPS request specifically for this call. + warning_filters: list[str]= [ + 'error', + "ignore:Unverified HTTPS request is being made to host 'localhost'", + ] + base_path: str = os.path.realpath(__file__) + while base_path != os.sep: + ini_loc: str = os.path.join(base_path, 'pytest.ini') + if os.path.exists(ini_loc): + ini_config: configparser.ConfigParser = configparser.ConfigParser() + ini_config.read(ini_loc) + if ini_config is not None: + ini_filters = ini_config.get('pytest', 'filterwarnings', fallback='') + warning_filters.extend(ini_filters.split('\n')) + break + else: + base_path = os.path.dirname(base_path) + + new_environ['PYTHONWARNINGS'] = ','.join(warning_filters) + return new_environ