[Telepathy-commits] [telepathy-gabble/master] Split out testing offering tubes to incapable contact
Will Thompson
will.thompson at collabora.co.uk
Wed Feb 18 09:57:15 PST 2009
---
tests/twisted/Makefile.am | 1 +
.../offer-accept-private-dbus-stream-tube-ibb.py | 47 +--------
...offer-accept-private-dbus-stream-tube-socks5.py | 48 +--------
tests/twisted/tubes/offer-no-caps.py | 116 ++++++++++++++++++++
4 files changed, 123 insertions(+), 89 deletions(-)
create mode 100644 tests/twisted/tubes/offer-no-caps.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 74d5512..5a2d1f0 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -55,6 +55,7 @@ TWISTED_TESTS = \
tubes/offer-accept-private-stream-tube-si-fallback.py \
tubes/offer-muc-dbus-tube.py \
tubes/offer-muc-stream-tube-ibb.py \
+ tubes/offer-no-caps.py \
tubes/offer-private-dbus-tube-ibb.py \
tubes/request-invalid-dbus-tube.py \
tubes/ensure-si-tube.py \
diff --git a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
index 9b8f7ee..368e648 100644
--- a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
+++ b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
@@ -84,30 +84,8 @@ def test(q, bus, conn, stream):
item = roster_event.query.addElement('item')
item['jid'] = 'bob at localhost' # Bob can do tubes
item['subscription'] = 'both'
- item = roster_event.query.addElement('item')
- item['jid'] = 'joe at localhost' # Joe cannot do tubes
- item['subscription'] = 'both'
stream.send(roster)
- # Send Joe presence is without tube caps
- presence = domish.Element(('jabber:client', 'presence'))
- presence['from'] = 'joe at localhost/Joe'
- presence['to'] = 'test at localhost/Resource'
- c = presence.addElement('c')
- c['xmlns'] = 'http://jabber.org/protocol/caps'
- c['node'] = 'http://example.com/IDontSupportTubes'
- c['ver'] = '1.0'
- stream.send(presence)
-
- event = q.expect('stream-iq', iq_type='get',
- query_ns='http://jabber.org/protocol/disco#info',
- to='joe at localhost/Joe')
- result = event.stanza
- result['type'] = 'result'
- assert event.query['node'] == \
- 'http://example.com/IDontSupportTubes#1.0'
- stream.send(result)
-
# Send Bob presence and his tube caps
presence = domish.Element(('jabber:client', 'presence'))
presence['from'] = 'bob at localhost/Bob'
@@ -130,33 +108,12 @@ def test(q, bus, conn, stream):
stream.send(result)
# A tube request can be done only if the contact has tube capabilities
- # Ensure that Joe and Bob's caps have been received
+ # Ensure that Bob's caps have been received
sync_stream(q, stream)
# new requestotron
requestotron = dbus.Interface(conn, CONN_IFACE_REQUESTS)
- # Test tubes with Joe. Joe does not have tube capabilities.
- # Gabble does not allow to offer a tube to him.
- joe_handle = conn.RequestHandles(1, ['joe at localhost'])[0]
- call_async(q, conn, 'RequestChannel', CHANNEL_TYPE_TUBES, HT_CONTACT, joe_handle, True);
-
- ret, old_sig, new_sig = q.expect_many(
- EventPattern('dbus-return', method='RequestChannel'),
- EventPattern('dbus-signal', signal='NewChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
- joe_chan_path = ret.value[0]
-
- joe_tubes_chan = bus.get_object(conn.bus_name, joe_chan_path)
- joe_tubes_iface = dbus.Interface(joe_tubes_chan, CHANNEL_TYPE_TUBES)
- path = os.getcwd() + '/stream'
- call_async(q, joe_tubes_iface, 'OfferStreamTube',
- 'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
- event = q.expect('dbus-error', method='OfferStreamTube')
-
- joe_tubes_chan.Close()
-
# Test tubes with Bob. Bob does not have tube capabilities.
bob_handle = conn.RequestHandles(1, ['bob at localhost'])[0]
@@ -237,6 +194,8 @@ def test(q, bus, conn, stream):
bob_handle, "bob at localhost")
# Create another tube using old API
+ # FIXME: make set_up_echo return this
+ path = os.getcwd() + '/stream'
call_async(q, tubes_iface, 'OfferStreamTube',
'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
diff --git a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
index cd7c5f3..61c03a0 100644
--- a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
+++ b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
@@ -83,30 +83,8 @@ def test(q, bus, conn, stream):
item = roster_event.query.addElement('item')
item['jid'] = 'bob at localhost' # Bob can do tubes
item['subscription'] = 'both'
- item = roster_event.query.addElement('item')
- item['jid'] = 'joe at localhost' # Joe cannot do tubes
- item['subscription'] = 'both'
stream.send(roster)
- # Send Joe presence is without tube caps
- presence = domish.Element(('jabber:client', 'presence'))
- presence['from'] = 'joe at localhost/Joe'
- presence['to'] = 'test at localhost/Resource'
- c = presence.addElement('c')
- c['xmlns'] = 'http://jabber.org/protocol/caps'
- c['node'] = 'http://example.com/IDontSupportTubes'
- c['ver'] = '1.0'
- stream.send(presence)
-
- event = q.expect('stream-iq', iq_type='get',
- query_ns='http://jabber.org/protocol/disco#info',
- to='joe at localhost/Joe')
- result = event.stanza
- result['type'] = 'result'
- assert event.query['node'] == \
- 'http://example.com/IDontSupportTubes#1.0'
- stream.send(result)
-
# Send Bob presence and his tube caps
presence = domish.Element(('jabber:client', 'presence'))
presence['from'] = 'bob at localhost/Bob'
@@ -129,33 +107,11 @@ def test(q, bus, conn, stream):
stream.send(result)
# A tube request can be done only if the contact has tube capabilities
- # Ensure that Joe and Bob's caps have been received
+ # Ensure that Bob's caps have been received
sync_stream(q, stream)
requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
- # Test tubes with Joe. Joe does not have tube capabilities.
- # Gabble does not allow to offer a tube to him.
- joe_handle = conn.RequestHandles(1, ['joe at localhost'])[0]
- call_async(q, conn, 'RequestChannel', cs.CHANNEL_TYPE_TUBES,
- cs.HT_CONTACT, joe_handle, True);
-
- ret, old_sig, new_sig = q.expect_many(
- EventPattern('dbus-return', method='RequestChannel'),
- EventPattern('dbus-signal', signal='NewChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
- joe_chan_path = ret.value[0]
-
- joe_tubes_chan = bus.get_object(conn.bus_name, joe_chan_path)
- joe_tubes_iface = dbus.Interface(joe_tubes_chan, cs.CHANNEL_TYPE_TUBES)
- path = os.getcwd() + '/stream'
- call_async(q, joe_tubes_iface, 'OfferStreamTube',
- 'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
- event = q.expect('dbus-error', method='OfferStreamTube')
-
- joe_tubes_chan.Close()
-
# Test tubes with Bob. Bob does not have tube capabilities.
bob_handle = conn.RequestHandles(1, ['bob at localhost'])[0]
@@ -217,6 +173,8 @@ def test(q, bus, conn, stream):
bob_handle, "bob at localhost")
# Offer the tube, old API
+ # FIXME: make set_up_echo return this
+ path = os.getcwd() + '/stream'
call_async(q, tubes_iface, 'OfferStreamTube',
'echo', sample_parameters, 0, dbus.ByteArray(path), 0, "")
diff --git a/tests/twisted/tubes/offer-no-caps.py b/tests/twisted/tubes/offer-no-caps.py
new file mode 100644
index 0000000..862b67f
--- /dev/null
+++ b/tests/twisted/tubes/offer-no-caps.py
@@ -0,0 +1,116 @@
+"""
+Test that offering a tube to a contact without tube capabilities fails
+appropriately.
+"""
+
+import os
+import dbus
+
+from twisted.words.xish import domish
+
+from servicetest import EventPattern, make_channel_proxy, call_async
+from gabbletest import exec_test, acknowledge_iq, sync_stream
+
+import constants as cs
+import tubetestutil as t
+
+def props(ct, extra=None):
+ ret = { cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+ cs.TARGET_ID: 'joe at localhost',
+ cs.CHANNEL_TYPE: ct,
+ }
+ if extra is not None:
+ ret.update(extra)
+ return ret
+
+def test(q, bus, conn, stream):
+ t.set_up_echo("")
+
+ conn.Connect()
+
+ _, vcard_event, roster_event = q.expect_many(
+ EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
+ EventPattern('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard'),
+ EventPattern('stream-iq', query_ns='jabber:iq:roster'))
+
+ acknowledge_iq(stream, vcard_event.stanza)
+
+ # Send a roster with one member, Joe.
+ roster = roster_event.stanza
+ roster['type'] = 'result'
+ item = roster_event.query.addElement('item')
+ item['jid'] = 'joe at localhost'
+ item['subscription'] = 'both'
+ stream.send(roster)
+
+ # Send Joe's presence.
+ presence = domish.Element(('jabber:client', 'presence'))
+ presence['from'] = 'joe at localhost/Joe'
+ presence['to'] = 'test at localhost/Resource'
+ c = presence.addElement('c')
+ c['xmlns'] = 'http://jabber.org/protocol/caps'
+ c['node'] = 'http://example.com/IDontSupportTubes'
+ c['ver'] = '1.0'
+ stream.send(presence)
+
+ # Gabble discoes Joe, because it doesn't know his client's caps
+ event = q.expect('stream-iq', iq_type='get',
+ query_ns='http://jabber.org/protocol/disco#info',
+ to='joe at localhost/Joe')
+ assert event.query['node'] == 'http://example.com/IDontSupportTubes#1.0'
+
+ # Send a "Joe doesn't have any caps" response.
+ result = event.stanza
+ result['type'] = 'result'
+ stream.send(result)
+
+ # Ensure Joe's caps have been received.
+ # FIXME: we shouldn't need to do this, the tubes code should wait for the
+ # caps to appear, just like the StreamedMedia channel does.
+ sync_stream(q, stream)
+
+ requests = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
+
+ # First, we make an old-style Tubes channel, which should work; calling
+ # OfferStreamTube or OfferDBusTube on it, however, should fail with
+ # NotAvailable
+ path, _ = requests.CreateChannel(props(cs.CHANNEL_TYPE_TUBES))
+ tubes = make_channel_proxy(conn, path, 'Channel.Type.Tubes')
+
+ call_async(q, tubes, 'OfferDBusTube', 'com.example.monkeys', {})
+ e = q.expect('dbus-error', method='OfferDBusTube').error
+ assert e.get_dbus_name() == cs.NOT_AVAILABLE, e.get_dbus_name()
+
+ # FIXME: make set_up_echo return this
+ path = os.getcwd() + '/stream'
+ call_async(q, tubes, 'OfferStreamTube', 'echo', {},
+ cs.SOCKET_ADDRESS_TYPE_UNIX, dbus.ByteArray(path),
+ cs.SOCKET_ACCESS_CONTROL_LOCALHOST, "")
+ e = q.expect('dbus-error', method='OfferStreamTube').error
+ assert e.get_dbus_name() == cs.NOT_AVAILABLE, e.get_dbus_name()
+
+ # Now we try making new-style DBusTube and StreamTube channels, and calling
+ # the relevant Offer method on them; this should fail with NotAvailable.
+ # FIXME: I think this should be NotCapable
+ st_path, _ = requests.CreateChannel(props(cs.CHANNEL_TYPE_STREAM_TUBE,
+ {cs.STREAM_TUBE_SERVICE: "newecho"}))
+ st_chan = bus.get_object(conn.bus_name, st_path)
+ st = dbus.Interface(st_chan, cs.CHANNEL_TYPE_STREAM_TUBE)
+ call_async(q, st, 'OfferStreamTube', cs.SOCKET_ADDRESS_TYPE_UNIX,
+ dbus.ByteArray(path), cs.SOCKET_ACCESS_CONTROL_LOCALHOST, "", {})
+ e = q.expect('dbus-error', method='OfferStreamTube').error
+ assert e.get_dbus_name() == cs.NOT_AVAILABLE, e.get_dbus_name()
+
+ dt_path, _ = requests.CreateChannel(props(cs.CHANNEL_TYPE_DBUS_TUBE,
+ { cs.DBUS_TUBE_SERVICE_NAME: "com.newecho" }))
+ dt_chan = bus.get_object(conn.bus_name, dt_path)
+ dt = dbus.Interface(dt_chan, cs.CHANNEL_TYPE_DBUS_TUBE)
+ call_async(q, dt, 'OfferDBusTube', {})
+ e = q.expect('dbus-error', method='OfferDBusTube').error
+ assert e.get_dbus_name() == cs.NOT_AVAILABLE, e.get_dbus_name()
+
+ conn.Disconnect()
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list