[python] honor assert_hostname in the asyncio and httpx clients
The urllib3 client passes Configuration.assert_hostname to the pool manager, but the asyncio (aiohttp) and httpx clients never read it, so assert_hostname=False has no effect there.
This sets ssl_context.check_hostname from it when verify_ssl is on. With verify_ssl off it is left alone, so certificate verification is not switched back on.
Context: the Kubernetes Python client hit this in its asyncio client (kubernetes-client/python#2795). The maintainers asked for the fix here in the generator rather than as a post-processing patch (kubernetes-client/gen#314).
Changes:
python/asyncio/rest.mustacheandpython/httpx/rest.mustache- regenerated
rest.pyin the python-aiohttp, python-httpx, python-httpx-sync, python-httpx2 and python-httpx2-sync samples - tests in the python-aiohttp and python-httpx samples (
TestAssertHostname): they fail on master and pass with this change. The rest of each sample suite is unchanged (the pet API tests need a running petstore server).
PR checklist
- Read the contribution guidelines.
- Updated samples: regenerated the five affected samples with openapi-generator-cli 7.27.0 and the changed templates (
batch bin/configs/<config>.yaml); the generatedrest.pyfiles match the committed ones exactly. Onlyrest.mustachechanged, so no other generated file is affected. - @mention the technical committee: @cbornet @tomplus @krjakbrjak @fa0311 @AndreyVMarkelov
Summary by cubic
Honors assert_hostname in the asyncio (aiohttp) and httpx clients so assert_hostname=False disables hostname checks there, matching the urllib3 client. This fixes the Kubernetes Python client's asyncio client (kubernetes-client/python#2795). Hostname checking is only applied when verify_ssl is on, so disabling verification never re-enables it.
- Added tests in the aiohttp and httpx samples covering both cases.