Skip to content

Can't make an HTTPS request with 'no verify' mode using aiohttp when Mocket is active #216

@ento

Description

@ento

Calling aiohttp's API with ssl=False fails:

from mocket.async_mocket import async_mocketize
from mocket.mockhttp import Entry

try:
    import aiohttp

    ENABLE_TEST_CLASS = True
except ImportError:
    ENABLE_TEST_CLASS = False

if ENABLE_TEST_CLASS:
    class AioHttpsEntryTestCase(IsolatedAsyncioTestCase):
        @async_mocketize
        async def test_no_verify(self):
            Entry.single_register(Entry.GET, self.target_url, status=404)

            async with aiohttp.ClientSession(timeout=self.timeout) as session:
                async with session.get(self.target_url, ssl=False) as get_response:
                    assert get_response.status == 404

This fails like so:

verified = False

    @staticmethod
    @functools.lru_cache(None)
    def _make_ssl_context(verified: bool) -> SSLContext:
        if verified:
            return ssl.create_default_context()
        else:
            sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
            sslcontext.options |= ssl.OP_NO_SSLv2
            sslcontext.options |= ssl.OP_NO_SSLv3
            sslcontext.check_hostname = False
            sslcontext.verify_mode = ssl.CERT_NONE
            try:
                sslcontext.options |= ssl.OP_NO_COMPRESSION
            except AttributeError as attr_err:
                warnings.warn(
                    "{!s}: The Python interpreter is compiled "
                    "against OpenSSL < 1.0.0. Ref: "
                    "https://docs.python.org/3/library/ssl.html"
                    "#ssl.OP_NO_COMPRESSION".format(attr_err),
                )
>           sslcontext.set_default_verify_paths()
E           TypeError: 'NoneType' object is not callable

.devenv/state/venv/lib/python3.11/site-packages/aiohttp/connector.py:936: TypeError

Versions used:
aiohttp: 3.9.1
mocket: cdd2eb8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions