Skip to content

Use sslcompat hostname matcher in TSSLSocket#3413

Merged
Jens-G merged 1 commit intoapache:masterfrom
Jens-G:py-ssl-hostname
Apr 22, 2026
Merged

Use sslcompat hostname matcher in TSSLSocket#3413
Jens-G merged 1 commit intoapache:masterfrom
Jens-G:py-ssl-hostname

Conversation

@Jens-G
Copy link
Copy Markdown
Member

@Jens-G Jens-G commented Apr 22, 2026

Summary

TSSLSocket.py defined _match_hostname as a module-level no-op lambda, shadowing the more complete implementation already exported by the companion sslcompat module. The sslcompat module exists specifically to abstract over Python version differences in ssl.match_hostname: it provides the real implementation on Python < 3.12 and a no-op on Python 3.12+ (where ssl.match_hostname was removed and hostname verification is handled entirely by OpenSSL via check_hostname=True).

This change:

  • lib/py/src/transport/TSSLSocket.py: imports _match_hostname from sslcompat alongside the existing _match_has_ipaddress import; removes the inline no-op lambda definition.

Tests added in lib/py/test/test_sslsocket.py (TestMatchHostname class):

  • test_match_hostname_is_from_sslcompat: asserts TSSLSocket._match_hostname is sslcompat._match_hostname.
  • test_match_hostname_rejects_mismatch: on Python < 3.12, verifies a hostname mismatch raises an exception (skipped on 3.12+ where ssl.match_hostname no longer exists).

Test plan

  • python3 lib/py/test/test_sslsocket.py -v — two new matcher tests pass

🤖 Generated with Claude Code

Client: py

The module-level _match_hostname was defined inline as a no-op lambda,
shadowing the more complete implementation already exported by sslcompat.
Use the sslcompat version directly, removing the duplicate definition.
Python 3.12+ removed ssl.match_hostname entirely; the sslcompat fallback
is a no-op on that version by design.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jens-G Jens-G requested a review from mhlakhani as a code owner April 22, 2026 00:30
@mergeable mergeable Bot added the python label Apr 22, 2026
@Jens-G Jens-G merged commit 87a8695 into apache:master Apr 22, 2026
86 of 87 checks passed
@Jens-G Jens-G deleted the py-ssl-hostname branch April 23, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants