[telepathy-gabble/master] test-fallback-socks5-proxy: test if proxy queries are sent when accepting a stream tube
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Thu Nov 26 07:32:40 PST 2009
---
tests/twisted/test-fallback-socks5-proxy.py | 51 +++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/tests/twisted/test-fallback-socks5-proxy.py b/tests/twisted/test-fallback-socks5-proxy.py
index 52d4183..09a0b55 100644
--- a/tests/twisted/test-fallback-socks5-proxy.py
+++ b/tests/twisted/test-fallback-socks5-proxy.py
@@ -1,4 +1,5 @@
import dbus
+import socket
from gabbletest import exec_test, elem, elem_iq, sync_stream, make_presence
from servicetest import EventPattern
from caps_helper import make_caps_disco_reply
@@ -91,6 +92,56 @@ def offer_dbus_tube(q, bus, conn, stream):
e = q.expect('stream-iq', to='alice at localhost/Test')
check_socks5_stanza(e.stanza)
+def accept_stream_tube(q, bus, conn, stream):
+ connect_and_announce_alice(q, bus, conn, stream)
+
+ # Accept a stream tube, we'll need SOCKS5 proxies each time we'll connect
+ # on the tube socket
+
+ # Alice offers us a stream tube
+ message = elem('message', to='test at localhost/Resource', from_='alice at localhost/Test')(
+ elem(ns.TUBES, 'tube', type='stream', service='http', id='10'))
+ stream.send(message)
+
+ # we are interested in the 'NewChannels' announcing the tube channel
+ def new_chan_predicate(e):
+ path, props = e.args[0][0]
+ return props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_STREAM_TUBE
+
+ # Proxy queries are send when receiving an incoming stream tube
+ new_chan, e1, e2 = q.expect_many(
+ EventPattern('dbus-signal', signal='NewChannels', predicate=new_chan_predicate),
+ proxy_query_events[0], proxy_query_events[1])
+
+ send_socks5_reply(stream, e1.stanza)
+ send_socks5_reply(stream, e2.stanza)
+
+ path, props = new_chan.args[0][0]
+ assert props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_STREAM_TUBE
+
+ tube_chan = bus.get_object(conn.bus_name, path)
+ tube_iface = dbus.Interface(tube_chan, cs.CHANNEL_TYPE_STREAM_TUBE)
+
+ # connect to the socket so a SOCKS5 bytestream will be created
+ address = tube_iface.Accept(cs.SOCKET_ADDRESS_TYPE_IPV4,
+ cs.SOCKET_ACCESS_CONTROL_LOCALHOST, 0, byte_arrays=True)
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect(address)
+
+ e = q.expect('stream-iq', to='alice at localhost/Test')
+
+ bytestream, profile = create_from_si_offer(stream, q, BytestreamS5B, e.stanza,
+ 'test at localhost/Resource')
+
+ # Alice accepts the connection
+ result, si = bytestream.create_si_reply(e.stanza)
+ stream.send(result)
+
+ e = q.expect('stream-iq', to='alice at localhost/Test')
+ check_socks5_stanza(e.stanza)
+
if __name__ == '__main__':
params = {'fallback-socks5-proxies': ['fallback1-proxy.localhost', 'fallback2-proxy.localhost']}
exec_test(offer_dbus_tube, params=params)
+ exec_test(accept_stream_tube, params=params)
--
1.5.6.5
More information about the telepathy-commits
mailing list