def test_npn_success(self):
    '\n        Tests that clients and servers that agree on the negotiated next\n        protocol can correct establish a connection, and that the agreed\n        protocol is reported by the connections.\n        '
    advertise_args = []
    select_args = []

    def advertise(conn):
        advertise_args.append((conn,))
        return [b'http/1.1', b'spdy/2']

    def select(conn, options):
        select_args.append((conn, options))
        return b'spdy/2'
    server_context = Context(TLSv1_METHOD)
    server_context.set_npn_advertise_callback(advertise)
    client_context = Context(TLSv1_METHOD)
    client_context.set_npn_select_callback(select)
    server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
    server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
    server = Connection(server_context, None)
    server.set_accept_state()
    client = Connection(client_context, None)
    client.set_connect_state()
    interact_in_memory(server, client)
    assert (advertise_args == [(server,)])
    assert (select_args == [(client, [b'http/1.1', b'spdy/2'])])
    assert (server.get_next_proto_negotiated() == b'spdy/2')
    assert (client.get_next_proto_negotiated() == b'spdy/2')
Tests that clients and servers that agree on the negotiated next
protocol can correct establish a connection, and that the agreed
protocol is reported by the connections.
def test_npn_success(self):
    '\n        Tests that clients and servers that agree on the negotiated next\n        protocol can correct establish a connection, and that the agreed\n        protocol is reported by the connections.\n        '
    advertise_args = []
    select_args = []

    def advertise(conn):
        advertise_args.append((conn,))
        return [b'http/1.1', b'spdy/2']

    def select(conn, options):
        select_args.append((conn, options))
        return b'spdy/2'
    server_context = Context(TLSv1_METHOD)
    server_context.set_npn_advertise_callback(advertise)
    client_context = Context(TLSv1_METHOD)
    client_context.set_npn_select_callback(select)
    server_context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
    server_context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
    server = Connection(server_context, None)
    server.set_accept_state()
    client = Connection(client_context, None)
    client.set_connect_state()
    interact_in_memory(server, client)
    assert (advertise_args == [(server,)])
    assert (select_args == [(client, [b'http/1.1', b'spdy/2'])])
    assert (server.get_next_proto_negotiated() == b'spdy/2')
    assert (client.get_next_proto_negotiated() == b'spdy/2')