fix(auth): pass an explicit protocol to ssl.SSLContext() in tests - #18187
Open
skippdot wants to merge 1 commit into
Open
fix(auth): pass an explicit protocol to ssl.SSLContext() in tests#18187skippdot wants to merge 1 commit into
skippdot wants to merge 1 commit into
Conversation
- Replace the ten bare `ssl.SSLContext()` calls in tests/transport/test__custom_tls_signer.py with `ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)` - Constructing an SSLContext without a protocol argument is deprecated since Python 3.10 and emits a DeprecationWarning on every run of this module - PROTOCOL_TLS_CLIENT matches what the library receives in production, where contexts come from `urllib3.util.ssl_.create_urllib3_context()`; the tests only hand the context to mocked native libraries and never inspect its verification settings, so no assertion depends on the bare-context defaults Fixes googleapis#17760
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates several test cases in test__custom_tls_signer.py to instantiate ssl.SSLContext with ssl.PROTOCOL_TLS_CLIENT instead of using the default constructor. There are no review comments to evaluate, and I have no feedback to provide.
macastelaz
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17760
Constructing
ssl.SSLContext()without a protocol argument is deprecated since Python 3.10.tests/transport/test__custom_tls_signer.pydoes this ten times, so every run of the module emits 20DeprecationWarnings (two per call site on 3.14).Change
Replace each bare
ssl.SSLContext()withssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT). One file, +10/−10.Why
PROTOCOL_TLS_CLIENTis the right protocoltransport/requests.pyandtransport/urllib3.pyobtain their contexts fromurllib3.util.ssl_.create_urllib3_context(), which builds them withPROTOCOL_TLS_CLIENT. The tests now exerciseattach_to_ssl_context()with the same kind of context the real code passes in.check_hostname,verify_modeorprotocol; they only hand the context to mocked native libraries via_cast_ssl_ctx_to_void_p_stdlib. So the stricter defaults of a client context (check_hostname=True,verify_mode=CERT_REQUIRED) do not affect any assertion.Verification
tests/transport/test__custom_tls_signer.pyon Python 3.10 and 3.14: 22 passed;without protocolwarnings 20 → 0.google-authunit suite on 3.10 and 3.14: all passing apart from two pre-existingtest_id_tokenfailures caused by a missing optionaljwtmodule in the local environment (identical on an unmodifiedmain).black --checkandflake8 --import-order-style=googleclean.