def onStreamError(self, errelem): """ Called when a stream:error element has been received. Dispatches a L{STREAM_ERROR_EVENT} event with the error element to allow for cleanup actions and drops the connection. @param errelem: The received error element. @type errelem: L{domish.Element} """ self.dispatch(failure.Failure(error.exceptionFromStreamError(errelem)), STREAM_ERROR_EVENT) self.transport.loseConnection()
def test_streamNoDialbackNamespace(self): """ Test stream error on missing dialback namespace. """ self.xmlstream.connectionMade() self.xmlstream.dataReceived( "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' " "xmlns='jabber:server' " "to='xmpp.example.com'>") self.assertEqual(3, len(self.output)) exc = error.exceptionFromStreamError(self.output[1]) self.assertEqual('invalid-namespace', exc.condition)
def test_streamRootElement(self): """ Test stream error on wrong stream namespace. """ self.xmlstream.connectionMade() self.xmlstream.dataReceived("<stream:stream xmlns:stream='badns' " "xmlns:db='jabber:server:dialback' " "xmlns='jabber:server' " "to='xmpp.example.com'>") self.assertEqual(3, len(self.output)) exc = error.exceptionFromStreamError(self.output[1]) self.assertEqual('invalid-namespace', exc.condition)
def test_streamToUnknownHost(self): """ Test stream error on stream's to attribute having unknown host. """ self.xmlstream.connectionMade() self.xmlstream.dataReceived( "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' " "xmlns:db='jabber:server:dialback' " "xmlns='jabber:server' " "to='badhost'>") self.assertEqual(3, len(self.output)) exc = error.exceptionFromStreamError(self.output[1]) self.assertEqual('host-unknown', exc.condition)
def test_streamRootElement(self): """ Test stream error on wrong stream namespace. """ self.xmlstream.connectionMade() self.xmlstream.dataReceived( "<stream:stream xmlns:stream='badns' " "xmlns:db='jabber:server:dialback' " "xmlns='jabber:server' " "to='xmpp.example.com'>") self.assertEqual(3, len(self.output)) exc = error.exceptionFromStreamError(self.output[1]) self.assertEqual('invalid-namespace', exc.condition)
def test_basic(self): """ Test basic operations of exceptionFromStreamError. Given a realistic stream error, check if a sane exception is returned. Using this error:: <stream:error xmlns:stream='http://etherx.jabber.org/streams'> <xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/> </stream:error> """ e = domish.Element(('http://etherx.jabber.org/streams', 'error')) e.addElement((NS_XMPP_STREAMS, 'xml-not-well-formed')) result = error.exceptionFromStreamError(e) self.assert_(isinstance(result, error.StreamError)) self.assertEqual('xml-not-well-formed', result.condition)