|
Revision 10435, 1.3 kB
(checked in by asterix, 2 months ago)
|
|
[dwd] fix reconnection when we get wrong XML with undeclared namespaces. Fixes #3083
|
| Line | |
|---|
| 1 | # tests for xmpppy's dispatcher_nb.py |
|---|
| 2 | import unittest |
|---|
| 3 | |
|---|
| 4 | import lib |
|---|
| 5 | lib.setup_env() |
|---|
| 6 | |
|---|
| 7 | from mock import Mock |
|---|
| 8 | |
|---|
| 9 | from common.xmpp import dispatcher_nb |
|---|
| 10 | from common.xmpp import auth |
|---|
| 11 | |
|---|
| 12 | class TestDispatcherNB(unittest.TestCase): |
|---|
| 13 | def test_unbound_namespace_prefix(self): |
|---|
| 14 | '''tests our handling of a message with an unbound namespace prefix''' |
|---|
| 15 | d = dispatcher_nb.Dispatcher() |
|---|
| 16 | |
|---|
| 17 | conn = Mock() |
|---|
| 18 | |
|---|
| 19 | owner = Mock() |
|---|
| 20 | owner._caller = Mock() |
|---|
| 21 | owner.defaultNamespace = auth.NS_CLIENT |
|---|
| 22 | owner.debug_flags = [] |
|---|
| 23 | owner.Connection = conn |
|---|
| 24 | owner._component = False |
|---|
| 25 | |
|---|
| 26 | d._owner = owner |
|---|
| 27 | d.plugin(owner) |
|---|
| 28 | |
|---|
| 29 | msgs = [] |
|---|
| 30 | |
|---|
| 31 | def _got_message(conn, msg): |
|---|
| 32 | msgs.append(msg) |
|---|
| 33 | |
|---|
| 34 | d.RegisterHandler('message', _got_message) |
|---|
| 35 | |
|---|
| 36 | d.StreamInit() |
|---|
| 37 | |
|---|
| 38 | d.ProcessNonBlocking("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>") |
|---|
| 39 | |
|---|
| 40 | # should be able to parse a normal message |
|---|
| 41 | d.ProcessNonBlocking('<message><body>hello</body></message>') |
|---|
| 42 | self.assertEqual(1, len(msgs)) |
|---|
| 43 | |
|---|
| 44 | d.ProcessNonBlocking('<message><x:y/></message>') |
|---|
| 45 | # we should not have been disconnected after that message |
|---|
| 46 | self.assertEqual(0, len(conn.mockGetNamedCalls('pollend'))) |
|---|
| 47 | |
|---|
| 48 | # we should be able to keep parsing |
|---|
| 49 | d.ProcessNonBlocking('<message><body>still here?</body></message>') |
|---|
| 50 | self.assertEqual(3, len(msgs)) |
|---|
| 51 | |
|---|
| 52 | if __name__ == '__main__': |
|---|
| 53 | unittest.main() |
|---|
| 54 | |
|---|
| 55 | # vim: se ts=3: |
|---|