summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2013-09-20 11:50:06 -0400
committerXavier Claessens <xavier.claessens@collabora.co.uk>2013-09-24 14:45:10 -0400
commit508f6f0d5031e146c3e369e53d76fa57b3af8a4b (patch)
treecccd34d4613e450816abc6a810b6f8ca071eff9b
parent28955b889390c8f8364022a81e6fb93c5e8dfe97 (diff)
downloadtelepathy-salut-508f6f0d5031e146c3e369e53d76fa57b3af8a4b.tar.gz
Drop 1-1 Tubes unit tests
These tubes are disabled until we get a better network protocol for them, and their tests have been disabled since 2009.
-rw-r--r--tests/twisted/Makefile.am7
-rw-r--r--tests/twisted/avahi/caps-tubes.py791
-rw-r--r--tests/twisted/avahi/tubes/disabled-1-1-tubes.py62
-rw-r--r--tests/twisted/avahi/tubes/offer-private-stream-tube.py360
-rw-r--r--tests/twisted/avahi/tubes/request-invalid-dbus-tube.py62
-rw-r--r--tests/twisted/avahi/tubes/tube-close.py71
-rw-r--r--tests/twisted/avahi/tubes/tubes-to-nonexistant-ids.py54
-rw-r--r--tests/twisted/avahi/tubes/two-private-stream-tubes.py329
8 files changed, 0 insertions, 1736 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index c5651291..a83c1432 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -14,7 +14,6 @@ TWISTED_AVAHI_TESTS = \
avahi/caps-file-transfer.py \
avahi/close-local-pending-room.py \
avahi/only-text-muc-when-needed.py \
- avahi/tubes/disabled-1-1-tubes.py \
avahi/file-transfer/send-file-and-cancel-immediately.py \
avahi/file-transfer/send-file-and-disconnect.py \
avahi/file-transfer/send-file-declined.py \
@@ -38,7 +37,6 @@ TWISTED_AVAHI_TESTS = \
avahi/file-transfer/metadata.py \
avahi/file-transfer/ft-client-caps.py \
avahi/caps-self.py \
- avahi/caps-tubes.py \
avahi/text-channel.py \
avahi/ichat-composing.py \
avahi/ichat-incoming-msg.py \
@@ -46,16 +44,11 @@ TWISTED_AVAHI_TESTS = \
avahi/file-transfer/ichat-receive-file.py \
avahi/file-transfer/ichat-send-file.py \
avahi/file-transfer/ichat-send-file-declined.py \
- avahi/tubes/request-invalid-dbus-tube.py \
avahi/request-muc.py \
avahi/tubes/request-muc-tubes.py \
avahi/roomlist.py \
avahi/set-presence.py \
- avahi/tubes/offer-private-stream-tube.py \
avahi/tubes/two-muc-stream-tubes.py \
- avahi/tubes/two-private-stream-tubes.py \
- avahi/tubes/tube-close.py \
- avahi/tubes/tubes-to-nonexistant-ids.py \
avahi/tubes/two-muc-dbus-tubes.py
TWISTED_AVAHI_OLPC_TESTS = \
diff --git a/tests/twisted/avahi/caps-tubes.py b/tests/twisted/avahi/caps-tubes.py
deleted file mode 100644
index dde30457..00000000
--- a/tests/twisted/avahi/caps-tubes.py
+++ /dev/null
@@ -1,791 +0,0 @@
-
-"""
-Test tubes capabilities with Connection.Interface.ContactCapabilities.DRAFT
-
-1. Receive presence and caps from contacts and check that
-GetContactCapabilities works correctly and that ContactCapabilitiesChanged is
-correctly received. Also check that GetContactAttributes gives the same
-results.
-
-- no tube cap at all
-- 1 stream tube cap
-- 1 D-Bus tube cap
-- 1 stream tube + 1 D-Bus tube caps
-- 2 stream tube + 2 D-Bus tube caps
-- 1 stream tube + 1 D-Bus tube caps, again, to test whether the caps cache
- works with tubes
-
-2. Test UpdateCapabilities and test that the avahi txt record is updated test
-that the D-Bus signal ContactCapabilitiesChanged is fired for the self handle,
-ask Salut for its caps with an iq request, check the reply is correct, and ask
-Salut for its caps using D-Bus method GetContactCapabilities. Also check that
-GetContactAttributes gives the same results.
-
-- no tube cap at all
-- 1 stream tube cap
-- 1 D-Bus tube cap
-- 1 stream tube + 1 D-Bus tube caps
-- 2 stream tube + 2 D-Bus tube caps
-- 1 stream tube + 1 D-Bus tube caps, again, just for the fun
-
-"""
-
-import dbus
-import sys
-
-from avahitest import AvahiAnnouncer, AvahiListener
-from avahitest import get_host_name
-from avahitest import txt_get_key
-import avahi
-
-from twisted.words.xish import domish, xpath
-
-from servicetest import EventPattern
-from saluttest import exec_test, make_result_iq, sync_stream, fixed_features
-from xmppstream import setup_stream_listener, connect_to_stream
-import ns
-from constants import *
-
-from caps_helper import compute_caps_hash, check_caps
-from config import PACKAGE_STRING
-
-print "FIXME: disabled because 1-1 tubes are disabled for now"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-text_fixed_properties = dbus.Dictionary({
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': 1L,
- 'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.Text'
- })
-text_allowed_properties = dbus.Array([
- 'org.freedesktop.Telepathy.Channel.TargetHandle',
- ])
-
-ft_fixed_properties = dbus.Dictionary({
- CHANNEL_TYPE: CHANNEL_TYPE_FILE_TRANSFER,
- TARGET_HANDLE_TYPE: HT_CONTACT
- })
-ft_allowed_properties = dbus.Array([
- FT_CONTENT_HASH_TYPE, TARGET_HANDLE, TARGET_ID, FT_CONTENT_TYPE, FT_FILENAME,
- FT_SIZE, FT_CONTENT_HASH, FT_DESCRIPTION,
- FT_DATE, FT_INITIAL_OFFSET, FT_URI
- ])
-
-stream_tube_fixed_properties = dbus.Dictionary({
- TARGET_HANDLE_TYPE: HT_CONTACT,
- CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE
- })
-stream_tube_allowed_properties = dbus.Array([TARGET_HANDLE,
- TARGET_ID, STREAM_TUBE_SERVICE])
-
-dbus_tube_fixed_properties = dbus.Dictionary({
- TARGET_HANDLE_TYPE: HT_CONTACT,
- CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE
- })
-dbus_tube_allowed_properties = dbus.Array([TARGET_HANDLE,
- TARGET_ID, DBUS_TUBE_SERVICE_NAME])
-
-daap_fixed_properties = dbus.Dictionary({
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': 1L,
- 'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube.Service':
- 'daap'
- })
-daap_allowed_properties = dbus.Array([
- 'org.freedesktop.Telepathy.Channel.TargetHandle',
- ])
-
-http_fixed_properties = dbus.Dictionary({
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': 1L,
- 'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube.Service':
- 'http'
- })
-http_allowed_properties = dbus.Array([
- 'org.freedesktop.Telepathy.Channel.TargetHandle',
- ])
-
-xiangqi_fixed_properties = dbus.Dictionary({
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': 1L,
- 'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.DBusTube',
- 'org.freedesktop.Telepathy.Channel.Type.DBusTube.ServiceName':
- 'com.example.Xiangqi'
- })
-xiangqi_allowed_properties = dbus.Array([
- 'org.freedesktop.Telepathy.Channel.TargetHandle',
- ])
-
-go_fixed_properties = dbus.Dictionary({
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': 1L,
- 'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.DBusTube',
- 'org.freedesktop.Telepathy.Channel.Type.DBusTube.ServiceName':
- 'com.example.Go'
- })
-go_allowed_properties = dbus.Array([
- 'org.freedesktop.Telepathy.Channel.TargetHandle',
- ])
-
-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
-
-# last value of the "ver" key we resolved. We use it to be sure that the
-# modified caps has already be announced.
-old_ver = ''
-
-def receive_presence_and_ask_caps(q, stream, service):
- global old_ver
-
- event_avahi, event_dbus = q.expect_many(
- EventPattern('service-resolved', service=service),
- EventPattern('dbus-signal', signal='ContactCapabilitiesChanged')
- )
- signaled_caps = event_dbus.args[0][1]
-
- ver = txt_get_key(event_avahi.txt, "ver")
- while ver == old_ver:
- # be sure that the announced caps actually changes
- event_avahi = q.expect('service-resolved', service=service)
- ver = txt_get_key(event_avahi.txt, "ver")
- old_ver = ver
-
- hash = txt_get_key(event_avahi.txt, "hash")
- node = txt_get_key(event_avahi.txt, "node")
- assert hash == 'sha-1'
-
- # ask caps
- request = """
-<iq from='fake_contact@jabber.org/resource'
- id='disco1'
- to='salut@jabber.org/resource'
- type='get'>
- <query xmlns='http://jabber.org/protocol/disco#info'
- node='""" + node + '#' + ver + """'/>
-</iq>
-"""
- stream.send(request)
-
- # receive caps
- event = q.expect('stream-iq',
- query_ns='http://jabber.org/protocol/disco#info')
- caps_str = str(xpath.queryForNodes('/iq/query/feature', event.stanza))
-
- features = []
- for feature in xpath.queryForNodes('/iq/query/feature', event.stanza):
- features.append(feature['var'])
-
- # Check if the hash matches the announced capabilities
- assert ver == compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], features, {})
-
- return (event, caps_str, signaled_caps)
-
-def caps_contain(event, cap):
- node = xpath.queryForNodes('/iq/query/feature[@var="%s"]'
- % cap,
- event.stanza)
- if node is None:
- return False
- if len(node) != 1:
- return False
- var = node[0].attributes['var']
- if var is None:
- return False
- return var == cap
-
-def test_tube_caps_from_contact(q, bus, conn, service,
- client):
-
- conn_caps_iface = dbus.Interface(conn, CONN_IFACE_CONTACT_CAPS)
- conn_contacts_iface = dbus.Interface(conn, CONN_IFACE_CONTACTS)
-
- # send presence with no tube cap
- ver = compute_caps_hash([], [], {})
- txt_record = { "txtvers": "1", "status": "avail",
- "node": client, "ver": ver, "hash": "sha-1"}
- contact_name = "test-caps-tube@" + get_host_name()
- listener, port = setup_stream_listener(q, contact_name)
- announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port,
- txt_record)
-
- # this is the first presence, Salut connects to the contact
- e = q.expect('incoming-connection', listener = listener)
- incoming = e.connection
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming, iq_type='set',
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + ver, (query_node.attributes['node'], client, ver)
-
- contact_handle = conn.RequestHandles(HT_CONTACT, [contact_name])[0]
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + 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'
- incoming.send(result)
-
- # no change in ContactCapabilities, so no signal ContactCapabilitiesChanged
- sync_stream(q, incoming)
-
- # no special capabilities
- basic_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == basic_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == basic_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
- # send presence with generic tube capability
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES], {})
- announcer.update(txt_record)
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming,
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + txt_record['ver']
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + txt_record['ver']
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES
- incoming.send(result)
-
- # generic tubes capabilities
- generic_tubes_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties)]})
- # FIXME: add D-Bus tube once implemented
- # (dbus_tube_fixed_properties, dbus_tube_allowed_properties)]})
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- assert len(event.args) == 1
- assert event.args[0] == generic_tubes_caps, generic_tubes_caps
-
- # send presence with 1 stream tube cap
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES + '/stream#daap'], {})
- announcer.update(txt_record)
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming, iq_type='set',
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + txt_record['ver']
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + txt_record['ver']
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/stream#daap'
- incoming.send(result)
-
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- signaled_caps = event.args[0][contact_handle]
- assert len(signaled_caps) == 3, signaled_caps # basic caps + daap
- assert (daap_fixed_properties, daap_allowed_properties) in signaled_caps
-
- # daap capabilities
- daap_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
- # send presence with 1 D-Bus tube cap
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi'], {})
- announcer.update(txt_record)
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming, iq_type='set',
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + txt_record['ver']
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + txt_record['ver']
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/dbus#com.example.Xiangqi'
- incoming.send(result)
-
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- signaled_caps = event.args[0][contact_handle]
- assert len(signaled_caps) == 3, signaled_caps # basic caps + Xiangqi
- assert (xiangqi_fixed_properties, xiangqi_allowed_properties) in signaled_caps
-
- # xiangqi capabilities
- xiangqi_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == xiangqi_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
- # send presence with both D-Bus and stream tube caps
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
- ns.TUBES + '/stream#daap'], {})
- announcer.update(txt_record)
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming, iq_type='set',
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + txt_record['ver']
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + txt_record['ver']
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/dbus#com.example.Xiangqi'
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/stream#daap'
- incoming.send(result)
-
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- signaled_caps = event.args[0][contact_handle]
- assert len(signaled_caps) == 4, signaled_caps # basic caps + daap+xiangqi
- assert (daap_fixed_properties, daap_allowed_properties) in signaled_caps
- assert (xiangqi_fixed_properties, xiangqi_allowed_properties) in signaled_caps
-
- # daap + xiangqi capabilities
- daap_xiangqi_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_xiangqi_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
- # send presence with 4 tube caps
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
- ns.TUBES + '/dbus#com.example.Go', ns.TUBES + '/stream#daap', ns.TUBES + '/stream#http'], {})
- announcer.update(txt_record)
-
- # Salut looks up our capabilities
- event = q.expect('stream-iq', connection = incoming, iq_type='set',
- query_ns='http://jabber.org/protocol/disco#info')
- query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
- assert query_node.attributes['node'] == \
- client + '#' + txt_record['ver']
-
- # send good reply
- result = make_result_iq(event.stanza)
- query = result.firstChildElement()
- query['node'] = client + '#' + txt_record['ver']
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/dbus#com.example.Xiangqi'
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/dbus#com.example.Go'
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/stream#daap'
- feature = query.addElement('feature')
- feature['var'] = ns.TUBES + '/stream#http'
- incoming.send(result)
-
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- signaled_caps = event.args[0][contact_handle]
- assert len(signaled_caps) == 6, signaled_caps # basic caps + 4 tubes
- assert (daap_fixed_properties, daap_allowed_properties) in signaled_caps
- assert (http_fixed_properties, http_allowed_properties) in signaled_caps
- assert (xiangqi_fixed_properties, xiangqi_allowed_properties) in signaled_caps
- assert (go_fixed_properties, go_allowed_properties) in signaled_caps
-
- # http + daap + xiangqi + go capabilities
- all_tubes_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties),
- (http_fixed_properties, http_allowed_properties),
- (xiangqi_fixed_properties,
- xiangqi_allowed_properties),
- (go_fixed_properties, go_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == all_tubes_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == all_tubes_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
- # send presence with both D-Bus and stream tube caps
- txt_record['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
- ns.TUBES + '/stream#daap'], {})
- announcer.update(txt_record)
-
- # Salut does not look up our capabilities because of the cache
-
- event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
- signaled_caps = event.args[0][contact_handle]
- assert len(signaled_caps) == 4, signaled_caps # basic caps + daap+xiangqi
- assert (daap_fixed_properties, daap_allowed_properties) in signaled_caps
- assert (xiangqi_fixed_properties, xiangqi_allowed_properties) in signaled_caps
-
- # daap + xiangqi capabilities
- daap_xiangqi_caps = dbus.Dictionary({contact_handle:
- [(text_fixed_properties, text_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties)]})
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_xiangqi_caps, caps
- # test again, to check GetContactCapabilities does not have side effect
- caps = conn_caps_iface.GetContactCapabilities([contact_handle])
- assert caps == daap_xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [contact_handle], [CONN_IFACE_CONTACT_CAPS], False) \
- [contact_handle][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[contact_handle], \
- caps_via_contacts_iface
-
-def test_tube_caps_to_contact(q, bus, conn, service):
- basic_caps = dbus.Dictionary({1:
- [(text_fixed_properties, text_allowed_properties),
- (ft_fixed_properties, ft_allowed_properties)]})
- daap_caps = dbus.Dictionary({1:
- [(text_fixed_properties, text_allowed_properties),
- (ft_fixed_properties, ft_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties)]})
- xiangqi_caps = dbus.Dictionary({1:
- [(text_fixed_properties, text_allowed_properties),
- (ft_fixed_properties, ft_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties)]})
- daap_xiangqi_caps = dbus.Dictionary({1:
- [(text_fixed_properties, text_allowed_properties),
- (ft_fixed_properties, ft_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties)]})
- all_tubes_caps = dbus.Dictionary({1:
- [(text_fixed_properties, text_allowed_properties),
- (ft_fixed_properties, ft_allowed_properties),
- (stream_tube_fixed_properties, stream_tube_allowed_properties),
- (daap_fixed_properties, daap_allowed_properties),
- (http_fixed_properties, http_allowed_properties),
- (xiangqi_fixed_properties, xiangqi_allowed_properties),
- (go_fixed_properties, go_allowed_properties)]})
-
- # send presence with no cap info
- txt_record = { "txtvers": "1", "status": "avail"}
- contact_name = "test-caps-tube2@" + get_host_name()
- listener, port = setup_stream_listener(q, contact_name)
- announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port,
- txt_record)
-
- # Before opening a connection to Salut, wait Salut receives our presence
- # via Avahi. Otherwise, Salut will not allow our connection. We may
- # consider it is a bug in Salut, and we may want Salut to wait a few
- # seconds in case Avahi was slow.
- # See incoming_pending_connection_got_from(): if the SalutContact is not
- # found in the table, we close the connection.
- q.expect('dbus-signal', signal='PresencesChanged')
-
- # initialise a connection (Salut does not do it because there is no caps
- # here)
- self_handle = conn.GetSelfHandle()
- self_handle_name = conn.InspectHandles(HT_CONTACT, [self_handle])[0]
- service.resolve()
- e = q.expect('service-resolved', service = service)
- outbound = connect_to_stream(q, contact_name,
- self_handle_name, str(e.pt), e.port)
- e = q.expect('connection-result')
- assert e.succeeded, e.reason
- e = q.expect('stream-opened', connection = outbound)
-
- conn_caps_iface = dbus.Interface(conn, CONN_IFACE_CONTACT_CAPS)
- conn_contacts_iface = dbus.Interface(conn, CONN_IFACE_CONTACTS)
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == basic_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- # Advertise nothing
- conn_caps_iface.UpdateCapabilities([])
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == basic_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- sync_stream(q, outbound)
-
- # Advertise daap
- ret_caps = conn_caps_iface.UpdateCapabilities(
- [('bigclient', [daap_fixed_properties], [])])
-
- # Expect Salut to reply with the correct caps
- event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, outbound,
- service)
- assert caps_contain(event, ns.TUBES) == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#daap') == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#http') == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Go') \
- == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Xiangqi') \
- == False, caps_str
- assert len(signaled_caps) == 4, signaled_caps # basic caps + daap
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- STREAM_TUBE_SERVICE: 'daap'}, [TARGET_HANDLE]) in signaled_caps
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == daap_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- # Advertise xiangqi
- ret_caps = conn_caps_iface.SetSelfCapabilities(
- [('bigclient', [xiangqi_fixed_properties], [])])
-
- # Expect Salut to reply with the correct caps
- event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, outbound,
- service)
- assert caps_contain(event, ns.TUBES) == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#daap') == False, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#http') == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Go') \
- == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Xiangqi') \
- == True, caps_str
- assert len(signaled_caps) == 4, signaled_caps # basic caps + daap
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- DBUS_TUBE_SERVICE_NAME: 'com.example.Xiangqi'}, [TARGET_HANDLE]) in signaled_caps
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- # Advertise daap + xiangqi
- ret_caps = conn_caps_iface.SetSelfCapabilities(
- [('bigclient', [daap_fixed_properties + xiangqi_fixed_properties], [])])
-
- # Expect Salut to reply with the correct caps
- event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, outbound,
- service)
- assert caps_contain(event, ns.TUBES) == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#daap') == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#http') == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Go') \
- == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Xiangqi') \
- == True, caps_str
- assert len(signaled_caps) == 5, signaled_caps # basic caps + daap+xiangqi
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- STREAM_TUBE_SERVICE: 'daap'}, [TARGET_HANDLE]) in signaled_caps
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- DBUS_TUBE_SERVICE_NAME: 'com.example.Xiangqi'}, [TARGET_HANDLE]) in signaled_caps
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == daap_xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- # Advertise 4 tubes
- ret_caps = conn_caps_iface.SetSelfCapabilities(
- [('bigclient', [daap_fixed_properties, http_fixed_properties,
- go_fixed_properties, xiangqi_fixed_properties], [])])
-
- # Expect Salut to reply with the correct caps
- event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, outbound,
- service)
- assert caps_contain(event, ns.TUBES) == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#daap') == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#http') == True, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Go') \
- == True, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Xiangqi') \
- == True, caps_str
- assert len(signaled_caps) == 7, signaled_caps # basic caps + 4 tubes
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- STREAM_TUBE_SERVICE: 'daap'}, [TARGET_HANDLE]) in signaled_caps
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- DBUS_TUBE_SERVICE_NAME: 'com.example.Xiangqi'}, [TARGET_HANDLE]) in signaled_caps
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- STREAM_TUBE_SERVICE: 'http'}, [TARGET_HANDLE]) in signaled_caps
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- DBUS_TUBE_SERVICE_NAME: 'com.example.Go'}, [TARGET_HANDLE]) in signaled_caps
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == all_tubes_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
- # Advertise daap + xiangqi
- ret_caps = conn_caps_iface.SetSelfCapabilities(
- [('bigclient', [daap_fixed_properties + xiangqi_fixed_properties], [])])
-
- # Expect Salut to reply with the correct caps
- event, caps_str, signaled_caps = receive_presence_and_ask_caps(q, outbound,
-service)
- assert caps_contain(event, ns.TUBES) == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#daap') == True, caps_str
- assert caps_contain(event, ns.TUBES + '/stream#http') == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Go') \
- == False, caps_str
- assert caps_contain(event, ns.TUBES + '/dbus#com.example.Xiangqi') \
- == True, caps_str
- assert len(signaled_caps) == 5, signaled_caps # basic caps + daap+xiangqi
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- STREAM_TUBE_SERVICE: 'daap'}, [TARGET_HANDLE]) in signaled_caps
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_DBUS_TUBE, TARGET_HANDLE_TYPE: HT_CONTACT,
- DBUS_TUBE_SERVICE_NAME: 'com.example.Xiangqi'}, [TARGET_HANDLE]) in signaled_caps
-
- # Check our own caps
- caps = conn_caps_iface.GetContactCapabilities([1])
- assert caps == daap_xiangqi_caps, caps
- # check the Contacts interface give the same caps
- caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
- [1], [CONN_IFACE_CONTACT_CAPS], False) \
- [1][CONN_IFACE_CONTACT_CAPS + '/caps']
- assert caps_via_contacts_iface == caps[1], caps_via_contacts_iface
-
-
-def test(q, bus, conn):
- # last value of the "ver" key we resolved. We use it to be sure that the
- # modified caps has already be announced.
- old_ver = None
-
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0, 0])
-
- self_handle = conn.GetSelfHandle()
- self_handle_name = conn.InspectHandles(1, [self_handle])[0]
-
- AvahiListener(q).listen_for_service("_presence._tcp")
- e = q.expect('service-added', name = self_handle_name,
- protocol = avahi.PROTO_INET)
- service = e.service
- service.resolve()
-
- e = q.expect('service-resolved', service = service)
- ver = txt_get_key(e.txt, "ver")
- while ver == old_ver:
- # be sure that the announced caps actually changes
- e = q.expect('service-resolved', service=service)
- ver = txt_get_key(e.txt, "ver")
- old_ver = ver
-
- caps = compute_caps_hash(['client/pc//%s' % PACKAGE_STRING],
- fixed_features, {})
- check_caps(e.txt, caps)
-
- client = 'http://telepathy.freedesktop.org/fake-client'
-
- test_tube_caps_from_contact(q, bus, conn, service,
- client)
-
- test_tube_caps_to_contact(q, bus, conn, service)
-
- conn.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-
-if __name__ == '__main__':
- exec_test(test)
-
diff --git a/tests/twisted/avahi/tubes/disabled-1-1-tubes.py b/tests/twisted/avahi/tubes/disabled-1-1-tubes.py
deleted file mode 100644
index a30acd56..00000000
--- a/tests/twisted/avahi/tubes/disabled-1-1-tubes.py
+++ /dev/null
@@ -1,62 +0,0 @@
-"""
-Test if 1-1 tubes support is properly disabled.
-This test should be removed as soon as we re-enable 1-1 tubes support.
-"""
-from saluttest import exec_test, wait_for_contact_in_publish
-from avahitest import AvahiAnnouncer, AvahiListener
-from avahitest import get_host_name
-import avahi
-import dbus
-import os
-import errno
-import string
-
-from xmppstream import setup_stream_listener, connect_to_stream
-from servicetest import make_channel_proxy, Event
-
-from twisted.words.xish import xpath, domish
-from twisted.internet.protocol import Factory, Protocol, ClientCreator
-from twisted.internet import reactor
-
-import constants as cs
-
-PUBLISHED_NAME="test-tube"
-
-CHANNEL_TYPE_TUBES = "org.freedesktop.Telepathy.Channel.Type.Tubes"
-HT_CONTACT = 1
-HT_CONTACT_LIST = 3
-TEXT_MESSAGE_TYPE_NORMAL = dbus.UInt32(0)
-SOCKET_ADDRESS_TYPE_UNIX = dbus.UInt32(0)
-SOCKET_ADDRESS_TYPE_IPV4 = dbus.UInt32(2)
-SOCKET_ACCESS_CONTROL_LOCALHOST = dbus.UInt32(0)
-
-sample_parameters = dbus.Dictionary({
- 's': 'hello',
- 'ay': dbus.ByteArray('hello'),
- 'u': dbus.UInt32(123),
- 'i': dbus.Int32(-123),
- }, signature='sv')
-
-def test(q, bus, conn):
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
- basic_txt = { "txtvers": "1", "status": "avail" }
-
- contact_name = PUBLISHED_NAME + get_host_name()
- listener, port = setup_stream_listener(q, contact_name)
-
- announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)
-
- handle = wait_for_contact_in_publish(q, bus, conn, contact_name)
-
- # we can't request 1-1 tubes channel
- try:
- conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT, handle,
- True)
- except dbus.DBusException, e:
- assert e.get_dbus_name() == cs.NOT_IMPLEMENTED
- else:
- assert False, "Should raise NotImplemented error"
-
-if __name__ == '__main__':
- exec_test(test)
diff --git a/tests/twisted/avahi/tubes/offer-private-stream-tube.py b/tests/twisted/avahi/tubes/offer-private-stream-tube.py
deleted file mode 100644
index 68fcb2cb..00000000
--- a/tests/twisted/avahi/tubes/offer-private-stream-tube.py
+++ /dev/null
@@ -1,360 +0,0 @@
-from saluttest import exec_test, wait_for_contact_in_publish
-from avahitest import AvahiAnnouncer, AvahiListener
-from avahitest import get_host_name
-import avahi
-import dbus
-import os
-import errno
-import string
-
-from xmppstream import setup_stream_listener, connect_to_stream
-from servicetest import make_channel_proxy, Event, EventPattern, call_async, \
- tp_name_prefix, sync_dbus
-
-from twisted.words.xish import xpath, domish
-from twisted.internet.protocol import Factory, Protocol, ClientCreator
-from twisted.internet import reactor
-
-from constants import INVALID_ARGUMENT, NOT_IMPLEMENTED
-
-PUBLISHED_NAME="test-tube"
-
-CHANNEL_TYPE_TUBES = "org.freedesktop.Telepathy.Channel.Type.Tubes"
-HT_CONTACT = 1
-HT_CONTACT_LIST = 3
-TEXT_MESSAGE_TYPE_NORMAL = dbus.UInt32(0)
-SOCKET_ADDRESS_TYPE_UNIX = dbus.UInt32(0)
-SOCKET_ADDRESS_TYPE_IPV4 = dbus.UInt32(2)
-SOCKET_ADDRESS_TYPE_IPV6 = dbus.UInt32(3)
-SOCKET_ACCESS_CONTROL_LOCALHOST = dbus.UInt32(0)
-
-sample_parameters = dbus.Dictionary({
- 's': 'hello',
- 'ay': dbus.ByteArray('hello'),
- 'u': dbus.UInt32(123),
- 'i': dbus.Int32(-123),
- }, signature='sv')
-
-test_string = "This string travels on a tube !"
-
-print "FIXME: disabled because 1-1 tubes are disabled for now"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-def check_conn_properties(q, bus, conn, channel_list=None):
- properties = conn.GetAll(
- 'org.freedesktop.Telepathy.Connection.Interface.Requests',
- dbus_interface='org.freedesktop.DBus.Properties')
-
- if channel_list == None:
- assert properties.get('Channels') == [], properties['Channels']
- else:
- for i in channel_list:
- assert i in properties['Channels'], \
- (i, properties['Channels'])
-
- assert ({'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.Tubes',
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': HT_CONTACT,
- },
- ['org.freedesktop.Telepathy.Channel.TargetHandle',
- ]
- ) in properties.get('RequestableChannelClasses'),\
- properties['RequestableChannelClasses']
- assert ({'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.TargetHandleType': HT_CONTACT,
- },
- ['org.freedesktop.Telepathy.Channel.TargetHandle',
- 'org.freedesktop.Telepathy.Channel.TargetID',
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube.Service',
- ]
- ) in properties.get('RequestableChannelClasses'),\
- properties['RequestableChannelClasses']
-
-def check_channel_properties(q, bus, conn, channel, channel_type,
- contact_handle, contact_id, state=None):
- # Exercise basic Channel Properties from spec 0.17.7
- # on the channel of type channel_type
- channel_props = channel.GetAll(
- 'org.freedesktop.Telepathy.Channel',
- dbus_interface='org.freedesktop.DBus.Properties')
- assert channel_props.get('TargetHandle') == contact_handle,\
- (channel_props.get('TargetHandle'), contact_handle)
- assert channel_props.get('TargetHandleType') == HT_CONTACT,\
- channel_props.get('TargetHandleType')
- assert channel_props.get('ChannelType') == \
- 'org.freedesktop.Telepathy.Channel.Type.' + channel_type,\
- channel_props.get('ChannelType')
- assert 'Interfaces' in channel_props, channel_props
- assert 'org.freedesktop.Telepathy.Channel.Interface.Group' not in \
- channel_props['Interfaces'], \
- channel_props['Interfaces']
- assert channel_props['TargetID'] == contact_id
-
- if channel_type == "Tubes":
- assert state is None
- else:
- assert state is not None
- tube_props = channel.GetAll(
- 'org.freedesktop.Telepathy.Channel.Interface.Tube',
- dbus_interface='org.freedesktop.DBus.Properties')
- assert tube_props['State'] == state, tube_props['State']
- # no strict check but at least check the properties exist
- assert tube_props.has_key('Parameters')
-
- self_handle = conn.GetSelfHandle()
- self_handle_name = conn.InspectHandles(HT_CONTACT, [self_handle])[0]
-
- assert channel_props['Requested'] == True
- assert channel_props['InitiatorID'] == self_handle_name
- assert channel_props['InitiatorHandle'] == self_handle
-
-
-def check_NewChannel_signal(old_sig, channel_type, chan_path, contact_handle):
- assert old_sig[0] == chan_path, old_sig[0]
- assert old_sig[1] == tp_name_prefix + '.Channel.Type.' + channel_type
- assert old_sig[2] == HT_CONTACT
- assert old_sig[3] == contact_handle
- assert old_sig[4] == True # suppress handler
-
-def check_NewChannels_signal(conn, new_sig, channel_type, chan_path, contact_handle,
- contact_id, initiator_handle):
- assert len(new_sig) == 1
- assert len(new_sig[0]) == 1 # one channel
- assert len(new_sig[0][0]) == 2 # two struct members
- assert new_sig[0][0][0] == chan_path
- emitted_props = new_sig[0][0][1]
-
- initiator_name = conn.InspectHandles(HT_CONTACT, [initiator_handle])[0]
- assert emitted_props[tp_name_prefix + '.Channel.ChannelType'] ==\
- tp_name_prefix + '.Channel.Type.' + channel_type
- assert emitted_props[tp_name_prefix + '.Channel.TargetHandleType'] == \
- HT_CONTACT
- assert emitted_props[tp_name_prefix + '.Channel.TargetHandle'] ==\
- contact_handle
- assert emitted_props[tp_name_prefix + '.Channel.TargetID'] == \
- contact_id
- assert emitted_props[tp_name_prefix + '.Channel.Requested'] == True
- assert emitted_props[tp_name_prefix + '.Channel.InitiatorHandle'] \
- == initiator_handle
- assert emitted_props[tp_name_prefix + '.Channel.InitiatorID'] == \
- initiator_name
-
-def test(q, bus, conn):
-
- # define a basic tcp server that echoes what the client says, but with
- # swapcase
- class TrivialServer(Protocol):
- def dataReceived(self, data):
- self.transport.write(string.swapcase(data))
- e = Event('server-data-received', service = self, data = data)
- q.append(e)
-
- # define a basic tcp client
- class ClientGreeter(Protocol):
- def dataReceived(self, data):
- e = Event('client-data-received', service = self, data = data)
- q.append(e)
- def client_connected_cb(p):
- e = Event('client-connected', transport = p.transport)
- q.append(e)
-
- # create the server
- factory = Factory()
- factory.protocol = TrivialServer
- server_socket_address = os.getcwd() + '/stream'
- try:
- os.remove(server_socket_address)
- except OSError, e:
- if e.errno != errno.ENOENT:
- raise
- l = reactor.listenUNIX(server_socket_address, factory)
-
-
- check_conn_properties(q, bus, conn)
-
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
- basic_txt = { "txtvers": "1", "status": "avail" }
-
- contact_name = PUBLISHED_NAME + "@" + get_host_name()
- listener, port = setup_stream_listener(q, contact_name)
-
- announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)
-
- handle = wait_for_contact_in_publish(q, bus, conn, contact_name)
-
- # NewChannels would be emitted for the contact list channels, we don't
- # want this to interfere with the NewChannels signals for the requested
- # tubes channel
- sync_dbus(bus, q, conn)
-
- # old requestotron
- call_async(q, conn, 'RequestChannel',
- CHANNEL_TYPE_TUBES, HT_CONTACT, 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'),
- )
-
- assert len(ret.value) == 1
- chan_path = ret.value[0]
-
- check_NewChannel_signal(old_sig.args, "Tubes", chan_path, handle)
- check_NewChannels_signal(conn, new_sig.args, "Tubes", chan_path,
- handle, contact_name, conn.GetSelfHandle())
- emitted_props = new_sig.args[0][0][1]
- old_tubes_channel_properties = new_sig.args[0][0]
-
- check_conn_properties(q, bus, conn, [old_tubes_channel_properties])
-
- # new requestotron
- requestotron = dbus.Interface(conn,
- 'org.freedesktop.Telepathy.Connection.Interface.Requests')
-
- # Try to CreateChannel with unknown properties
- # Salut must return an error
- try:
- requestotron.CreateChannel(
- {'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.TargetHandleType':
- HT_CONTACT,
- 'org.freedesktop.Telepathy.Channel.TargetHandle':
- handle,
- 'this.property.does.not.exist':
- 'this.value.should.not.exist'
- })
- except dbus.DBusException, e:
- assert e.get_dbus_name() == NOT_IMPLEMENTED, e.get_dbus_name()
- else:
- assert False, "Should raise NotImplemented error"
-
- # CreateChannel failed, we expect no new channel
- check_conn_properties(q, bus, conn, [old_tubes_channel_properties])
-
- # Try to CreateChannel with missing properties ("Service")
- # Salut must return an error
- try:
- requestotron.CreateChannel(
- {'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.TargetHandleType':
- HT_CONTACT,
- 'org.freedesktop.Telepathy.Channel.TargetHandle':
- handle
- });
- except dbus.DBusException, e:
- assert e.get_dbus_name() == INVALID_ARGUMENT, e.get_dbus_name()
- else:
- assert False, "Should raise InvalidArgument error"
-
- # CreateChannel failed, we expect no new channel
- check_conn_properties(q, bus, conn, [old_tubes_channel_properties])
-
- # Try to CreateChannel with correct properties
- # Salut must succeed
- call_async(q, requestotron, 'CreateChannel',
- {'org.freedesktop.Telepathy.Channel.ChannelType':
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube',
- 'org.freedesktop.Telepathy.Channel.TargetHandleType':
- HT_CONTACT,
- 'org.freedesktop.Telepathy.Channel.TargetHandle':
- handle,
- 'org.freedesktop.Telepathy.Channel.Type.StreamTube.Service':
- "newecho"
- });
- ret, old_sig, new_sig = q.expect_many(
- EventPattern('dbus-return', method='CreateChannel'),
- EventPattern('dbus-signal', signal='NewChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
-
- assert len(ret.value) == 2 # CreateChannel returns 2 values: o, a{sv}
- new_chan_path = ret.value[0]
- stream_tube_channel_properties = ret.value
- # The path of the Channel.Type.Tubes object MUST be different to the path
- # of the Channel.Type.StreamTube object !
- assert chan_path != new_chan_path
-
- channels = new_sig.args[0]
- # tubes and tube channels are announced
- assert len(channels) == 2
-
- check_conn_properties(q, bus, conn,
- [old_tubes_channel_properties, stream_tube_channel_properties])
-
- assert stream_tube_channel_properties[1]['org.freedesktop.Telepathy.Channel.Type.StreamTube.Service'] == \
- 'newecho'
- assert stream_tube_channel_properties[1]['org.freedesktop.Telepathy.Channel.Type.StreamTube.SupportedSocketTypes'] == \
- {SOCKET_ADDRESS_TYPE_UNIX: [SOCKET_ACCESS_CONTROL_LOCALHOST],
- SOCKET_ADDRESS_TYPE_IPV4: [SOCKET_ACCESS_CONTROL_LOCALHOST],
- SOCKET_ADDRESS_TYPE_IPV6: [SOCKET_ACCESS_CONTROL_LOCALHOST]}
-
- # continue
- tubes_channel = make_channel_proxy(conn, chan_path, "Channel.Type.Tubes")
- tube_channel = make_channel_proxy(conn, new_chan_path,
- "Channel.Type.StreamTube")
- check_channel_properties(q, bus, conn, tubes_channel, "Tubes", handle,
- contact_name)
- check_channel_properties(q, bus, conn, tube_channel, "StreamTube",
- handle, contact_name, 3)
-
- tube_channel.Offer(SOCKET_ADDRESS_TYPE_UNIX, dbus.ByteArray(server_socket_address),
- SOCKET_ACCESS_CONTROL_LOCALHOST, {'foo': 'bar'})
-
- e = q.expect('stream-iq')
- iq_tube = xpath.queryForNodes('/iq/tube', e.stanza)[0]
- transport = xpath.queryForNodes('/iq/tube/transport', e.stanza)[0]
- assert iq_tube.attributes['type'] == 'stream'
- assert iq_tube.attributes['service'] == 'newecho', \
- iq_tube.attributes['service']
- assert iq_tube.attributes['id'] is not None
- port = transport.attributes['port']
- assert port is not None
- port = int(port)
- assert port > 1024
- assert port < 65536
-
- params = {}
- parameter_nodes = xpath.queryForNodes('/iq/tube/parameters/parameter',
- e.stanza)
- for node in parameter_nodes:
- assert node['name'] not in params
- params[node['name']] = (node['type'], str(node))
- assert params == {'foo': ('str', 'bar')}, params
-
- # find the right host/IP address because Salut checks it
- self_handle = conn.GetSelfHandle()
- self_handle_name = conn.InspectHandles(HT_CONTACT, [self_handle])[0]
- AvahiListener(q).listen_for_service("_presence._tcp")
- e = q.expect('service-added', name = self_handle_name,
- protocol = avahi.PROTO_INET)
- service = e.service
- service.resolve()
- e = q.expect('service-resolved', service = service)
- host_name = e.host_name
-
- client = ClientCreator(reactor, ClientGreeter)
- client.connectTCP(host_name, port).addCallback(client_connected_cb)
-
- e = q.expect('client-connected')
- client_transport = e.transport
- client_transport.write(test_string)
-
- e = q.expect('server-data-received')
- assert e.data == test_string
-
- e = q.expect('client-data-received')
- assert e.data == string.swapcase(test_string)
-
- # Close the tubes propertly
- for i in tubes_channel.ListTubes():
- tubes_channel.CloseTube(i[0])
- conn.Disconnect()
-
-if __name__ == '__main__':
- exec_test(test)
diff --git a/tests/twisted/avahi/tubes/request-invalid-dbus-tube.py b/tests/twisted/avahi/tubes/request-invalid-dbus-tube.py
deleted file mode 100644
index f1cb8792..00000000
--- a/tests/twisted/avahi/tubes/request-invalid-dbus-tube.py
+++ /dev/null
@@ -1,62 +0,0 @@
-from saluttest import exec_test
-from avahitest import AvahiAnnouncer, AvahiListener
-from avahitest import get_host_name
-import avahi
-import dbus
-import os
-import errno
-import string
-
-from xmppstream import setup_stream_listener, connect_to_stream
-from servicetest import make_channel_proxy, Event, EventPattern, call_async, \
- tp_name_prefix, sync_dbus
-
-from twisted.words.xish import xpath, domish
-from twisted.internet.protocol import Factory, Protocol, ClientCreator
-from twisted.internet import reactor
-import constants as cs
-
-print "FIXME: disabled because new DBus tube API is not implemented"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-PUBLISHED_NAME="test-tube"
-
-CHANNEL_TYPE_TUBES = "org.freedesktop.Telepathy.Channel.Type.Tubes"
-C_T_DTUBE = 'org.freedesktop.Telepathy.Channel.Type.DBusTube'
-HT_CONTACT = 1
-
-invalid_service_names = [ 'invalidServiceName'
- , 'one ten hundred thousand million'
- , 'me.is.it.you?.hello.you.sexy.sons.o.@#$%.heh'
- , ':1.1'
- , ''
- ]
-
-def test(q, bus, conn):
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
-
- requestotron = dbus.Interface(conn,
- 'org.freedesktop.Telepathy.Connection.Interface.Requests')
-
- for invalid_service_name in invalid_service_names:
- try:
- requestotron.CreateChannel(
- {'org.freedesktop.Telepathy.Channel.ChannelType':
- C_T_DTUBE,
- 'org.freedesktop.Telepathy.Channel.TargetHandleType':
- HT_CONTACT,
- 'org.freedesktop.Telepathy.Channel.TargetID':
- 'alice',
- C_T_DTUBE + '.ServiceName':
- invalid_service_name
- });
- except dbus.DBusException, e:
- assert e.get_dbus_name() == cs.INVALID_ARGUMENT,\
- (e.get_dbus_name(), invalid_service_name)
- else:
- assert False, "Should raise InvalidArgument error"
-
-if __name__ == '__main__':
- exec_test(test)
diff --git a/tests/twisted/avahi/tubes/tube-close.py b/tests/twisted/avahi/tubes/tube-close.py
deleted file mode 100644
index ae2c2af0..00000000
--- a/tests/twisted/avahi/tubes/tube-close.py
+++ /dev/null
@@ -1,71 +0,0 @@
-"""
-Offer a 1-1 stream tube and close the connection. Salut must just send a
-stanza to close the tube and disconnect.
-"""
-
-from saluttest import exec_test, wait_for_contact_in_publish
-from avahitest import AvahiAnnouncer, AvahiListener
-from avahitest import get_host_name
-import avahi
-
-from xmppstream import setup_stream_listener, connect_to_stream
-from servicetest import make_channel_proxy
-
-from twisted.words.xish import xpath, domish
-
-import dbus
-
-PUBLISHED_NAME="test-tube"
-
-CHANNEL_TYPE_TUBES = "org.freedesktop.Telepathy.Channel.Type.Tubes"
-HT_CONTACT = 1
-HT_CONTACT_LIST = 3
-SOCKET_ADDRESS_TYPE_IPV4 = dbus.UInt32(2)
-SOCKET_ACCESS_CONTROL_LOCALHOST = dbus.UInt32(0)
-
-#print "FIXME: test-tube-close.py disabled because sending a close stanza on "
-#print "disconnection is not yet implemented in telepathy-salut. It requires "
-#print "to ensure the XmppConnection and reestablish it"
-print "FIXME: disabled because 1-1 tubes are disabled for now"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-def test(q, bus, conn):
- # Salut will not connect to this socket, the test finishs before
- socket_address = ('0.0.0.0', dbus.UInt16(0))
-
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
- basic_txt = { "txtvers": "1", "status": "avail" }
-
- contact_name = PUBLISHED_NAME + "@" + get_host_name()
- listener, port = setup_stream_listener(q, contact_name)
-
- announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)
-
- handle = wait_for_contact_in_publish(q, bus, conn, contact_name)
-
- t = conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT, handle,
- True)
- tubes_channel = make_channel_proxy(conn, t, "Channel.Type.Tubes")
-
- tubes_channel.OfferStreamTube("http", dbus.Dictionary({}),
- SOCKET_ADDRESS_TYPE_IPV4, socket_address,
- SOCKET_ACCESS_CONTROL_LOCALHOST, "")
-
- e = q.expect('stream-iq')
-
- # Close the connection just after the tube has been offered.
- conn.Disconnect()
-
- # receive the close stanza for the tube
- event = q.expect('stream-message')
- message = event.stanza
- close_node = xpath.queryForNodes('/message/close[@xmlns="%s"]' % NS_TUBES,
- message)
- assert close_node is not None
-
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-if __name__ == '__main__':
- exec_test(test)
diff --git a/tests/twisted/avahi/tubes/tubes-to-nonexistant-ids.py b/tests/twisted/avahi/tubes/tubes-to-nonexistant-ids.py
deleted file mode 100644
index 7fb9b162..00000000
--- a/tests/twisted/avahi/tubes/tubes-to-nonexistant-ids.py
+++ /dev/null
@@ -1,54 +0,0 @@
-"""
-Test that requests for Tubes and StreamTube channels to ids which aren't
-actually on the network fail gracefully with NotAvailable
-"""
-
-from saluttest import exec_test
-
-from constants import (
- HT_CONTACT, CONN_IFACE_REQUESTS,
- CHANNEL_TYPE, TARGET_HANDLE_TYPE, TARGET_HANDLE,
- CHANNEL_TYPE_TUBES, CHANNEL_TYPE_STREAM_TUBE,
- NOT_AVAILABLE
- )
-
-import dbus
-
-arbitrary_ids = [ "DooN4Bei@TheeK6bo-Tegh4aci", "ahrui1iM@Dai6igho-ADetaes3" ]
-
-print "FIXME: disabled because 1-1 tubes are disabled for now"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-def test(q, bus, conn):
- conn.Connect()
- q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
-
- h1, h2 = conn.RequestHandles(HT_CONTACT, arbitrary_ids)
-
- try:
- conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT, h1, True)
- except dbus.DBusException, e:
- assert e.get_dbus_name() == NOT_AVAILABLE, e.get_dbus_name()
- else:
- assert False, "Should raise NotAvailable error"
-
- requestotron = dbus.Interface(conn, CONN_IFACE_REQUESTS)
-
- try:
- requestotron.CreateChannel({
- CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
- TARGET_HANDLE_TYPE: HT_CONTACT,
- TARGET_HANDLE: h2,
- CHANNEL_TYPE_STREAM_TUBE + ".Service": "com.example",
- })
- except dbus.DBusException, e:
- assert e.get_dbus_name() == NOT_AVAILABLE, e.get_dbus_name()
- else:
- assert False, "Should raise NotAvailable error"
-
- conn.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-if __name__ == '__main__':
- exec_test(test)
diff --git a/tests/twisted/avahi/tubes/two-private-stream-tubes.py b/tests/twisted/avahi/tubes/two-private-stream-tubes.py
deleted file mode 100644
index e1956be9..00000000
--- a/tests/twisted/avahi/tubes/two-private-stream-tubes.py
+++ /dev/null
@@ -1,329 +0,0 @@
-from saluttest import exec_test
-import dbus
-import os
-import errno
-import string
-
-from servicetest import make_channel_proxy, Event, EventPattern, call_async
-
-from twisted.internet.protocol import Factory, Protocol, ClientCreator
-from twisted.internet import reactor
-from constants import *
-import tubetestutil as t
-
-sample_parameters = dbus.Dictionary({
- 's': 'hello',
- 'ay': dbus.ByteArray('hello'),
- 'u': dbus.UInt32(123),
- 'i': dbus.Int32(-123),
- }, signature='sv')
-
-test_string = "This string travels on a tube !"
-
-SERVER_WELCOME_MSG = "Welcome!"
-
-print "FIXME: disabled because 1-1 tubes are disabled for now"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-def test(q, bus, conn):
-
- # define a basic tcp server that echoes what the client says, but with
- # swapcase
- class TrivialServer(Protocol):
- def dataReceived(self, data):
- self.transport.write(string.swapcase(data))
- e = Event('server-data-received', service = self, data = data)
- q.append(e)
-
- def connectionMade(self):
- e = Event('server-connected', transport = self.transport)
- q.append(e)
-
- # send welcome message to the client
- self.transport.write(SERVER_WELCOME_MSG)
-
- # define a basic tcp client
- class ClientGreeter(Protocol):
- def dataReceived(self, data):
- e = Event('client-data-received', service = self, data = data)
- q.append(e)
-
- def client_connected_cb(p):
- e = Event('client-connected', transport = p.transport)
- q.append(e)
-
- # create the server
- factory = Factory()
- factory.protocol = TrivialServer
- server_socket_address = os.getcwd() + '/stream'
- try:
- os.remove(server_socket_address)
- except OSError, e:
- if e.errno != errno.ENOENT:
- raise
- l = reactor.listenUNIX(server_socket_address, factory)
-
- contact1_name, conn2, contact2_name, contact2_handle_on_conn1,\
- contact1_handle_on_conn2 = t.connect_two_accounts(q, bus, conn)
-
- conn1_self_handle = conn.GetSelfHandle()
-
- # contact1 offers stream tube to contact2 (old API)
- contact1_tubes_channel_path = conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT,
- contact2_handle_on_conn1, True)
- contact1_tubes_channel = make_channel_proxy(conn, contact1_tubes_channel_path, "Channel.Type.Tubes")
- contact1_tubes_channel_iface = make_channel_proxy(conn, contact1_tubes_channel_path, "Channel")
-
- tube_id = contact1_tubes_channel.OfferStreamTube("http", sample_parameters,
- SOCKET_ADDRESS_TYPE_UNIX, dbus.ByteArray(server_socket_address),
- SOCKET_ACCESS_CONTROL_LOCALHOST, "")
-
- contact2_tubes_channel_path = None
- while contact2_tubes_channel_path is None:
- e = q.expect('dbus-signal', signal='NewChannel')
- if (e.args[1] == CHANNEL_TYPE_TUBES) and (e.path.endswith("testsuite2") == True):
- contact2_tubes_channel_path = e.args[0]
-
- contact2_tubes_channel = make_channel_proxy(conn2, contact2_tubes_channel_path, "Channel.Type.Tubes")
- contact2_tubes_channel_iface = make_channel_proxy(conn, contact2_tubes_channel_path, "Channel")
-
- contact2_tubes = contact2_tubes_channel.ListTubes()
- assert len(contact2_tubes) == 1
- contact2_tube = contact2_tubes[0]
- assert contact2_tube[0] is not None # tube id
- assert contact2_tube[1] is not None # initiator
- assert contact2_tube[2] == 1 # type = stream tube
- assert contact2_tube[3] == 'http' # service = http
- assert contact2_tube[4] is not None # parameters
- assert contact2_tube[5] == 0, contact2_tube[5] # status = local pending
-
- unix_socket_adr = contact2_tubes_channel.AcceptStreamTube(
- contact2_tube[0], 0, 0, '', byte_arrays=True)
-
- client = ClientCreator(reactor, ClientGreeter)
- client.connectUNIX(unix_socket_adr).addCallback(client_connected_cb)
-
- # server got the connection
- _, e, new_conn_event, data_event = q.expect_many(
- EventPattern('server-connected'),
- EventPattern('client-connected'),
- EventPattern('dbus-signal', signal='StreamTubeNewConnection', path=contact1_tubes_channel_path),
- EventPattern('client-data-received'))
-
- client_transport = e.transport
-
- id, handle = new_conn_event.args
- assert id == tube_id
- assert handle == contact2_handle_on_conn1
-
- # client receives server's welcome message
- assert data_event.data == SERVER_WELCOME_MSG
-
- client_transport.write(test_string)
-
- server_received, client_received = q.expect_many(
- EventPattern('server-data-received'),
- EventPattern('client-data-received'))
-
- assert server_received.data == test_string
- assert client_received.data == string.swapcase(test_string)
-
- # Close the tube propertly
- call_async(q, contact1_tubes_channel, 'CloseTube', tube_id)
-
- q.expect_many(
- EventPattern('dbus-signal', signal='TubeClosed', path=contact1_tubes_channel_path),
- EventPattern('dbus-signal', signal='TubeClosed', path=contact2_tubes_channel_path),
- EventPattern('dbus-return', method='CloseTube'))
-
- # close both tubes channels
- contact1_tubes_channel_iface.Close()
- contact2_tubes_channel_iface.Close()
-
- # now contact1 will offer another stream tube to contact2 using the new
- # API
-
- # Can we request private stream tubes?
- properties = conn.GetAll(CONN_IFACE_REQUESTS, dbus_interface=PROPERTIES_IFACE)
-
- assert ({CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
- TARGET_HANDLE_TYPE: HT_CONTACT},
- [TARGET_HANDLE, TARGET_ID, STREAM_TUBE_SERVICE]
- ) in properties.get('RequestableChannelClasses'),\
- properties['RequestableChannelClasses']
-
- requestotron = dbus.Interface(conn, CONN_IFACE_REQUESTS)
-
- requestotron.CreateChannel({
- CHANNEL_TYPE: CHANNEL_TYPE_STREAM_TUBE,
- TARGET_HANDLE_TYPE: HT_CONTACT,
- TARGET_ID: contact2_name,
- STREAM_TUBE_SERVICE: 'test'})
-
- # tubes and tube channels are created on the first connection
- e = q.expect('dbus-signal', signal='NewChannels', path=conn.object.object_path)
- channels = e.args[0]
- assert len(channels) == 2
-
- # get the list of all channels to check that newly announced ones are in it
- all_channels = conn.Get(CONN_IFACE_REQUESTS, 'Channels', dbus_interface=PROPERTIES_IFACE,
- byte_arrays=True)
-
- got_tubes, got_tube = False, False
- for path, props in channels:
- if props[CHANNEL_TYPE] == CHANNEL_TYPE_TUBES:
- got_tubes = True
- assert props[REQUESTED] == False
- assert props[INTERFACES] == []
- elif props[CHANNEL_TYPE] == CHANNEL_TYPE_STREAM_TUBE:
- got_tube = True
- assert props[REQUESTED] == True
- assert props[INTERFACES] == [CHANNEL_IFACE_TUBE]
- assert props[STREAM_TUBE_SERVICE] == 'test'
-
- contact1_tube = bus.get_object(conn.bus_name, path)
- contact1_stream_tube = make_channel_proxy(conn, path, "Channel.Type.StreamTube")
- contact1_tube_channel = make_channel_proxy(conn, path, "Channel")
- tube1_path = path
- else:
- assert False
-
- assert props[INITIATOR_HANDLE] == conn1_self_handle
- assert props[INITIATOR_ID] == contact1_name
- assert props[TARGET_ID] == contact2_name
-
- assert (path, props) in all_channels, (path, props)
-
- assert got_tubes
- assert got_tube
-
- state = contact1_stream_tube.Get(CHANNEL_IFACE_TUBE, 'State', dbus_interface=PROPERTIES_IFACE)
- assert state == TUBE_CHANNEL_STATE_NOT_OFFERED
-
- call_async(q, contact1_stream_tube, 'Offer', SOCKET_ADDRESS_TYPE_UNIX,
- dbus.ByteArray(server_socket_address), SOCKET_ACCESS_CONTROL_LOCALHOST, sample_parameters)
-
- _, return_event, new_chans = q.expect_many(
- EventPattern('dbus-signal', signal='TubeChannelStateChanged',
- args=[TUBE_CHANNEL_STATE_REMOTE_PENDING]),
- EventPattern('dbus-return', method='Offer'),
- EventPattern('dbus-signal', signal='NewChannels', path=conn2.object.object_path))
-
- state = contact1_stream_tube.Get(CHANNEL_IFACE_TUBE, 'State', dbus_interface=PROPERTIES_IFACE)
- assert state == TUBE_CHANNEL_STATE_REMOTE_PENDING
-
- # tube and tubes channels have been created on conn2
- channels = new_chans.args[0]
- assert len(channels) == 2
-
- # get the list of all channels to check that newly announced ones are in it
- all_channels = conn2.Get(CONN_IFACE_REQUESTS, 'Channels', dbus_interface=PROPERTIES_IFACE,
- byte_arrays=True)
-
- got_tubes, got_tube = False, False
- for path, props in channels:
- if props[CHANNEL_TYPE] == CHANNEL_TYPE_TUBES:
- got_tubes = True
- assert props[REQUESTED] == False
- assert props[INTERFACES] == []
- elif props[CHANNEL_TYPE] == CHANNEL_TYPE_STREAM_TUBE:
- got_tube = True
- assert props[REQUESTED] == False
- assert props[INTERFACES] == [CHANNEL_IFACE_TUBE]
- assert props[STREAM_TUBE_SERVICE] == 'test'
-
- contact2_tube = bus.get_object(conn.bus_name, path)
- contact2_stream_tube = make_channel_proxy(conn, path, "Channel.Type.StreamTube")
- contact2_tube_channel = make_channel_proxy(conn, path, "Channel")
- tube2_path = path
- else:
- assert False
-
- assert props[INITIATOR_HANDLE] == contact1_handle_on_conn2
- assert props[INITIATOR_ID] == contact1_name
- assert props[TARGET_ID] == contact1_name
-
- assert (path, props) in all_channels, (path, props)
-
- assert got_tubes
- assert got_tube
-
- state = contact2_tube.Get(CHANNEL_IFACE_TUBE, 'State', dbus_interface=PROPERTIES_IFACE)
- assert state == TUBE_CHANNEL_STATE_LOCAL_PENDING
-
- # second connection: accept the tube (new API)
- unix_socket_adr = contact2_stream_tube.Accept(SOCKET_ADDRESS_TYPE_UNIX,
- SOCKET_ACCESS_CONTROL_LOCALHOST, '', byte_arrays=True)
-
- state = contact2_tube.Get(CHANNEL_IFACE_TUBE, 'State', dbus_interface=PROPERTIES_IFACE)
- assert state == TUBE_CHANNEL_STATE_OPEN
-
- q.expect_many(
- EventPattern('dbus-signal', signal='TubeChannelStateChanged', path=tube2_path,
- args=[TUBE_CHANNEL_STATE_OPEN]),
- EventPattern('dbus-signal', signal='TubeChannelStateChanged', path=tube1_path,
- args=[TUBE_CHANNEL_STATE_OPEN]))
-
- client = ClientCreator(reactor, ClientGreeter)
- client.connectUNIX(unix_socket_adr).addCallback(client_connected_cb)
-
- # server got the connection
- _, client_connected, remote_sig, local_sig, data_received = q.expect_many(
- EventPattern('server-connected'),
- EventPattern('client-connected'),
- EventPattern('dbus-signal', signal='NewRemoteConnection',
- path=tube1_path),
- EventPattern('dbus-signal', signal='NewLocalConnection',
- path=tube2_path),
- EventPattern('client-data-received'))
-
- client_transport = client_connected.transport
-
- handle, conn_param, contact1_tube_conn_id = remote_sig.args
- assert handle == contact2_handle_on_conn1
- assert contact1_tube_conn_id != 0
-
- contact2_tube_conn_id = local_sig.args[0]
- assert contact2_tube_conn_id != 0
-
- # client receives server's welcome message
- assert data_received.data == SERVER_WELCOME_MSG
-
- client_transport.write(test_string)
-
- server_received, client_received = q.expect_many(
- EventPattern('server-data-received'),
- EventPattern('client-data-received'))
-
- assert server_received.data == test_string
- assert client_received.data == string.swapcase(test_string)
-
- # contact1 close the tube
- call_async(q, contact1_tube_channel, 'Close')
-
- # tube is closed on both sides
- _, e1, e2, _, _, _, _ = q.expect_many(
- EventPattern('dbus-return', method='Close'),
- EventPattern('dbus-signal', signal='ConnectionClosed', path=tube1_path),
- EventPattern('dbus-signal', signal='ConnectionClosed', path=tube2_path),
- EventPattern('dbus-signal', signal='Closed', path=tube1_path),
- EventPattern('dbus-signal', signal='Closed', path=tube2_path),
- EventPattern('dbus-signal', signal='ChannelClosed', path=conn.object.object_path),
- EventPattern('dbus-signal', signal='ChannelClosed', path=conn2.object.object_path))
-
- conn_id, error, dbus_msg = e1.args
- assert conn_id == contact1_tube_conn_id
- assert error == CANCELLED
-
- conn_id, error, dbus_msg = e2.args
- assert conn_id == contact2_tube_conn_id
- assert error == CANCELLED
-
- conn.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
- conn2.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-if __name__ == '__main__':
- exec_test(test)