':py:obj:`Context.add_extra_chain_cert` accepts an :py:obj:`X509` instance to add to
the certificate chain.
See :py:obj:`_create_certificate_chain` for the details of the certificate
chain tested.
The chain is tested by starting a server with scert and connecting
to it with a client which trusts cacert and requires verification to
succeed.'

def test_add_extra_chain_cert(self):

    chain = _create_certificate_chain()
    [(cakey, cacert), (ikey, icert), (skey, scert)] = chain
    for (cert, name) in [(cacert, 'ca.pem'), (icert, 'i.pem'), (scert, 's.pem')]:
        fObj = open(name, 'w')
        fObj.write(dump_certificate(FILETYPE_PEM, cert).decode('ascii'))
        fObj.close()
    for (key, name) in [(cakey, 'ca.key'), (ikey, 'i.key'), (skey, 's.key')]:
        fObj = open(name, 'w')
        fObj.write(dump_privatekey(FILETYPE_PEM, key).decode('ascii'))
        fObj.close()
    serverContext = Context(TLSv1_METHOD)
    serverContext.use_privatekey(skey)
    serverContext.use_certificate(scert)
    serverContext.add_extra_chain_cert(icert)
    clientContext = Context(TLSv1_METHOD)
    clientContext.set_verify((VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT), verify_cb)
    clientContext.load_verify_locations('ca.pem')
    self._handshake_test(serverContext, clientContext)
