'When a client specifies a server name in its hello message, the callback
passed to :py:obj:`Contexts.set_tlsext_servername_callback` is invoked and the
result of :py:obj:`Connection.get_servername` is that server name.'

def test_servername(self):

    args = []
    def servername(conn):
        args.append((conn, conn.get_servername()))
    context = Context(TLSv1_METHOD)
    context.set_tlsext_servername_callback(servername)
    context.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
    context.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
    server = Connection(context, None)
    server.set_accept_state()
    client = Connection(Context(TLSv1_METHOD), None)
    client.set_connect_state()
    client.set_tlsext_host_name(b('foo1.example.com'))
    self._interactInMemory(server, client)
    self.assertEqual([(server, b('foo1.example.com'))], args)
