google-auth: Local developer mTLS environment leaks into unit tests, causing mock failures
Los mantenedores suelen responder en 1 día
@Shubham-Padkonde ya está trabajando en esto.
Desde el 22/9/2026.
- #18436 de @Shubham-Padkonde — abierto
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- python
- Área
- testing-qa
Línea de trabajo
Comienza en tests/conftest.py y revisa los fixtures existentes de pytest y las pruebas relacionadas con mTLS. Ejecuta la suite de pruebas unitarias con variables de entorno locales de mTLS o con una configuración de certificados presente y, a continuación, verifica que las pruebas normales usen endpoints estándar, mientras que las pruebas que habilitan explícitamente mTLS sigan pasando. Se considera terminado cuando el entorno está aislado por prueba y se restaura después.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Determine this is the right repository
- I determined this is the correct repository in which to report this bug.
Summary of the issue
When running unit tests locally on developer machines that have context-aware access or enterprise mTLS configured (such as Google-managed corporate MacBooks), several tests fail unexpectedly.
This happens because the test suite's global configuration (tests/conftest.py) does not sanitize the environment. Global environment variables (like GOOGLE_API_CERTIFICATE_CONFIG or GOOGLE_API_USE_CLIENT_CERTIFICATE) and default configuration files (like ~/.config/gcloud/certificate_config.json) leak directly into the pytest session.
Any test that does not explicitly mock _mtls_helper.check_use_client_cert() or clear these environment variables will transition to using mTLS hostnames (e.g. expecting iamcredentials.googleapis.com but getting iamcredentials.mtls.googleapis.com). Since the mock networks in the tests are configured with standard endpoints, the requests fail to match the mock setups, causing transport exceptions and test failures.
Proposed fix
Introduce a function-scoped, autouse fixture in tests/conftest.py to establish a clean, hermetic environment for every unit test. Using pytest's standard monkeypatch fixture ensures all local environmental variables and mocks are automatically cleaned up and restored back to the developer's original workstation state after each test executes. This can be accomplished by something like:
# tests/conftest.py
@pytest.fixture(autouse=True)
def clean_mtls_environment(monkeypatch):
from google.auth.transport import _mtls_helper
# Pop all mTLS-related environment variables
for var in [
"GOOGLE_API_USE_CLIENT_CERTIFICATE",
"GOOGLE_API_CERTIFICATE_CONFIG",
"CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE",
"CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH",
]:
monkeypatch.delenv(var, raising=False)
# Mock check_use_client_cert to return False by default
monkeypatch.setattr(_mtls_helper, "check_use_client_cert", lambda: False)
This way tests specifically designed to verify mTLS behaviors can easily override the global mock locally by re-patching the method in their own bodies (which runs after the global autouse setup):
def test_mtls_behavior(monkeypatch):
from google.auth.transport import _mtls_helper
monkeypatch.setattr(_mtls_helper, "check_use_client_cert", lambda: True)
# Test runs with mTLS enabled cleanly
- Lenguaje dominante
- Python
- Estrellas
- 5.4k
- Forks
- 1.8k
- Merge medio
- 2 d 9 h
- PR fusionados (30 d)
- 138
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de googleapis/google-cloud-python
-
api: spanner type: feature request
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
googleapis/google-cloud-python#18584 ·
Los mantenedores suelen responder en 1 día
-
ci: remove UV_PRERELEASE workaround once Python 3.15 is officially releasedPosiblemente ocupada @daniel-sanche la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
googleapis/google-cloud-python#18532 ·
Los mantenedores suelen responder en 1 día
-
auth: call_client_cert_callback() discards passphrase for encrypted keysPosiblemente ocupada @kwy404 la tomó hace 10 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
googleapis/google-cloud-python#18467 ·
Los mantenedores suelen responder en 1 día
-
auth: `impersonated_credentials` loses `subject` on copy, so `with_scopes()` and `with_quota_project()` turn off domain wide delegationPosiblemente ocupada @Om-singhaI la tomó hace 22 días. Abiertoauth priority: p2 type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
googleapis/google-cloud-python#18428 ·
Los mantenedores suelen responder en 1 día
-
priority: p2 type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
googleapis/google-cloud-python#18375 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de googleapis/google-cloud-python
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
esphome/esphome.io#7657 ·
Los mantenedores suelen responder en 1 día
-
comp/gateway comp/plugins duplicate P3 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NousResearch/hermes-agent#137019 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Kumo-Tabular weights unreachable behind restrictive egress proxies (Xet + plain HTTP both fail)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
NVIDIA/structured-data-models#1091 ·
Los mantenedores suelen responder en 1 día
-
[work-item] adam-adae-worsening-emergence: conform spec.yaml to the specification style contract (REQ-1280)Posiblemente ocupada @muse-yamaa-bot la tomó hoy. Abiertowork-item
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día