[Telepathy-commits] [telepathy-gabble/master] test-caps-hash.py: new test for XEP-0115
Alban Crequy
alban.crequy at collabora.co.uk
Tue Aug 19 10:52:31 PDT 2008
20080509121831-a41c0-6d3d9d04b40565e8f67a511b26c9f70c35f64f3f.gz
---
tests/twisted/Makefile.am | 1 +
tests/twisted/test-caps-hash.py | 201 +++++++++++++++++++++++++++++++++++++++
2 files changed, 202 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/test-caps-hash.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index f688add..fdd8b69 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -41,6 +41,7 @@ TWISTED_TESTS = \
jingle/test-outgoing-call-deprecated2.py \
jingle/test-outgoing-call-rejected.py \
test-capabilities.py \
+ test-caps-update.py \
test-connect-fail.py \
test-connect.py \
test-disco.py \
diff --git a/tests/twisted/test-caps-hash.py b/tests/twisted/test-caps-hash.py
new file mode 100644
index 0000000..9c300b6
--- /dev/null
+++ b/tests/twisted/test-caps-hash.py
@@ -0,0 +1,201 @@
+
+"""
+Test the verification string introduced in version 1.5 of XEP-0115
+
+This test changes the caps several times:
+- Initial presence to be online
+- Change presence to handle audio calls, using XEP-0115-v1.3. Check that
+ 'CapabilitiesChanged' *is* fired
+- Change presence *not* to handle audio calls, using XEP-0115-v1.5, but with a
+ *bogus* hash. Check that 'CapabilitiesChanged' is *not* fired
+- Change presence *not* to handle audio calls, using XEP-0115-v1.5, with a
+ *good* hash. Check that 'CapabilitiesChanged' *is* fired
+- Change presence to handle audio calls, using XEP-0115-v1.5. Check that
+ 'CapabilitiesChanged' is fired
+"""
+
+import dbus
+import sys
+
+from twisted.words.xish import domish, xpath
+
+from gabbletest import exec_test, make_result_iq
+
+text = 'org.freedesktop.Telepathy.Channel.Type.Text'
+sm = 'org.freedesktop.Telepathy.Channel.Type.StreamedMedia'
+caps_iface = 'org.freedesktop.Telepathy.Connection.Interface.Capabilities'
+
+caps_changed_flag = 0
+
+def caps_changed_cb(dummy):
+ # Workaround to bug 9980: do not raise an error but use a flag
+ # https://bugs.freedesktop.org/show_bug.cgi?id=9980
+ global caps_changed_flag
+ caps_changed_flag = 1
+
+def make_presence(from_jid, type, status):
+ presence = domish.Element((None, 'presence'))
+
+ if from_jid is not None:
+ presence['from'] = from_jid
+
+ if type is not None:
+ presence['type'] = type
+
+ if status is not None:
+ presence.addElement('status', content=status)
+
+ return presence
+
+def presence_add_caps(presence, ver, client, hash=None):
+ c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
+ c['node'] = client
+ c['ver'] = ver
+ if hash is not None:
+ c['hash'] = hash
+ return presence
+
+def _test(q, bus, conn, stream, contact, contact_handle, client):
+ global caps_changed_flag
+
+ presence = make_presence(contact, None, 'hello')
+ stream.send(presence)
+
+ event = q.expect('dbus-signal', signal='PresenceUpdate',
+ args=[{contact_handle: (0L, {u'available': {'message': 'hello'}})}])
+
+ # no special capabilities
+ basic_caps = [(contact_handle, text, 3, 0)]
+ assert conn.Capabilities.GetCapabilities([contact_handle]) == basic_caps
+
+ # send updated presence with Jingle caps info
+ presence = make_presence(contact, None, 'hello')
+ presence = presence_add_caps(presence, '0.1', client)
+ print str(presence)
+ stream.send(presence)
+
+ # Gabble looks up our capabilities
+ event = q.expect('stream-iq', to=contact,
+ query_ns='http://jabber.org/protocol/disco#info')
+ query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
+ assert query_node.attributes['node'] == \
+ client + '#' + '0.1'
+
+ # send good reply
+ result = make_result_iq(stream, event.stanza)
+ query = result.firstChildElement()
+ feature = query.addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/jingle'
+ feature = query.addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/jingle/description/audio'
+ feature = query.addElement('feature')
+ feature['var'] = 'http://www.google.com/transport/p2p'
+ stream.send(result)
+
+ # we can now do audio calls
+ event = q.expect('dbus-signal', signal='CapabilitiesChanged')
+ caps_changed_flag = 0
+
+ # send bogus presence
+ presence = make_presence(contact, None, 'hello')
+ c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
+ c['node'] = client
+ c['ver'] = 'KyuUmfhC34jP1sDjs489RjkJfsg=' # good hash
+ c['ver'] = 'X' + c['ver'] # now the hash is broken
+ c['hash'] = 'sha-1'
+ stream.send(presence)
+
+ # Gabble looks up our capabilities
+ event = q.expect('stream-iq', to=contact,
+ query_ns='http://jabber.org/protocol/disco#info')
+ query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
+ assert query_node.attributes['node'] == \
+ client + '#' + c['ver']
+
+ # send bogus reply
+ result = make_result_iq(stream, event.stanza)
+ query = result.firstChildElement()
+ feature = query.addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/bogus-feature'
+ stream.send(result)
+
+ # don't receive any D-Bus signal
+ assert caps_changed_flag == 0
+
+ # send presence with empty caps
+ presence = make_presence(contact, None, 'hello')
+ presence = presence_add_caps(presence, '0.0', client)
+ print str(presence)
+ stream.send(presence)
+
+ # Gabble looks up our capabilities
+ event = q.expect('stream-iq', to=contact,
+ query_ns='http://jabber.org/protocol/disco#info')
+ query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
+ assert query_node.attributes['node'] == \
+ client + '#' + '0.0'
+
+ # still don't receive any D-Bus signal
+ assert caps_changed_flag == 0
+
+ # send good reply
+ result = make_result_iq(stream, event.stanza)
+ query = result.firstChildElement()
+ stream.send(result)
+
+ # we can now do nothing
+ event = q.expect('dbus-signal', signal='CapabilitiesChanged')
+ assert caps_changed_flag == 1
+ caps_changed_flag = 0
+
+ # send correct presence
+ presence = make_presence(contact, None, 'hello')
+ c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
+ c['node'] = client
+ c['ver'] = 'JpaYgiKL0y4fUOCTwN3WLGpaftM=' # good hash
+ c['hash'] = 'sha-1'
+ stream.send(presence)
+
+ assert caps_changed_flag == 0
+
+ # Gabble looks up our capabilities
+ event = q.expect('stream-iq', to=contact,
+ query_ns='http://jabber.org/protocol/disco#info')
+ query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
+ assert query_node.attributes['node'] == \
+ client + '#' + c['ver']
+
+ # send good reply
+ result = make_result_iq(stream, event.stanza)
+ query = result.firstChildElement()
+ query['node'] = client + '#' + c['ver']
+ feature = query.addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/jingle'
+ feature = query.addElement('feature')
+ feature['var'] = 'http://jabber.org/protocol/jingle/description/audio'
+ feature = query.addElement('feature')
+ feature['var'] = 'http://www.google.com/transport/p2p'
+ stream.send(result)
+
+ # we can now do audio calls
+ assert caps_changed_flag == 0
+ event = q.expect('dbus-signal', signal='CapabilitiesChanged')
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ # be notified when the signal CapabilitiesChanged is fired
+ conn_caps_iface = dbus.Interface(conn, caps_iface)
+ conn_caps_iface.connect_to_signal('CapabilitiesChanged', caps_changed_cb)
+
+ _test(q, bus, conn, stream, 'bob at foo.com/Foo', 2L, 'http://telepathy.freedesktop.org/fake-client')
+ _test(q, bus, conn, stream, 'bob2 at foo.com/Foo', 3L, 'http://telepathy.freedesktop.org/fake-client2')
+
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+
+if __name__ == '__main__':
+ exec_test(test)
+
--
1.5.6.3
More information about the Telepathy-commits
mailing list