'If the connection closes at any point 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
the reason for the lost connection.'

def test_connectionClosedBeforeSecure(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 = StringTransport()
    factory = self.reactor.tcpClients[0][2]
    client = factory.buildProtocol(None)
    client.makeConnection(transport)
    client.connectionLost(Failure(ConnectionDone()))
    self.failureResultOf(d).trap(ConnectionDone)
