From cb7921f61c7bfd47f07afe3848bc1c576e907aae Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 27 Mar 2023 17:25:14 +0200 Subject: [PATCH] Support python binaries that are not called "python" --- Makefile | 37 ++++++++++++++------------- tests/integration/test_integration.py | 8 +++++- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index da423c5537..f111b2f9e6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ SHELL := /bin/bash +PYTHON ?= python NS ?= abhinavsingh IMAGE_NAME ?= proxy.py @@ -40,23 +41,23 @@ all: lib-test https-certificates: # Generate server key - python -m proxy.common.pki gen_private_key \ + $(PYTHON) -m proxy.common.pki gen_private_key \ --private-key-path $(HTTPS_KEY_FILE_PATH) - python -m proxy.common.pki remove_passphrase \ + $(PYTHON) -m proxy.common.pki remove_passphrase \ --private-key-path $(HTTPS_KEY_FILE_PATH) # Generate server certificate - python -m proxy.common.pki gen_public_key \ + $(PYTHON) -m proxy.common.pki gen_public_key \ --private-key-path $(HTTPS_KEY_FILE_PATH) \ --public-key-path $(HTTPS_CERT_FILE_PATH) sign-https-certificates: # Generate CSR request - python -m proxy.common.pki gen_csr \ + $(PYTHON) -m proxy.common.pki gen_csr \ --csr-path $(HTTPS_CSR_FILE_PATH) \ --private-key-path $(HTTPS_KEY_FILE_PATH) \ --public-key-path $(HTTPS_CERT_FILE_PATH) # Sign CSR with CA - python -m proxy.common.pki sign_csr \ + $(PYTHON) -m proxy.common.pki sign_csr \ --csr-path $(HTTPS_CSR_FILE_PATH) \ --crt-path $(HTTPS_SIGNED_CERT_FILE_PATH) \ --hostname localhost \ @@ -65,23 +66,23 @@ sign-https-certificates: ca-certificates: # Generate CA key - python -m proxy.common.pki gen_private_key \ + $(PYTHON) -m proxy.common.pki gen_private_key \ --private-key-path $(CA_KEY_FILE_PATH) - python -m proxy.common.pki remove_passphrase \ + $(PYTHON) -m proxy.common.pki remove_passphrase \ --private-key-path $(CA_KEY_FILE_PATH) # Generate CA certificate - python -m proxy.common.pki gen_public_key \ + $(PYTHON) -m proxy.common.pki gen_public_key \ --private-key-path $(CA_KEY_FILE_PATH) \ --public-key-path $(CA_CERT_FILE_PATH) # Generate key that will be used to generate domain certificates on the fly # Generated certificates are then signed with CA certificate / key generated above - python -m proxy.common.pki gen_private_key \ + $(PYTHON) -m proxy.common.pki gen_private_key \ --private-key-path $(CA_SIGNING_KEY_FILE_PATH) - python -m proxy.common.pki remove_passphrase \ + $(PYTHON) -m proxy.common.pki remove_passphrase \ --private-key-path $(CA_SIGNING_KEY_FILE_PATH) lib-check: - python check.py + $(PYTHON) check.py lib-clean: find . -name '*.pyc' -exec rm -f {} + @@ -107,10 +108,10 @@ lib-dep: pip install "setuptools>=42" lib-pre-commit: - python -m pre_commit run --hook-stage manual --all-files -v + $(PYTHON) -m pre_commit run --hook-stage manual --all-files -v lib-lint: - python -m tox -e lint + $(PYTHON) -m tox -e lint lib-flake8: tox -e lint -- flake8 --all-files @@ -119,12 +120,12 @@ lib-mypy: tox -e lint -- mypy --all-files lib-pytest: - python -m tox -e python -- -v + $(PYTHON) -m tox -e python -- -v lib-test: lib-clean lib-check lib-lint lib-pytest lib-package: lib-clean lib-check - python -m tox -e cleanup-dists,build-dists,metadata-validation + $(PYTHON) -m tox -e cleanup-dists,build-dists,metadata-validation lib-release-test: lib-package twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/* @@ -133,7 +134,7 @@ lib-release: lib-package twine upload dist/* lib-doc: - python -m tox -e build-docs && \ + $(PYTHON) -m tox -e build-docs && \ $(OPEN) .tox/build-docs/docs_out/index.html || true lib-coverage: lib-clean @@ -145,7 +146,7 @@ lib-profile: sudo py-spy record \ -o profile.svg \ -t -F -s -- \ - python -m proxy \ + $(PYTHON) -m proxy \ --hostname 127.0.0.1 \ --num-acceptors 1 \ --num-workers 1 \ @@ -161,7 +162,7 @@ lib-speedscope: -o profile.speedscope.json \ -f speedscope \ -t -F -s -- \ - python -m proxy \ + $(PYTHON) -m proxy \ --hostname 127.0.0.1 \ --num-acceptors 1 \ --num-workers 1 \ diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index ca0012b6a6..56313629e0 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -11,6 +11,7 @@ Test the simplest proxy use scenario for smoke. """ import os +import sys import time import tempfile import subprocess @@ -130,10 +131,12 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str: def _gen_https_certificates(request: Any) -> None: check_output([ 'make', 'https-certificates', + '-e', 'PYTHON="%s"' % (sys.executable,), '-e', 'CERT_DIR=%s/' % (str(CERT_DIR)), ]) check_output([ 'make', 'sign-https-certificates', + '-e', 'PYTHON="%s"' % (sys.executable,), '-e', 'CERT_DIR=%s/' % (str(CERT_DIR)), ]) @@ -142,15 +145,18 @@ def _gen_https_certificates(request: Any) -> None: def _gen_ca_certificates(request: Any) -> None: check_output([ 'make', 'ca-certificates', + '-e', 'PYTHON="%s"' % (sys.executable,), '-e', 'CERT_DIR=%s/' % (str(CERT_DIR)), ]) check_output([ 'make', 'ca-certificates', + '-e', 'PYTHON="%s"' % (sys.executable,), '-e', 'CA_CERT_SUFFIX=-chunk', '-e', 'CERT_DIR=%s/' % (str(CERT_DIR)), ]) check_output([ 'make', 'ca-certificates', + '-e', 'PYTHON="%s"' % (sys.executable,), '-e', 'CA_CERT_SUFFIX=-post', '-e', 'CERT_DIR=%s/' % (str(CERT_DIR)), ]) @@ -175,7 +181,7 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]: ca_cert_dir = TEMP_DIR / ('certificates-%s' % run_id) os.makedirs(ca_cert_dir, exist_ok=True) proxy_cmd = ( - 'python', '-m', 'proxy', + sys.executable, '-m', 'proxy', '--hostname', '127.0.0.1', '--port', '0', '--port-file', str(port_file),