def test_value_error(): reset_match_hostname() patch_match_hostname() with pytest.raises(ssl.CertificateError): cert = {'subject': ((('commonName', '.net'), ), )} ssl.match_hostname(cert, '.com')
def test_match_hostname_not_py370(): reset_match_hostname() patch_match_hostname() cert = { 'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'), ), ) } # noqa ssl.match_hostname(cert, 'цфоут.мвд.рф') cert = {'subject': ((('commonName', 'xn--einla-pqa.de'), ), )} ssl.match_hostname(cert, 'einlaß.de')
def test_match_hostname(): reset_match_hostname() patch_match_hostname() cert = { 'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'), ), ) } ssl.match_hostname(cert, 'xn--n1aiccj.xn--b1aew.xn--p1ai') cert = {'subject': ((('commonName', 'xn--einla-pqa.de'), ), )} ssl.match_hostname(cert, 'xn--einla-pqa.de') cert = {'subject': ((('commonName', 'abc_def.com'), ), )} ssl.match_hostname(cert, 'abc_def.com') cert = {'subject': ((('commonName', '::1'), ), )} ssl.match_hostname(cert, '::1')
async def test_aiohttp(loop): reset_match_hostname() url = 'https://цфоут.мвд.рф/news/item/8065038/' with pytest.raises(aiohttp.ClientConnectorCertificateError): async with aiohttp.ClientSession(loop=loop) as session: async with session.get(url) as response: await response.read() patch_match_hostname() async with aiohttp.ClientSession(loop=loop) as session: async with session.get(url) as response: await response.read() assert response.status == 200
def test_patch(): reset_match_hostname() assert not hasattr(ssl.match_hostname, 'patched') patch_match_hostname() assert hasattr(ssl.match_hostname, 'patched') patch_match_hostname() assert hasattr(ssl.match_hostname, 'patched') reset_match_hostname() assert not hasattr(ssl.match_hostname, 'patched') reset_match_hostname() assert not hasattr(ssl.match_hostname, 'patched')
def test_match_hostname(): reset_match_hostname() patch_match_hostname() cert = {'subject': ((('commonName', 'цфоут.мвд.рф'), ), )} ssl.match_hostname(cert, 'цфоут.мвд.рф') cert = { 'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'), ), ) } ssl.match_hostname(cert, 'xn--n1aiccj.xn--b1aew.xn--p1ai') cert = { 'subject': ((('commonName', 'xn--n1aiccj.xn--b1aew.xn--p1ai'), ), ) } ssl.match_hostname(cert, 'цфоут.мвд.рф') with pytest.raises(ssl.CertificateError): cert = {'subject': ((('commonName', 'цфоут.мвд.рф'), ), )} ssl.match_hostname(cert, 'xn--n1aiccj.xn--b1aew.xn--p1ai')
from typing_extensions import final from yarl import URL from . import hdrs from .log import client_logger from .typedefs import PathLike # noqa __all__ = ('BasicAuth', 'ChainMapProxy') PY_36 = sys.version_info >= (3, 6) PY_37 = sys.version_info >= (3, 7) PY_38 = sys.version_info >= (3, 8) if not PY_37: import idna_ssl idna_ssl.patch_match_hostname() try: from typing import ContextManager except ImportError: from typing_extensions import ContextManager def all_tasks( loop: Optional[asyncio.AbstractEventLoop] = None ) -> Set['asyncio.Task[Any]']: tasks = list(asyncio.Task.all_tasks(loop)) return {t for t in tasks if not t.done()} if PY_37:
PY_34 = sys.version_info < (3, 5) PY_35 = sys.version_info >= (3, 5) PY_352 = sys.version_info >= (3, 5, 2) if sys.version_info >= (3, 4, 3): from http.cookies import SimpleCookie # noqa else: from .backport_cookies import SimpleCookie # noqa __all__ = ('BasicAuth', 'Timeout') if sys.version_info < (3, 7): import idna_ssl idna_ssl.patch_match_hostname() sentinel = object() Timeout = timeout NO_EXTENSIONS = bool(os.environ.get('AIOHTTP_NO_EXTENSIONS')) CHAR = set(chr(i) for i in range(0, 128)) CTL = set(chr(i) for i in range(0, 32)) | {chr(127), } SEPARATORS = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', chr(9)} TOKEN = CHAR ^ CTL ^ SEPARATORS if PY_35: from collections.abc import Coroutine
from idna_ssl import patch_match_hostname # noqa isort:skip patch_match_hostname() # noqa isort:skip import asyncio import aiohttp URL = 'https://цфоут.мвд.рф/news/item/8065038/' async def main(): async with aiohttp.ClientSession() as session: async with session.get(URL) as response: print(response) loop = asyncio.get_event_loop() loop.run_until_complete(main())