Implement AsyncOpenSearch() parameter ssl_assert_hostname (#843)

* Implement AsyncOpenSearch() parameter `ssl_assert_hostname` to allow disabling SSL hostname verification

Signed-off-by: merlinz01 <[email protected]>

* Update PR link

Signed-off-by: merlinz01 <[email protected]>

* Add test

Signed-off-by: merlinz01 <[email protected]>

* Update docs

Signed-off-by: merlinz01 <[email protected]>

* Add test for default value

Signed-off-by: merlinz01 <[email protected]>

* Fix formatting

Signed-off-by: merlinz01 <[email protected]>

* Fix test failing on Python >3.12.7

Signed-off-by: merlinz01 <[email protected]>

* Fix formatting

Signed-off-by: merlinz01 <[email protected]>

---------

Signed-off-by: merlinz01 <[email protected]>
Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
This commit is contained in:
Merlin
2024-11-16 08:29:10 -05:00
committed by GitHub
co-authored by Daniel Doubrovkine
parent 1269cdc95a
commit 12c379d32d
6 changed files with 39 additions and 7 deletions
@@ -29,6 +29,7 @@ import gzip
import io
import json
import ssl
import sys
import warnings
from platform import python_version
from typing import Any
@@ -97,6 +98,17 @@ class TestAIOHttpConnection:
assert con.use_ssl
assert con.session.connector._ssl == context
async def test_ssl_assert_hostname(self) -> None:
con = AIOHttpConnection(use_ssl=True, ssl_assert_hostname=True)
await con._create_aiohttp_session()
assert con.use_ssl
assert con.session.connector._ssl.check_hostname is True
con = AIOHttpConnection(use_ssl=True, ssl_assert_hostname=False)
await con._create_aiohttp_session()
assert con.use_ssl
assert con.session.connector._ssl.check_hostname is False
async def test_opaque_id(self) -> None:
con = AIOHttpConnection(opaque_id="app-1")
assert con.headers["x-opaque-id"] == "app-1"
@@ -217,7 +229,15 @@ class TestAIOHttpConnection:
use_ssl=True, verify_certs=False, ssl_show_warn=False
)
await con._create_aiohttp_session()
assert w == []
if sys.hexversion < 0x30C0700:
assert w == []
else:
assert len(w) == 1
assert (
str(w[0].message) == "enable_cleanup_closed ignored because "
"https://github.com/python/cpython/pull/118960 is fixed in "
"Python version sys.version_info(major=3, minor=12, micro=7, releaselevel='final', serial=0)"
)
assert isinstance(con.session, aiohttp.ClientSession)