telepathy-gabble: jingle: correctly send back unknown-session errors

Will Thompson wjt at kemper.freedesktop.org
Fri Nov 23 10:30:37 PST 2012


Module: telepathy-gabble
Branch: master
Commit: ecee60dfc33f05e56eb2d2b34faf188943ff8931
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=ecee60dfc33f05e56eb2d2b34faf188943ff8931

Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Nov 23 18:26:20 2012 +0000

jingle: correctly send back unknown-session errors

I broke this in c1be75d9 but it wasn't tested. Luckily
WOCKY_JINGLE_ERROR_UNKNOWN_SESSION (2) is a valid WockyXmppError too so
we didn't crash before, we just sent <gone> instead.

https://bugs.freedesktop.org/show_bug.cgi?id=33789 is relevant.

---

 src/jingle-factory.c                    |    2 +-
 tests/twisted/Makefile.am               |    1 +
 tests/twisted/jingle/unknown-session.py |   38 +++++++++++++++++++++++++++++++
 tests/twisted/ns.py                     |    1 +
 4 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/src/jingle-factory.c b/src/jingle-factory.c
index 0e9f6f7..2451dd6 100644
--- a/src/jingle-factory.c
+++ b/src/jingle-factory.c
@@ -367,7 +367,7 @@ ensure_session (GabbleJingleFactory *self,
         }
       else
         {
-          g_set_error (error, WOCKY_XMPP_ERROR,
+          g_set_error (error, WOCKY_JINGLE_ERROR,
               WOCKY_JINGLE_ERROR_UNKNOWN_SESSION,
               "session %s is unknown", sid);
           return NULL;
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index eff6454..bd39290 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -215,6 +215,7 @@ TWISTED_JINGLE_TESTS = \
 	jingle/test-wait-for-caps-incomplete.py \
 	jingle/test-wait-for-caps.py \
 	jingle/transport-info-parsing.py \
+	jingle/unknown-session.py \
 	$(NULL)
 
 TWISTED_FT_TESTS = \
diff --git a/tests/twisted/jingle/unknown-session.py b/tests/twisted/jingle/unknown-session.py
new file mode 100644
index 0000000..68c97c6
--- /dev/null
+++ b/tests/twisted/jingle/unknown-session.py
@@ -0,0 +1,38 @@
+"""
+Tests that Gabble doesn't explode if it gets Jingle stanzas for unknown
+sessions.
+"""
+
+from gabbletest import exec_test
+from servicetest import assertEquals
+from jingletest2 import JingleProtocol031
+import ns
+
+def assertHasChild(node, uri, name):
+    try:
+        node.elements(uri=uri, name=name).next()
+    except StopIteration:
+        raise AssertionError(
+            "Expected <%s xmlns='%s'> to be a child of\n    %s" % (
+            name, uri, node.toXml()))
+
+def test_send_action_for_unknown_session(q, bus, conn, stream):
+    jp = JingleProtocol031()
+    peer = 'guybrush at threepwo.od'
+
+    iq = jp.SetIq(peer, 'test at localhost',
+        [ jp.Jingle('fine-leather-jackets', peer, 'session-info', [])
+        ])
+    stream.send(jp.xml(iq))
+
+    e = q.expect('stream-iq', iq_type='error', iq_id=iq[2]['id'])
+    stanza = e.stanza
+    error_node = stanza.children[-1]
+    assertEquals('error', error_node.name)
+
+    # http://xmpp.org/extensions/xep-0166.html#example-29
+    assertHasChild(error_node, ns.STANZA, 'item-not-found')
+    assertHasChild(error_node, ns.JINGLE_ERRORS, 'unknown-session')
+
+if __name__ == '__main__':
+    exec_test(test_send_action_for_unknown_session)
diff --git a/tests/twisted/ns.py b/tests/twisted/ns.py
index 458e4e1..48b656b 100644
--- a/tests/twisted/ns.py
+++ b/tests/twisted/ns.py
@@ -26,6 +26,7 @@ JINGLE_015 = "http://jabber.org/protocol/jingle"
 JINGLE_015_AUDIO = "http://jabber.org/protocol/jingle/description/audio"
 JINGLE_015_VIDEO = "http://jabber.org/protocol/jingle/description/video"
 JINGLE = "urn:xmpp:jingle:1"
+JINGLE_ERRORS = "urn:xmpp:jingle:errors:1"
 JINGLE_RTP = "urn:xmpp:jingle:apps:rtp:1"
 JINGLE_RTP_AUDIO = "urn:xmpp:jingle:apps:rtp:audio"
 JINGLE_RTP_VIDEO = "urn:xmpp:jingle:apps:rtp:video"



More information about the telepathy-commits mailing list