From 66a51766ac455f2ac9bbb2662bba954cdcacd81f Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 25 Feb 2013 09:51:46 +0000 Subject: [PATCH 6/6] Test for #61433 and #39464 Backported: Simon McVittie --- tests/twisted/caps/hashed-caps.py | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/tests/twisted/caps/hashed-caps.py b/tests/twisted/caps/hashed-caps.py index b9c40b1..4324f88 100644 --- a/tests/twisted/caps/hashed-caps.py +++ b/tests/twisted/caps/hashed-caps.py @@ -24,7 +24,7 @@ import dbus from twisted.words.xish import xpath -from gabbletest import exec_test, make_result_iq, make_presence, sync_stream +from gabbletest import exec_test, make_result_iq, make_presence, sync_stream, elem from servicetest import sync_dbus, EventPattern, assertLength import constants as cs import ns @@ -290,6 +290,81 @@ def test_two_clients(q, bus, conn, stream, contact1, contact2, sync_dbus(bus, q, conn) assert caps_changed_flag == False +def test_39464(q, bus, conn, stream): + """ + Regression test for an issue where a form with no type='' attribute on the + node would crash Gabble. + """ + client = 'fake:qutim' + hash = 'blahblah' + contact = 'bug-39464@example.com/foo' + caps = { + 'node': client, + 'ver': hash, + 'hash': 'sha-1', + } + presence = make_presence(contact, status='hello', caps=caps) + stream.send(presence) + + # Gabble looks up our capabilities + event = q.expect('stream-iq', to=contact, query_ns=ns.DISCO_INFO) + + # Send a reply with a form without a type='' + result = make_result_iq(stream, event.stanza, add_query_node=False) + result.addChild( + elem(ns.DISCO_INFO, 'query', node='%s#%s' % (client, hash))( + # NB. no type='' attribute + elem(ns.X_DATA, 'x') + ) + ) + stream.send(result) + # We don't really care what Gabble does, as long as it doesn't crash. + sync_stream(q, stream) + +def test_no_var(q, bus, conn, stream): + """ + Regression test for a form containing an anonymous fixed field (legal, but + meaningless in this context and undefined by the hashing algorithm) + crashing us. + """ + client = 'evil@person' + hash = 'f00f00' + contact = 'bug-61433@example.com/foo' + caps = { + 'node': client, + 'ver': hash, + 'hash': 'sha-1', + } + presence = make_presence(contact, status='hello', caps=caps) + stream.send(presence) + + # Gabble looks up our capabilities + event = q.expect('stream-iq', to=contact, query_ns=ns.DISCO_INFO) + + # Send a reply with a form without a type='' + result = make_result_iq(stream, event.stanza, add_query_node=False) + result.addChild( + elem(ns.DISCO_INFO, 'query', node='%s#%s' % (client, hash))( + elem(ns.X_DATA, 'x', type='result')( + elem("field", var='FORM_TYPE', type='hidden')( + elem("value")( + u"urn:xmpp:dataforms:softwareinfo" + ) + ), + # No var='' attribute, which is legal on fixed fields, but pretty + # questionable in your caps. + elem("field", type="fixed")( + elem("value")( + u"HAHAHAHAHA" + ) + ) + ) + ) + ) + stream.send(result) + # We don't really care what Gabble does, as long as it doesn't crash. + sync_stream(q, stream) + def test(q, bus, conn, stream): # be notified when the signal CapabilitiesChanged is fired conn_caps_iface = dbus.Interface(conn, cs.CONN_IFACE_CAPS) @@ -305,5 +380,8 @@ def test(q, bus, conn, stream): 'user4@example.com/Res', 6L, 7L, 'http://telepathy.freedesktop.org/fake-client4', 1) + test_39464(q, bus, conn, stream) + test_no_var(q, bus, conn, stream) + if __name__ == '__main__': exec_test(test) -- 1.7.10.4