Esempio n. 1
0
async def test_https_proxy_unsupported_tls_in_tls(
    client_ssl_ctx,
    secure_proxy_url,
    web_server_endpoint_type,
) -> None:
    """Ensure connecting to TLS endpoints w/ HTTPS proxy needs patching.

    This also checks that a helpful warning on how to patch the env
    is displayed.
    """
    url = URL.build(scheme=web_server_endpoint_type, host="python.org")

    escaped_host_port = ":".join((url.host.replace(".", r"\."), str(url.port)))
    escaped_proxy_url = str(secure_proxy_url).replace(".", r"\.")

    conn = aiohttp.TCPConnector()
    sess = aiohttp.ClientSession(connector=conn)

    expected_warning_text = (
        r"^"
        r"An HTTPS request is being sent through an HTTPS proxy\. "
        "This support for TLS in TLS is known to be disabled "
        r"in the stdlib asyncio\. This is why you'll probably see "
        r"an error in the log below\.\n\n"
        "It is possible to enable it via monkeypatching under "
        r"Python 3\.7 or higher\. For more details, see:\n"
        r"\* https://bugs\.python\.org/issue37179\n"
        r"\* https://github\.com/python/cpython/pull/28073\n\n"
        r"You can temporarily patch this as follows:\n"
        r"\* https://docs\.aiohttp\.org/en/stable/client_advanced\.html#proxy-support\n"
        r"\* https://github\.com/aio-libs/aiohttp/discussions/6044\n$"
    )
    type_err = (
        r"transport <asyncio\.sslproto\._SSLProtocolTransport object at "
        r"0x[\d\w]+> is not supported by start_tls\(\)"
    )
    expected_exception_reason = (
        r"^"
        "Cannot initialize a TLS-in-TLS connection to host "
        f"{escaped_host_port!s} through an underlying connection "
        f"to an HTTPS proxy {escaped_proxy_url!s} ssl:{client_ssl_ctx!s} "
        f"[{type_err!s}]"
        r"$"
    )

    with pytest.warns(RuntimeWarning, match=expected_warning_text,), pytest.raises(
        ClientConnectionError,
        match=expected_exception_reason,
    ) as conn_err:
        await sess.get(url, proxy=secure_proxy_url, ssl=client_ssl_ctx)

    assert type(conn_err.value.__cause__) == TypeError
    assert match_regex(f"^{type_err!s}$", str(conn_err.value.__cause__))

    await sess.close()
    await conn.close()
Esempio n. 2
0
        def check_user_messages(message):
            user_message_begin_index = 3
            split_line = message.split(" ")

            if split_line[1] == "MODE":
                name = match_regex(r"-o (\S*)", message)
                if name is not None:
                    try_op(name.group(1))

            elif len(split_line) >= user_message_begin_index:
                if split_line[user_message_begin_index] == ":.botquit":
                    disconnect()
                    return NextExecutionStep.RETURN

                if split_line[user_message_begin_index] == ":.get":
                    print(message)
                    match = match_regex(":([^!]*)!.*?:\.get ([\S ]*)", message)
                    name = match.group(1)
                    message = match.group(2).replace(" ", "_")
                    url = "https://en.wikipedia.org/wiki/" + message.lower()
                    send_data("PRIVMSG %s" % (channel + " :" + name + ": " + url))

            return NextExecutionStep.DO_NOTHING
Esempio n. 3
0
        def check_user_messages(message):
            user_message_begin_index = 3
            split_line = message.split(" ")

            if split_line[1] == "MODE":
                name = match_regex(r"-o (\S*)", message)
                if name is not None:
                    try_op(name.group(1))

            elif len(split_line) >= user_message_begin_index:
                if split_line[user_message_begin_index] == ":.botquit":
                    disconnect()
                    return NextExecutionStep.RETURN

                if split_line[user_message_begin_index] == ":.get":
                    print(message)
                    match = match_regex(":([^!]*)!.*?:\.get ([\S ]*)", message)
                    name = match.group(1)
                    message = match.group(2).replace(" ", "_")
                    url = "https://en.wikipedia.org/wiki/" + message.lower()
                    send_data("PRIVMSG %s" %
                              (channel + " :" + name + ": " + url))

            return NextExecutionStep.DO_NOTHING
Esempio n. 4
0
        def check_server_messages(message):
            split_line = message.split(" ")
            if split_line[0] == "PING":
                send_data("PONG %s" % split_line[1])

            elif split_line[1] == "JOIN":
                name = match_regex(r":([^!]*)!", split_line[0]).group(1)
                if not (name is None or name == nick_name or name == user_name):
                    send_data("PRIVMSG %s" % (channel + " :Hello, " + name))
                    try_op(name)

            else:
                return NextExecutionStep.DO_NOTHING

            return NextExecutionStep.CONTINUE
Esempio n. 5
0
        def check_server_messages(message):
            split_line = message.split(" ")
            if split_line[0] == "PING":
                send_data("PONG %s" % split_line[1])

            elif split_line[1] == "JOIN":
                name = match_regex(r":([^!]*)!", split_line[0]).group(1)
                if not (name is None or name == nick_name
                        or name == user_name):
                    send_data("PRIVMSG %s" % (channel + " :Hello, " + name))
                    try_op(name)

            else:
                return NextExecutionStep.DO_NOTHING

            return NextExecutionStep.CONTINUE