'If the connection is cancelled before the SSH transport layer has
finished key exchange (ie, gotten to the point where we may attempt to
authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
L{CancelledError} and the connection is aborted.'

def test_connectionCancelledBeforeSecure(self):

    endpoint = SSHCommandClientEndpoint.newConnection(self.reactor, '/bin/ls    -l', 'dummy    user', self.hostname, self.port, knownHosts=self.knownHosts, ui=FixedResponseUI(False))
    factory = Factory()
    factory.protocol = Protocol
    d = endpoint.connect(factory)
    transport = AbortableFakeTransport(None, isServer=False)
    factory = self.reactor.tcpClients[0][2]
    client = factory.buildProtocol(None)
    client.makeConnection(transport)
    d.cancel()
    self.failureResultOf(d).trap(CancelledError)
    self.assertTrue(transport.aborted)
    client.connectionLost(Failure(ConnectionDone()))
