'Test that the userauth server and client play nicely with each other.'

def test_loopback(self):

    server = userauth.SSHUserAuthServer()
    client = ClientUserAuth('foo', self.Factory.Service())
    server.transport = transport.SSHTransportBase()
    server.transport.service = server
    server.transport.isEncrypted = (lambda x: True)
    client.transport = transport.SSHTransportBase()
    client.transport.service = client
    server.transport.sessionID = client.transport.sessionID = ''
    server.transport.sendKexInit = client.transport.sendKexInit = (lambda : None)
    server.transport.factory = self.Factory()
    server.passwordDelay = 0
    realm = Realm()
    portal = Portal(realm)
    checker = SSHProtocolChecker()
    checker.registerChecker(PasswordChecker())
    checker.registerChecker(PrivateKeyChecker())
    checker.areDone = (lambda aId: (len(checker.successfulCredentials[aId]) == 2))
    portal.registerChecker(checker)
    server.transport.factory.portal = portal
    d = loopback.loopbackAsync(server.transport, client.transport)
    server.transport.transport.logPrefix = (lambda : '_ServerLoopback')
    client.transport.transport.logPrefix = (lambda : '_ClientLoopback')
    server.serviceStarted()
    client.serviceStarted()
    def check(ignored):
        self.assertEqual(server.transport.service.name, 'TestService')
    return d.addCallback(check)
