'Test plain-text authentication.
Act as a server supporting plain-text authentication and expect the
C{password} field to be filled with the password. Then act as if
authentication succeeds.'

def testPlainText(self):

    def onAuthGet(iq):
        '\n                                                Called    when    the    initializer    sent    a    query    for    authentication    methods.\n\n                                                The    response    informs    the    client    that    plain-text    authentication\n                                                is    supported.\n                                                '
        response = xmlstream.toResponse(iq, 'result')
        response.addElement(('jabber:iq:auth', 'query'))
        response.query.addElement('username')
        response.query.addElement('password')
        response.query.addElement('resource')
        d = self.waitFor(IQ_AUTH_SET, onAuthSet)
        self.pipe.source.send(response)
        return d
    def onAuthSet(iq):
        '\n                                                Called    when    the    initializer    sent    the    authentication    request.\n\n                                                The    server    checks    the    credentials    and    responds    with    an    empty    result\n                                                signalling    success.\n                                                '
        self.assertEqual('user', unicode(iq.query.username))
        self.assertEqual('secret', unicode(iq.query.password))
        self.assertEqual('resource', unicode(iq.query.resource))
        response = xmlstream.toResponse(iq, 'result')
        self.pipe.source.send(response)
    d1 = self.waitFor(IQ_AUTH_GET, onAuthGet)
    d2 = self.init.initialize()
    return defer.gatherResults([d1, d2])
