[telepathy-gabble/master] tests: Support data forms in compute_caps_hash

Will Thompson will.thompson at collabora.co.uk
Mon Jun 15 10:30:18 PDT 2009


---
 tests/twisted/caps_helper.py                       |   29 +++++++++++++++-----
 .../file-transfer/test-caps-file-transfer.py       |    4 +-
 tests/twisted/test-caps-tubes.py                   |    2 +-
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/tests/twisted/caps_helper.py b/tests/twisted/caps_helper.py
index a1505e5..b1fdcc5 100644
--- a/tests/twisted/caps_helper.py
+++ b/tests/twisted/caps_helper.py
@@ -46,18 +46,33 @@ ft_allowed_properties = dbus.Array([
     cs.CHANNEL_TYPE_FILE_TRANSFER + '.Date'])
 
 def compute_caps_hash(identities, features, dataforms):
-    S = ''
+    """
+    Accepts a list of slash-separated identities, a list of feature namespaces,
+    and a map from FORM_TYPE to (map from field name to values), returns the
+    verification string as defined by
+    <http://xmpp.org/extensions/xep-0115.html#ver>.
+    """
+    components = []
 
     for identity in sorted(identities):
-        S += '%s<' % identity
+        components.append(identity)
 
     for feature in sorted(features):
-        S += '%s<' % feature
+        components.append(feature)
 
-    # FIXME: support dataforms
+    for form_type in sorted(dataforms.keys()):
+        components.append(form_type)
+
+        for var in sorted(dataforms[form_type].keys()):
+            components.append(var)
+
+            for value in sorted(dataforms[form_type][var]):
+                components.append(value)
+
+    components.append('')
 
     m = hashlib.sha1()
-    m.update(S)
+    m.update('<'.join(components))
     return base64.b64encode(m.digest())
 
 def make_caps_disco_reply(stream, req, features):
@@ -109,7 +124,7 @@ def receive_presence_and_ask_caps(q, stream):
         features.append(feature['var'])
 
     # Check if the hash matches the announced capabilities
-    assert ver == compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], features, [])
+    assert ver == compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], features, {})
 
     return (event, caps_str, signaled_caps)
 
@@ -132,4 +147,4 @@ if __name__ == '__main__':
         ["http://jabber.org/protocol/disco#info",
         "http://jabber.org/protocol/disco#items",
         "http://jabber.org/protocol/muc", "http://jabber.org/protocol/caps"],
-        []) == 'QgayPKawpkPSDYmwT/WM94uAlu0='
+        {}) == 'QgayPKawpkPSDYmwT/WM94uAlu0='
diff --git a/tests/twisted/file-transfer/test-caps-file-transfer.py b/tests/twisted/file-transfer/test-caps-file-transfer.py
index 76e2131..9c7fad3 100644
--- a/tests/twisted/file-transfer/test-caps-file-transfer.py
+++ b/tests/twisted/file-transfer/test-caps-file-transfer.py
@@ -22,7 +22,7 @@ def test_ft_caps_from_contact(q, bus, conn, stream, contact, contact_handle, cli
     presence = make_presence(contact, status='hello')
     c = presence.addElement((ns.CAPS, 'c'))
     c['node'] = client
-    c['ver'] = compute_caps_hash([], [], [])
+    c['ver'] = compute_caps_hash([], [], {})
     c['hash'] = 'sha-1'
     stream.send(presence)
 
@@ -60,7 +60,7 @@ def test_ft_caps_from_contact(q, bus, conn, stream, contact, contact_handle, cli
     presence = make_presence(contact, status='hello')
     c = presence.addElement((ns.CAPS, 'c'))
     c['node'] = client
-    c['ver'] = compute_caps_hash([], [ns.FILE_TRANSFER], [])
+    c['ver'] = compute_caps_hash([], [ns.FILE_TRANSFER], {})
     c['hash'] = 'sha-1'
     stream.send(presence)
 
diff --git a/tests/twisted/test-caps-tubes.py b/tests/twisted/test-caps-tubes.py
index 27ecedb..35f310b 100644
--- a/tests/twisted/test-caps-tubes.py
+++ b/tests/twisted/test-caps-tubes.py
@@ -80,7 +80,7 @@ def receive_caps(q, conn, stream, contact, contact_handle, features,
     c['node'] = client
     c['ver'] = compute_caps_hash([],
         features if features is not None else [],
-        [])
+        {})
     c['hash'] = 'sha-1'
     stream.send(presence)
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list