'Test initializer failure to authenticate.'

def testFailAuth(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    a    not-authorized\n                                                stanza    error.\n                                                '
        response = error.StanzaError('not-authorized').toResponse(iq)
        self.pipe.source.send(response)
    d1 = self.waitFor(IQ_AUTH_GET, onAuthGet)
    d2 = self.init.initialize()
    self.assertFailure(d2, error.StanzaError)
    return defer.gatherResults([d1, d2])
