'Test serving over SSL'

def test_ssl(self):

    address = u'127.0.0.1'
    with TemporaryDirectory(u'srv-test-ssl') as tdir:
        (cert_file, key_file, ca_file) = map((lambda x: os.path.join(tdir, x)), u'cka')
        create_server_cert(address, ca_file, cert_file, key_file, key_size=1024)
        ctx = ssl.create_default_context(cafile=ca_file)
        with TestServer((lambda data: (data.path[0] + data.read())), ssl_certfile=cert_file, ssl_keyfile=key_file, listen_on=address, port=0) as server:
            conn = httplib.HTTPSConnection(address, server.address[1], strict=True, context=ctx)
            conn.request(u'GET', u'/test', u'body')
            r = conn.getresponse()
            self.ae(r.status, httplib.OK)
            self.ae(r.read(), 'testbody')
            cert = conn.sock.getpeercert()
            subject = dict((x[0] for x in cert[u'subject']))
            self.ae(subject[u'commonName'], address)
