#NEWLINE# def test_loseConnectionAfterHandshake( self ) : #NEWLINE# #INDENT# '\n        L{TLSMemoryBIOProtocol.loseConnection} sends a TLS close alert and\n        shuts down the underlying connection.\n        ' #NEWLINE# clientConnectionLost = Deferred ( ) #NEWLINE# clientFactory = ClientFactory ( ) #NEWLINE# clientFactory . protocol = ( lambda : ConnectionLostNotifyingProtocol ( clientConnectionLost ) ) #NEWLINE# ( clientContextFactory , handshakeDeferred ) = HandshakeCallbackContextFactory . factoryAndDeferred ( ) #NEWLINE# wrapperFactory = TLSMemoryBIOFactory ( clientContextFactory , True , clientFactory ) #NEWLINE# sslClientProtocol = wrapperFactory . buildProtocol ( None ) #NEWLINE# serverProtocol = Protocol ( ) #NEWLINE# serverFactory = ServerFactory ( ) #NEWLINE# serverFactory . protocol = ( lambda : serverProtocol ) #NEWLINE# serverContextFactory = DefaultOpenSSLContextFactory ( certPath , certPath ) #NEWLINE# wrapperFactory = TLSMemoryBIOFactory ( serverContextFactory , False , serverFactory ) #NEWLINE# sslServerProtocol = wrapperFactory . buildProtocol ( None ) #NEWLINE# connectionDeferred = loopbackAsync ( sslServerProtocol , sslClientProtocol ) #NEWLINE# def cbHandshake( ignored ) : #NEWLINE# #INDENT# serverProtocol . transport . loseConnection ( ) #NEWLINE# return clientConnectionLost #NEWLINE# #UNINDENT# handshakeDeferred . addCallback ( cbHandshake ) #NEWLINE# def cbConnectionDone( clientProtocol ) : #NEWLINE# #INDENT# clientProtocol . lostConnectionReason . trap ( ConnectionDone ) #NEWLINE# self . assertTrue ( serverProtocol . transport . q . disconnect ) #NEWLINE# self . assertTrue ( clientProtocol . transport . q . disconnect ) #NEWLINE# #UNINDENT# handshakeDeferred . addCallback ( cbConnectionDone ) #NEWLINE# return handshakeDeferred