google-auth 2.59.0__tar.gz → 2.59.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_auth-2.59.0/google_auth.egg-info → google_auth-2.59.1}/PKG-INFO +1 -1
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/requests.py +100 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/version.py +1 -1
- {google_auth-2.59.0 → google_auth-2.59.1/google_auth.egg-info}/PKG-INFO +1 -1
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test_requests.py +341 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/LICENSE +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/MANIFEST.in +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/README.rst +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_agent_identity_utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_cache.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_cloud_sdk.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_credentials_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_credentials_base.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_default.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_default_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_exponential_backoff.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_helpers.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_jwt_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_oauth2client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_refresh_worker.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_regional_access_boundary_utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/_service_account_info.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/_helpers.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/transport/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/transport/aiohttp.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/transport/mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aio/transport/sessions.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/api_key.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/app_engine.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/aws.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/compute_engine/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/compute_engine/_metadata.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/compute_engine/_mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/compute_engine/credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/_cryptography_rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/_helpers.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/_python_rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/base.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/es.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/es256.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/crypt/rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/downscoped.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/environment_vars.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/exceptions.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/external_account.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/external_account_authorized_user.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/iam.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/identity_pool.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/impersonated_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/jwt.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/metrics.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/pluggable.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/py.typed +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/_aiohttp_requests.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/_custom_tls_signer.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/_http_client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/_mtls_helper.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/_requests_base.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/grpc.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/auth/transport/urllib3.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_client_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_credentials_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_id_token_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_reauth_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/_service_account_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/challenges.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/gdch_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/id_token.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/py.typed +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/reauth.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/service_account.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/sts.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/webauthn_handler.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/webauthn_handler_factory.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google/oauth2/webauthn_types.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google_auth.egg-info/SOURCES.txt +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google_auth.egg-info/dependency_links.txt +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google_auth.egg-info/requires.txt +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/google_auth.egg-info/top_level.txt +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/setup.cfg +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/setup.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/aio/test__helpers.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/data/smbios_product_name +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/data/smbios_product_name_non_google +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/test__metadata.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/test__mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/compute_engine/test_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/conftest.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test__cryptography_rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test__python_rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test_crypt.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test_es.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test_es256.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/crypt/test_rsa.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/authorized_user.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/authorized_user_cloud_sdk.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/authorized_user_cloud_sdk_with_quota_project_id.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/authorized_user_with_rapt_token.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/client_secrets.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/context_aware_metadata.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/enterprise_cert_invalid.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/enterprise_cert_valid.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/enterprise_cert_valid_provider.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es256_privatekey.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es256_public_cert.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es256_publickey.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es256_service_account.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es384_privatekey.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es384_public_cert.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es384_publickey.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/es384_service_account.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/external_account_authorized_user.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/external_account_authorized_user_non_gdu.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/external_subject_token.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/external_subject_token.txt +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/gdch_service_account.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/impersonated_service_account_authorized_user_source.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/impersonated_service_account_external_account_authorized_user_source.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/impersonated_service_account_service_account_source.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/impersonated_service_account_with_quota_project.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/old_oauth_credentials_py3.pickle +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/other_cert.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/pem_from_pkcs12.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/privatekey.p12 +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/privatekey.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/privatekey.pub +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/public_cert.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/service_account.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/service_account_non_gdu.json +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/trust_chain_with_leaf.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/trust_chain_without_leaf.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/data/trust_chain_wrong_order.pem +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test__client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_challenges.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_gdch_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_id_token.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_reauth.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_service_account.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_sts.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_webauthn_handler.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_webauthn_handler_factory.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/oauth2/test_webauthn_types.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__cache.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__cloud_sdk.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__default.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__exponential_backoff.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__helpers.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__oauth2client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__refresh_worker.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__regional_access_boundary_utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test__service_account_info.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_agent_identity_utils.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_api_key.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_app_engine.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_aws.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_credentials_async.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_downscoped.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_exceptions.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_external_account.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_external_account_authorized_user.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_iam.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_identity_pool.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_impersonated_credentials.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_jwt.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_metrics.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_packaging.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/test_pluggable.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/__init__.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aio/conftest.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aio/test_aiohttp.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aio/test_mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aio/test_sessions.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aio/test_sessions_mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/aioresponses_compat.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/compliance.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test__custom_tls_signer.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test__http_client.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test__mtls_helper.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test_aio_mtls_helper.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test_grpc.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test_mtls.py +0 -0
- {google_auth-2.59.0 → google_auth-2.59.1}/tests/transport/test_urllib3.py +0 -0
|
@@ -16,11 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import absolute_import
|
|
18
18
|
|
|
19
|
+
import collections
|
|
20
|
+
import copy
|
|
19
21
|
import functools
|
|
20
22
|
import http.client as http_client
|
|
21
23
|
import logging
|
|
22
24
|
import numbers
|
|
25
|
+
import threading
|
|
23
26
|
import time
|
|
27
|
+
import urllib.parse as urllib_parse
|
|
24
28
|
from typing import Optional
|
|
25
29
|
|
|
26
30
|
try:
|
|
@@ -136,11 +140,28 @@ class Request(transport.Request):
|
|
|
136
140
|
.. automethod:: __call__
|
|
137
141
|
"""
|
|
138
142
|
|
|
143
|
+
_mtls_adapter = None
|
|
144
|
+
_mtls_unavailable = False
|
|
145
|
+
|
|
139
146
|
def __init__(self, session: Optional[requests.Session] = None) -> None:
|
|
140
147
|
if not session:
|
|
141
148
|
session = requests.Session()
|
|
142
149
|
|
|
143
150
|
self.session = session
|
|
151
|
+
self._mtls_adapter = None
|
|
152
|
+
self._mtls_unavailable = False
|
|
153
|
+
self._mtls_lock = threading.Lock()
|
|
154
|
+
|
|
155
|
+
def __getstate__(self):
|
|
156
|
+
state = self.__dict__.copy()
|
|
157
|
+
state["_mtls_lock"] = None
|
|
158
|
+
return state
|
|
159
|
+
|
|
160
|
+
def __setstate__(self, state):
|
|
161
|
+
self.__dict__.update(state)
|
|
162
|
+
self._mtls_lock = threading.Lock()
|
|
163
|
+
if not isinstance(self._mtls_adapter, _MutualTlsAdapter):
|
|
164
|
+
self._mtls_adapter = None
|
|
144
165
|
|
|
145
166
|
def __del__(self):
|
|
146
167
|
try:
|
|
@@ -152,6 +173,59 @@ class Request(transport.Request):
|
|
|
152
173
|
# TypeError.
|
|
153
174
|
pass
|
|
154
175
|
|
|
176
|
+
def _configure_mtls_if_needed(self, url):
|
|
177
|
+
"""Lazily mounts a mutual TLS adapter onto the session for mTLS endpoints.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
url (str): The target request URL.
|
|
181
|
+
"""
|
|
182
|
+
if not _mtls_helper.is_mtls_endpoint(url):
|
|
183
|
+
return
|
|
184
|
+
|
|
185
|
+
# Mount on the specific origin rather than globally on "https://" so client
|
|
186
|
+
# certificates are not sent to other hosts sharing this session. The trailing
|
|
187
|
+
# slash prevents requests' startswith() matching from matching lookalike domains.
|
|
188
|
+
parsed = urllib_parse.urlparse(url)
|
|
189
|
+
prefix = f"{parsed.scheme}://{parsed.netloc.lower()}/"
|
|
190
|
+
with self._mtls_lock:
|
|
191
|
+
session_adapter = self.session.get_adapter(url if parsed.path else prefix)
|
|
192
|
+
# Skip if _MutualTlsAdapter is already mounted or the caller mounted a custom adapter.
|
|
193
|
+
if (
|
|
194
|
+
type(session_adapter) is not requests.adapters.HTTPAdapter
|
|
195
|
+
or self.session.get_adapter(prefix) is not session_adapter
|
|
196
|
+
):
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
if self._mtls_adapter is None:
|
|
200
|
+
if self._mtls_unavailable or not _mtls_helper.check_use_client_cert():
|
|
201
|
+
return
|
|
202
|
+
has_cert, cert, key = _mtls_helper.get_client_cert_and_key()
|
|
203
|
+
if not has_cert:
|
|
204
|
+
self._mtls_unavailable = True
|
|
205
|
+
return
|
|
206
|
+
|
|
207
|
+
self._mtls_adapter = _MutualTlsAdapter(
|
|
208
|
+
cert,
|
|
209
|
+
key,
|
|
210
|
+
max_retries=session_adapter.max_retries,
|
|
211
|
+
pool_connections=session_adapter._pool_connections,
|
|
212
|
+
pool_maxsize=session_adapter._pool_maxsize,
|
|
213
|
+
pool_block=session_adapter._pool_block,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# Replace session.adapters atomically instead of calling session.mount(),
|
|
217
|
+
# which mutates the OrderedDict in place and can raise RuntimeError if
|
|
218
|
+
# another thread is iterating over session.adapters in get_adapter().
|
|
219
|
+
new_adapters = self.session.adapters.copy()
|
|
220
|
+
new_adapters[prefix] = self._mtls_adapter
|
|
221
|
+
self.session.adapters = collections.OrderedDict(
|
|
222
|
+
sorted(
|
|
223
|
+
new_adapters.items(),
|
|
224
|
+
key=lambda item: len(item[0]),
|
|
225
|
+
reverse=True,
|
|
226
|
+
)
|
|
227
|
+
)
|
|
228
|
+
|
|
155
229
|
def __call__(
|
|
156
230
|
self,
|
|
157
231
|
url,
|
|
@@ -181,6 +255,19 @@ class Request(transport.Request):
|
|
|
181
255
|
Raises:
|
|
182
256
|
google.auth.exceptions.TransportError: If any exception occurred.
|
|
183
257
|
"""
|
|
258
|
+
if not kwargs.get("cert"):
|
|
259
|
+
try:
|
|
260
|
+
self._configure_mtls_if_needed(url)
|
|
261
|
+
except (
|
|
262
|
+
exceptions.MutualTLSChannelError,
|
|
263
|
+
exceptions.ClientCertError,
|
|
264
|
+
OSError,
|
|
265
|
+
) as caught_exc:
|
|
266
|
+
new_exc = exceptions.TransportError(caught_exc)
|
|
267
|
+
raise new_exc from caught_exc
|
|
268
|
+
|
|
269
|
+
# Missing CA bundles or cert paths raised by requests must bubble up
|
|
270
|
+
# unwrapped to fail immediately rather than triggering client retries.
|
|
184
271
|
try:
|
|
185
272
|
_helpers.request_log(_LOGGER, method, url, body, headers)
|
|
186
273
|
response = self.session.request(
|
|
@@ -212,9 +299,11 @@ class _MutualTlsAdapter(requests.adapters.HTTPAdapter):
|
|
|
212
299
|
import certifi
|
|
213
300
|
|
|
214
301
|
ctx_poolmanager = create_urllib3_context()
|
|
302
|
+
ctx_poolmanager.check_hostname = False
|
|
215
303
|
ctx_poolmanager.load_verify_locations(cafile=certifi.where())
|
|
216
304
|
|
|
217
305
|
ctx_proxymanager = create_urllib3_context()
|
|
306
|
+
ctx_proxymanager.check_hostname = False
|
|
218
307
|
ctx_proxymanager.load_verify_locations(cafile=certifi.where())
|
|
219
308
|
|
|
220
309
|
try:
|
|
@@ -251,6 +340,17 @@ class _MutualTlsAdapter(requests.adapters.HTTPAdapter):
|
|
|
251
340
|
|
|
252
341
|
super(_MutualTlsAdapter, self).__init__(**kwargs)
|
|
253
342
|
|
|
343
|
+
def __deepcopy__(self, memo):
|
|
344
|
+
new_adapter = object.__new__(type(self))
|
|
345
|
+
memo[id(self)] = new_adapter
|
|
346
|
+
new_adapter._ctx_poolmanager = self._ctx_poolmanager
|
|
347
|
+
new_adapter._ctx_proxymanager = self._ctx_proxymanager
|
|
348
|
+
new_adapter.__setstate__(copy.deepcopy(self.__getstate__(), memo))
|
|
349
|
+
return new_adapter
|
|
350
|
+
|
|
351
|
+
def __reduce_ex__(self, protocol):
|
|
352
|
+
return (requests.adapters.HTTPAdapter, (), self.__getstate__())
|
|
353
|
+
|
|
254
354
|
def init_poolmanager(self, *args, **kwargs):
|
|
255
355
|
kwargs["ssl_context"] = self._ctx_poolmanager
|
|
256
356
|
super(_MutualTlsAdapter, self).init_poolmanager(*args, **kwargs)
|
|
@@ -12,10 +12,14 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
import copy
|
|
15
16
|
import datetime
|
|
16
17
|
import functools
|
|
17
18
|
import http.client as http_client
|
|
19
|
+
import json
|
|
18
20
|
import os
|
|
21
|
+
import pickle
|
|
22
|
+
import ssl
|
|
19
23
|
from unittest import mock
|
|
20
24
|
|
|
21
25
|
import freezegun
|
|
@@ -38,6 +42,34 @@ def frozen_time():
|
|
|
38
42
|
yield frozen
|
|
39
43
|
|
|
40
44
|
|
|
45
|
+
@pytest.fixture
|
|
46
|
+
def workload_cert_config(tmpdir, monkeypatch):
|
|
47
|
+
cert_file = tmpdir.join("public_cert.pem")
|
|
48
|
+
cert_file.write_binary(pytest.public_cert_bytes)
|
|
49
|
+
config_file = tmpdir.join("certificate_config.json")
|
|
50
|
+
config_file.write(
|
|
51
|
+
json.dumps(
|
|
52
|
+
{
|
|
53
|
+
"cert_configs": {
|
|
54
|
+
"workload": {
|
|
55
|
+
"cert_path": str(cert_file),
|
|
56
|
+
"key_path": os.path.join(pytest.data_dir, "privatekey.pem"),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
monkeypatch.setenv(environment_vars.GOOGLE_API_CERTIFICATE_CONFIG, str(config_file))
|
|
63
|
+
monkeypatch.delenv(
|
|
64
|
+
environment_vars.GOOGLE_API_USE_CLIENT_CERTIFICATE, raising=False
|
|
65
|
+
)
|
|
66
|
+
monkeypatch.delenv(
|
|
67
|
+
environment_vars.CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE,
|
|
68
|
+
raising=False,
|
|
69
|
+
)
|
|
70
|
+
return cert_file
|
|
71
|
+
|
|
72
|
+
|
|
41
73
|
CERT_MOCK_VAL = b"-----BEGIN CERTIFICATE-----\nMIIDIzCCAgugAwIBAgIJAMfISuBQ5m+5MA0GCSqGSIb3DQEBBQUAMBUxEzARBgNV\nBAMTCnVuaXQtdGVzdHMwHhcNMTExMjA2MTYyNjAyWhcNMjExMjAzMTYyNjAyWjAV\nMRMwEQYDVQQDEwp1bml0LXRlc3RzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\nCgKCAQEA4ej0p7bQ7L/r4rVGUz9RN4VQWoej1Bg1mYWIDYslvKrk1gpj7wZgkdmM\n7oVK2OfgrSj/FCTkInKPqaCR0gD7K80q+mLBrN3PUkDrJQZpvRZIff3/xmVU1Wer\nuQLFJjnFb2dqu0s/FY/2kWiJtBCakXvXEOb7zfbINuayL+MSsCGSdVYsSliS5qQp\ngyDap+8b5fpXZVJkq92hrcNtbkg7hCYUJczt8n9hcCTJCfUpApvaFQ18pe+zpyl4\n+WzkP66I28hniMQyUlA1hBiskT7qiouq0m8IOodhv2fagSZKjOTTU2xkSBc//fy3\nZpsL7WqgsZS7Q+0VRK8gKfqkxg5OYQIDAQABo3YwdDAdBgNVHQ4EFgQU2RQ8yO+O\ngN8oVW2SW7RLrfYd9jEwRQYDVR0jBD4wPIAU2RQ8yO+OgN8oVW2SW7RLrfYd9jGh\nGaQXMBUxEzARBgNVBAMTCnVuaXQtdGVzdHOCCQDHyErgUOZvuTAMBgNVHRMEBTAD\nAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQBRv+M/6+FiVu7KXNjFI5pSN17OcW5QUtPr\nodJMlWrJBtynn/TA1oJlYu3yV5clc/71Vr/AxuX5xGP+IXL32YDF9lTUJXG/uUGk\n+JETpKmQviPbRsvzYhz4pf6ZIOZMc3/GIcNq92ECbseGO+yAgyWUVKMmZM0HqXC9\novNslqe0M8C1sLm1zAR5z/h/litE7/8O2ietija3Q/qtl2TOXJdCA6sgjJX2WUql\nybrC55ct18NKf3qhpcEkGQvFU40rVYApJpi98DiZPYFdx1oBDp/f4uZ3ojpxRVFT\ncDwcJLfNRCPUhormsY7fDS9xSyThiHsW9mjJYdcaKQkwYZ0F11yB\n-----END CERTIFICATE-----\n"
|
|
42
74
|
KEY_MOCK_VAL = b"-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIHeMEkGCSqGSIb3DQEFDTA8MBsGCSqGSIb3DQEFDDAOBAj9XnJ2h78QVAICCAAw\nHQYJYIZIAWUDBAECBBBeiiOF2LnLzq/wjb/viwMwBIGQk28Zkfj2EIk42bgc7UzC\nSf98qssCVhsIYz0Xa3eSATg8Cpn83YieaBeyxdk/tXTnrOhxMV/vt7T98kWhaGbH\n5Z9CdGVLfes0UFvVJqrlk6vcf2sOnLCGbrn78HS+ayrGOCRSCd/7+dnEiB/7Um1B\nMk6BBJHsLEnZZSHyfrw8jvYgVmcSBy/WdY0pqldD/+4D\n-----END ENCRYPTED PRIVATE KEY-----\n"
|
|
43
75
|
|
|
@@ -65,6 +97,302 @@ class TestRequestResponse(compliance.RequestResponseTests):
|
|
|
65
97
|
request.__del__()
|
|
66
98
|
http.close.assert_called_with()
|
|
67
99
|
|
|
100
|
+
@pytest.mark.parametrize(
|
|
101
|
+
"mount_prefix",
|
|
102
|
+
["https://", "https://iamcredentials.mtls.googleapis.com/"],
|
|
103
|
+
)
|
|
104
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
105
|
+
def test_mtls_origin_mount_and_reuse(
|
|
106
|
+
self, mock_send, mount_prefix, workload_cert_config
|
|
107
|
+
):
|
|
108
|
+
mock_send.return_value = make_response()
|
|
109
|
+
session = requests.Session()
|
|
110
|
+
base_adapter = requests.adapters.HTTPAdapter(
|
|
111
|
+
max_retries=3, pool_connections=4, pool_maxsize=8, pool_block=True
|
|
112
|
+
)
|
|
113
|
+
session.mount(mount_prefix, base_adapter)
|
|
114
|
+
https_adapter = session.adapters["https://"]
|
|
115
|
+
request = google.auth.transport.requests.Request(session)
|
|
116
|
+
|
|
117
|
+
request("https://oauth2.googleapis.com/token")
|
|
118
|
+
# Verify mounting replaces session.adapters rather than mutating it in place.
|
|
119
|
+
adapters_iter = iter(session.adapters.items())
|
|
120
|
+
next(adapters_iter)
|
|
121
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
122
|
+
list(adapters_iter)
|
|
123
|
+
adapters_after_mount = session.adapters
|
|
124
|
+
adapters_snapshot = session.adapters.copy()
|
|
125
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
126
|
+
assert session.adapters is adapters_after_mount
|
|
127
|
+
assert session.adapters == adapters_snapshot
|
|
128
|
+
request("https://STS.mtls.googleapis.com")
|
|
129
|
+
|
|
130
|
+
mtls_adapter = session.adapters["https://iamcredentials.mtls.googleapis.com/"]
|
|
131
|
+
assert isinstance(
|
|
132
|
+
mtls_adapter, google.auth.transport.requests._MutualTlsAdapter
|
|
133
|
+
)
|
|
134
|
+
assert mtls_adapter.max_retries.total == 3
|
|
135
|
+
assert mtls_adapter._pool_connections == 4
|
|
136
|
+
assert mtls_adapter._pool_maxsize == 8
|
|
137
|
+
assert mtls_adapter._pool_block is True
|
|
138
|
+
assert session.adapters["https://sts.mtls.googleapis.com/"] is mtls_adapter
|
|
139
|
+
sent_adapters = [call.args[0] for call in mock_send.call_args_list]
|
|
140
|
+
assert sent_adapters == [
|
|
141
|
+
https_adapter,
|
|
142
|
+
mtls_adapter,
|
|
143
|
+
mtls_adapter,
|
|
144
|
+
mtls_adapter,
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
@pytest.mark.parametrize(
|
|
148
|
+
"mount_prefix,adapter_cls",
|
|
149
|
+
[
|
|
150
|
+
("https://", requests.adapters.BaseAdapter),
|
|
151
|
+
(
|
|
152
|
+
"https://iamcredentials.mtls.googleapis.com/",
|
|
153
|
+
requests.adapters.BaseAdapter,
|
|
154
|
+
),
|
|
155
|
+
(
|
|
156
|
+
"https://iamcredentials.mtls.googleapis.com/v1/token",
|
|
157
|
+
requests.adapters.BaseAdapter,
|
|
158
|
+
),
|
|
159
|
+
("https://", google.auth.transport.requests._MutualTlsAdapter),
|
|
160
|
+
(
|
|
161
|
+
"https://iamcredentials.mtls.googleapis.com/v1/",
|
|
162
|
+
requests.adapters.HTTPAdapter,
|
|
163
|
+
),
|
|
164
|
+
],
|
|
165
|
+
)
|
|
166
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
167
|
+
def test_mtls_preserves_custom_adapter(
|
|
168
|
+
self,
|
|
169
|
+
mock_send,
|
|
170
|
+
mount_prefix,
|
|
171
|
+
adapter_cls,
|
|
172
|
+
workload_cert_config,
|
|
173
|
+
):
|
|
174
|
+
mock_send.return_value = make_response()
|
|
175
|
+
session = requests.Session()
|
|
176
|
+
if adapter_cls is google.auth.transport.requests._MutualTlsAdapter:
|
|
177
|
+
custom_adapter = adapter_cls(
|
|
178
|
+
pytest.public_cert_bytes, pytest.private_key_bytes
|
|
179
|
+
)
|
|
180
|
+
elif adapter_cls is requests.adapters.BaseAdapter:
|
|
181
|
+
custom_adapter = AdapterStub([make_response()])
|
|
182
|
+
else:
|
|
183
|
+
custom_adapter = adapter_cls()
|
|
184
|
+
session.mount(mount_prefix, custom_adapter)
|
|
185
|
+
adapters_before = session.adapters
|
|
186
|
+
adapters_snapshot = session.adapters.copy()
|
|
187
|
+
request = google.auth.transport.requests.Request(session)
|
|
188
|
+
|
|
189
|
+
request("https://IAMCREDENTIALS.mtls.googleapis.com/v1/token")
|
|
190
|
+
|
|
191
|
+
assert session.adapters is adapters_before
|
|
192
|
+
assert session.adapters == adapters_snapshot
|
|
193
|
+
assert (
|
|
194
|
+
session.get_adapter("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
195
|
+
is custom_adapter
|
|
196
|
+
)
|
|
197
|
+
assert request._mtls_adapter is None
|
|
198
|
+
|
|
199
|
+
@pytest.mark.parametrize(
|
|
200
|
+
"use_cert,request_kwargs",
|
|
201
|
+
[
|
|
202
|
+
("false", {}),
|
|
203
|
+
("true", {"cert": ("cert.pem", "key.pem")}),
|
|
204
|
+
],
|
|
205
|
+
)
|
|
206
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
207
|
+
def test_mtls_skips_when_disabled_or_explicit_cert(
|
|
208
|
+
self,
|
|
209
|
+
mock_send,
|
|
210
|
+
use_cert,
|
|
211
|
+
request_kwargs,
|
|
212
|
+
workload_cert_config,
|
|
213
|
+
monkeypatch,
|
|
214
|
+
):
|
|
215
|
+
mock_send.return_value = make_response()
|
|
216
|
+
monkeypatch.setenv(environment_vars.GOOGLE_API_USE_CLIENT_CERTIFICATE, use_cert)
|
|
217
|
+
session = requests.Session()
|
|
218
|
+
request = google.auth.transport.requests.Request(session)
|
|
219
|
+
|
|
220
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token", **request_kwargs)
|
|
221
|
+
|
|
222
|
+
assert "https://iamcredentials.mtls.googleapis.com/" not in session.adapters
|
|
223
|
+
assert request._mtls_adapter is None
|
|
224
|
+
|
|
225
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
226
|
+
@mock.patch.object(
|
|
227
|
+
google.auth.transport._mtls_helper,
|
|
228
|
+
"get_client_cert_and_key",
|
|
229
|
+
return_value=(False, None, None),
|
|
230
|
+
)
|
|
231
|
+
def test_mtls_no_cert_caches_unavailable(
|
|
232
|
+
self, mock_get_cert, mock_send, monkeypatch
|
|
233
|
+
):
|
|
234
|
+
mock_send.return_value = make_response()
|
|
235
|
+
monkeypatch.setenv(environment_vars.GOOGLE_API_USE_CLIENT_CERTIFICATE, "true")
|
|
236
|
+
session = requests.Session()
|
|
237
|
+
request = google.auth.transport.requests.Request(session)
|
|
238
|
+
|
|
239
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
240
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
241
|
+
|
|
242
|
+
assert "https://iamcredentials.mtls.googleapis.com/" not in session.adapters
|
|
243
|
+
assert request._mtls_unavailable is True
|
|
244
|
+
mock_get_cert.assert_called_once()
|
|
245
|
+
|
|
246
|
+
@pytest.mark.parametrize(
|
|
247
|
+
"cert_bytes,expected_cause",
|
|
248
|
+
[
|
|
249
|
+
(None, FileNotFoundError),
|
|
250
|
+
(b"invalid", exceptions.ClientCertError),
|
|
251
|
+
(
|
|
252
|
+
b"-----BEGIN CERTIFICATE-----\ninvalid\n-----END CERTIFICATE-----\n",
|
|
253
|
+
exceptions.MutualTLSChannelError,
|
|
254
|
+
),
|
|
255
|
+
],
|
|
256
|
+
)
|
|
257
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
258
|
+
def test_mtls_cert_error_raises_transport_error_and_recovers(
|
|
259
|
+
self, mock_send, cert_bytes, expected_cause, workload_cert_config
|
|
260
|
+
):
|
|
261
|
+
mock_send.return_value = make_response()
|
|
262
|
+
if cert_bytes is None:
|
|
263
|
+
workload_cert_config.remove()
|
|
264
|
+
else:
|
|
265
|
+
workload_cert_config.write_binary(cert_bytes)
|
|
266
|
+
|
|
267
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
268
|
+
with pytest.raises(exceptions.TransportError) as exc_info:
|
|
269
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
270
|
+
assert isinstance(exc_info.value.__cause__, expected_cause)
|
|
271
|
+
assert request._mtls_unavailable is False
|
|
272
|
+
|
|
273
|
+
workload_cert_config.write_binary(pytest.public_cert_bytes)
|
|
274
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
275
|
+
assert isinstance(
|
|
276
|
+
request._mtls_adapter,
|
|
277
|
+
google.auth.transport.requests._MutualTlsAdapter,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
@pytest.mark.parametrize(
|
|
281
|
+
"request_kwargs",
|
|
282
|
+
[
|
|
283
|
+
{"verify": "/nonexistent/path/ca.pem"},
|
|
284
|
+
{"cert": ("/nonexistent/path/cert.pem", "/nonexistent/path/key.pem")},
|
|
285
|
+
],
|
|
286
|
+
)
|
|
287
|
+
def test_session_request_missing_cert_or_ca_raises_oserror(self, request_kwargs):
|
|
288
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
289
|
+
|
|
290
|
+
with pytest.raises(OSError) as exc_info:
|
|
291
|
+
request("https://oauth2.googleapis.com/token", **request_kwargs)
|
|
292
|
+
|
|
293
|
+
assert not isinstance(exc_info.value, exceptions.TransportError)
|
|
294
|
+
|
|
295
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
296
|
+
def test_mtls_deepcopy(self, mock_send, workload_cert_config):
|
|
297
|
+
mock_send.return_value = make_response()
|
|
298
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
299
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
300
|
+
|
|
301
|
+
copied_request = copy.deepcopy(request)
|
|
302
|
+
copied_request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
303
|
+
|
|
304
|
+
assert copied_request.session is not request.session
|
|
305
|
+
assert copied_request._mtls_lock is not request._mtls_lock
|
|
306
|
+
assert copied_request._mtls_adapter is not request._mtls_adapter
|
|
307
|
+
assert (
|
|
308
|
+
copied_request._mtls_adapter._ctx_poolmanager
|
|
309
|
+
is request._mtls_adapter._ctx_poolmanager
|
|
310
|
+
)
|
|
311
|
+
assert (
|
|
312
|
+
copied_request._mtls_adapter._ctx_proxymanager
|
|
313
|
+
is request._mtls_adapter._ctx_proxymanager
|
|
314
|
+
)
|
|
315
|
+
assert (
|
|
316
|
+
copied_request._mtls_adapter.poolmanager
|
|
317
|
+
is not request._mtls_adapter.poolmanager
|
|
318
|
+
)
|
|
319
|
+
assert mock_send.call_args_list[1].args[0] is copied_request._mtls_adapter
|
|
320
|
+
|
|
321
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
322
|
+
def test_mtls_pickle(self, mock_send, workload_cert_config):
|
|
323
|
+
mock_send.return_value = make_response()
|
|
324
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
325
|
+
request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
326
|
+
prefix = "https://iamcredentials.mtls.googleapis.com/"
|
|
327
|
+
assert isinstance(
|
|
328
|
+
request._mtls_adapter,
|
|
329
|
+
google.auth.transport.requests._MutualTlsAdapter,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
unpickled_request = pickle.loads(pickle.dumps(request))
|
|
333
|
+
|
|
334
|
+
assert unpickled_request.session is not request.session
|
|
335
|
+
assert unpickled_request._mtls_lock is not request._mtls_lock
|
|
336
|
+
assert unpickled_request._mtls_adapter is None
|
|
337
|
+
assert unpickled_request._mtls_unavailable is False
|
|
338
|
+
assert (
|
|
339
|
+
type(unpickled_request.session.adapters[prefix])
|
|
340
|
+
is requests.adapters.HTTPAdapter
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
unpickled_request("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
344
|
+
assert isinstance(
|
|
345
|
+
unpickled_request._mtls_adapter,
|
|
346
|
+
google.auth.transport.requests._MutualTlsAdapter,
|
|
347
|
+
)
|
|
348
|
+
assert (
|
|
349
|
+
unpickled_request.session.adapters[prefix]
|
|
350
|
+
is unpickled_request._mtls_adapter
|
|
351
|
+
)
|
|
352
|
+
assert mock_send.call_args_list[1].args[0] is unpickled_request._mtls_adapter
|
|
353
|
+
|
|
354
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
355
|
+
def test_mtls_legacy_pickle(self, mock_send, workload_cert_config):
|
|
356
|
+
mock_send.return_value = make_response()
|
|
357
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
358
|
+
with mock.patch.object(
|
|
359
|
+
google.auth.transport.requests.Request,
|
|
360
|
+
"__getstate__",
|
|
361
|
+
return_value={"session": request.session},
|
|
362
|
+
):
|
|
363
|
+
legacy_pickled = pickle.dumps(request)
|
|
364
|
+
unpickled_legacy = pickle.loads(legacy_pickled)
|
|
365
|
+
assert unpickled_legacy._mtls_adapter is None
|
|
366
|
+
assert unpickled_legacy._mtls_unavailable is False
|
|
367
|
+
|
|
368
|
+
unpickled_legacy("https://iamcredentials.mtls.googleapis.com/v1/token")
|
|
369
|
+
prefix = "https://iamcredentials.mtls.googleapis.com/"
|
|
370
|
+
assert isinstance(
|
|
371
|
+
unpickled_legacy._mtls_adapter,
|
|
372
|
+
google.auth.transport.requests._MutualTlsAdapter,
|
|
373
|
+
)
|
|
374
|
+
assert (
|
|
375
|
+
unpickled_legacy.session.adapters[prefix] is unpickled_legacy._mtls_adapter
|
|
376
|
+
)
|
|
377
|
+
assert mock_send.call_args.args[0] is unpickled_legacy._mtls_adapter
|
|
378
|
+
|
|
379
|
+
@mock.patch.object(requests.adapters.HTTPAdapter, "send", autospec=True)
|
|
380
|
+
def test_mtls_request_verify_false(self, mock_send, workload_cert_config):
|
|
381
|
+
mock_send.return_value = make_response()
|
|
382
|
+
request = google.auth.transport.requests.Request(requests.Session())
|
|
383
|
+
|
|
384
|
+
response = request(
|
|
385
|
+
"https://iamcredentials.mtls.googleapis.com/v1/token", verify=False
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
assert response.status == http_client.OK
|
|
389
|
+
mock_send.assert_called_once()
|
|
390
|
+
assert isinstance(
|
|
391
|
+
mock_send.call_args.args[0],
|
|
392
|
+
google.auth.transport.requests._MutualTlsAdapter,
|
|
393
|
+
)
|
|
394
|
+
assert mock_send.call_args.kwargs["verify"] is False
|
|
395
|
+
|
|
68
396
|
|
|
69
397
|
class TestTimeoutGuard(object):
|
|
70
398
|
def make_guard(self, *args, **kwargs):
|
|
@@ -182,12 +510,25 @@ class TestMutualTlsAdapter(object):
|
|
|
182
510
|
pytest.public_cert_bytes, pytest.private_key_bytes
|
|
183
511
|
)
|
|
184
512
|
|
|
513
|
+
assert adapter._ctx_poolmanager.check_hostname is False
|
|
514
|
+
assert adapter._ctx_proxymanager.check_hostname is False
|
|
515
|
+
|
|
185
516
|
adapter.init_poolmanager()
|
|
186
517
|
mock_init_poolmanager.assert_called_with(ssl_context=adapter._ctx_poolmanager)
|
|
187
518
|
|
|
188
519
|
adapter.proxy_manager_for()
|
|
189
520
|
mock_proxy_manager_for.assert_called_with(ssl_context=adapter._ctx_proxymanager)
|
|
190
521
|
|
|
522
|
+
def test_verify_false_compatibility(self):
|
|
523
|
+
adapter = google.auth.transport.requests._MutualTlsAdapter(
|
|
524
|
+
pytest.public_cert_bytes, pytest.private_key_bytes
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
adapter._ctx_poolmanager.verify_mode = ssl.CERT_NONE
|
|
528
|
+
adapter._ctx_proxymanager.verify_mode = ssl.CERT_NONE
|
|
529
|
+
assert adapter._ctx_poolmanager.verify_mode == ssl.CERT_NONE
|
|
530
|
+
assert adapter._ctx_proxymanager.verify_mode == ssl.CERT_NONE
|
|
531
|
+
|
|
191
532
|
def test_invalid_cert_or_key(self):
|
|
192
533
|
with pytest.raises(exceptions.MutualTLSChannelError):
|
|
193
534
|
google.auth.transport.requests._MutualTlsAdapter(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|