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()
示例#2
0
    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)
示例#3
0
    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()
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
    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)