[Telepathy-commits] [telepathy-gabble/master] offer-accept-private-dbus-stream-tube-socks5.py: use BytestreamS5B
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Wed Feb 25 03:59:22 PST 2009
---
...offer-accept-private-dbus-stream-tube-socks5.py | 91 +++++++------------
1 files changed, 34 insertions(+), 57 deletions(-)
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 ad5b497..1b1ba52 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
@@ -11,14 +11,10 @@ from gabbletest import exec_test, acknowledge_iq, sync_stream
import constants as cs
import ns
import tubetestutil as t
-from bytestream import S5BFactory, socks5_expect_connection, socks5_connect, \
- send_socks5_init, expect_socks5_init, expect_socks5_reply, \
- create_si_offer, parse_si_reply, create_si_reply, parse_si_offer, \
- listen_socks5, send_socks5_reply
+from bytestream import expect_socks5_reply, create_si_offer, parse_si_reply,\
+ create_si_reply, parse_si_offer, listen_socks5, BytestreamS5B
from twisted.words.xish import domish, xpath
-from twisted.internet import reactor
-from twisted.words.protocols.jabber.client import IQ
sample_parameters = dbus.Dictionary({
's': 'hello',
@@ -253,8 +249,12 @@ def test(q, bus, conn, stream):
# The CM is the server, so fake a client wanting to talk to it
# Old API tube
- iq, si = create_si_offer(stream, bob_full_jid, self_full_jid, 'alpha', ns.TUBES,
- [ns.BYTESTREAMS])
+
+ bytestream1 = BytestreamS5B(stream, q, 'alpha', bob_full_jid,
+ self_full_jid)
+
+ iq, si = create_si_offer(stream, bytestream1.initiator, bytestream1.target,
+ bytestream1.stream_id, ns.TUBES, [bytestream1.get_ns()])
stream_node = si.addElement((ns.TUBES, 'stream'))
stream_node['tube'] = str(stream_tube_id)
@@ -280,8 +280,11 @@ def test(q, bus, conn, stream):
# The CM is the server, so fake a client wanting to talk to it
# New API tube
- iq, si = create_si_offer(stream, bob_full_jid, self_full_jid, 'beta', ns.TUBES,
- [ns.BYTESTREAMS])
+ bytestream2 = BytestreamS5B(stream, q, 'beta', bob_full_jid,
+ self_full_jid)
+
+ iq, si = create_si_offer(stream, bytestream2.initiator, bytestream2.target,
+ bytestream2.stream_id, ns.TUBES, [bytestream2.get_ns()])
stream_node = si.addElement((ns.TUBES, 'stream'))
stream_node['tube'] = str(new_stream_tube_id)
@@ -310,48 +313,25 @@ def test(q, bus, conn, stream):
cs.TUBE_STATE_OPEN,
) in tubes, tubes
- port = listen_socks5(q)
- # have the fake client open the stream
- # Old tube API
- send_socks5_init(stream, bob_full_jid, self_full_jid, 'alpha', 'tcp', [
- # Not working streamhost
- ('invalid.invalid', 'invalid.invalid', port),
- # Working streamhost
- (bob_full_jid, '127.0.0.1', port),
- # This works too but should not be tried as gabble should just
- # connect to the previous one
- ('bob at localhost', '127.0.0.1', port)])
-
- transport = socks5_expect_connection(q, 'alpha', bob_full_jid, self_full_jid)
+ bytestream1.open_bytestream()
streamhost_used = expect_socks5_reply(q)
assert streamhost_used['jid'] == bob_full_jid
- transport.write("HELLO WORLD")
+ bytestream1.send_data("HELLO WORLD")
event = q.expect('s5b-data-received')
assert event.data == 'hello world'
# this connection is disconnected
- transport.loseConnection()
-
- port = listen_socks5(q)
+ bytestream1.transport.loseConnection()
- send_socks5_init(stream, bob_full_jid, self_full_jid, 'beta', 'tcp', [
- # Not working streamhost
- ('invalid.invalid', 'invalid.invalid', port),
- # Working streamhost
- (bob_full_jid, '127.0.0.1', port),
- # This works too but should not be tried as gabble should just
- # connect to the previous one
- ('bob at localhost', '127.0.0.1', port)])
-
- transport = socks5_expect_connection(q, 'beta', bob_full_jid, self_full_jid)
+ bytestream2.open_bytestream()
streamhost_used = expect_socks5_reply(q)
assert streamhost_used['jid'] == bob_full_jid
- transport.write("HELLO, NEW WORLD")
+ bytestream2.send_data("HELLO, NEW WORLD")
event = q.expect('s5b-data-received')
assert event.data == 'hello, new world'
@@ -384,17 +364,13 @@ def test(q, bus, conn, stream):
'u': ('uint', '123'),
}
- result = create_si_reply(stream, event.stanza, self_full_jid, ns.BYTESTREAMS)
- stream.send(result)
-
- id, mode, sid, hosts = expect_socks5_init(q)
- assert mode == 'tcp'
- assert sid == dbus_stream_id
- jid, host, port = hosts[0]
+ bytestream3 = BytestreamS5B(stream, q, dbus_stream_id, self_full_jid,
+ event.stanza['to'])
- transport = socks5_connect(q, host, port, sid, self_full_jid, bob_full_jid)
+ result = create_si_reply(stream, event.stanza, self_full_jid, bytestream3.get_ns())
+ stream.send(result)
- send_socks5_reply(stream, bob_full_jid, self_full_jid, id, jid)
+ bytestream3.wait_bytestream_open()
q.expect('dbus-signal', signal='TubeStateChanged',
args=[dbus_tube_id, cs.TUBE_STATE_OPEN])
@@ -433,14 +409,14 @@ def test(q, bus, conn, stream):
watch_tube_signals(q, dbus_tube_conn)
# Have the fake client send us a message all in one go...
- transport.write(dbus_message)
+ bytestream3.send_data(dbus_message)
# ... and a message one byte at a time ...
for byte in dbus_message:
- transport.write(byte)
+ bytestream3.send_data(byte)
# ... and two messages in one go
- transport.write(dbus_message + dbus_message)
+ bytestream3.send_data(dbus_message + dbus_message)
q.expect('tube-signal', signal='baz', args=[42], tube=dbus_tube_conn)
q.expect('tube-signal', signal='baz', args=[42], tube=dbus_tube_conn)
@@ -448,8 +424,10 @@ def test(q, bus, conn, stream):
q.expect('tube-signal', signal='baz', args=[42], tube=dbus_tube_conn)
# OK, now let's try to accept a D-Bus tube
- iq, si = create_si_offer(stream, bob_full_jid, self_full_jid, 'beta', ns.TUBES,
- [ns.BYTESTREAMS])
+ bytestream4 = BytestreamS5B(stream, q, 'beta', bob_full_jid, self_full_jid)
+
+ iq, si = create_si_offer(stream, bytestream4.initiator, bytestream4.target,
+ bytestream4.stream_id, ns.TUBES, [bytestream4.get_ns()])
tube = si.addElement((ns.TUBES, 'tube'))
tube['type'] = 'dbus'
@@ -490,13 +468,12 @@ def test(q, bus, conn, stream):
port = listen_socks5(q)
+ expected = EventPattern('dbus-return', method='AcceptDBusTube')
+
# Init the SOCKS5 bytestream
- send_socks5_init(stream, bob_full_jid, self_full_jid, 'beta', 'tcp', [
- (bob_full_jid, '127.0.0.1', port)])
+ event = bytestream4.open_bytestream(expected)
+ print event
- event, _ = q.expect_many(
- EventPattern('dbus-return', method='AcceptDBusTube'),
- EventPattern('s5b-connected'))
address = event.value[0]
assert len(address) > 0
--
1.5.6.5
More information about the telepathy-commits
mailing list