[Telepathy-commits] [telepathy-gabble/master] Connect tests: moved in connect/ directory, separate the blocking-tls test and the connect-twice test

Alban Crequy alban.crequy at collabora.co.uk
Tue Aug 19 10:52:53 PDT 2008


20080603170156-a41c0-ecfdd43e0c78e4ef65846e838c6ef72bb1b34670.gz
---
 tests/twisted/Makefile.am                     |    7 +-
 tests/twisted/connect/test-fail.py            |   17 +++
 tests/twisted/connect/test-nonblocking-tls.py |  133 +++++++++++++++++++++++++
 tests/twisted/connect/test-success.py         |   21 ++++
 tests/twisted/connect/test-twice.py           |   90 +++++++++++++++++
 tests/twisted/test-connect-fail.py            |   17 ---
 tests/twisted/test-connect-twice.py           |  133 -------------------------
 tests/twisted/test-connect.py                 |   21 ----
 8 files changed, 265 insertions(+), 174 deletions(-)
 create mode 100644 tests/twisted/connect/.git-darcs-dir
 create mode 100644 tests/twisted/connect/test-fail.py
 create mode 100644 tests/twisted/connect/test-nonblocking-tls.py
 create mode 100644 tests/twisted/connect/test-success.py
 create mode 100644 tests/twisted/connect/test-twice.py
 delete mode 100644 tests/twisted/test-connect-fail.py
 delete mode 100644 tests/twisted/test-connect-twice.py
 delete mode 100644 tests/twisted/test-connect.py

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 142ac33..a516072 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -43,9 +43,10 @@ TWISTED_TESTS = \
 	test-capabilities.py \
 	test-caps-cache.py \
 	test-caps-hash.py \
-	test-connect-fail.py \
-	test-connect.py \
-	test-connect-twice.py \
+	connect/test-fail.py \
+	connect/test-success.py \
+	connect/test-twice.py \
+	connect/test-nonblocking-tls.py \
 	test-disco.py \
 	test-disco-no-reply.py \
 	test-group-race.py \
diff --git a/tests/twisted/connect/.git-darcs-dir b/tests/twisted/connect/.git-darcs-dir
new file mode 100644
index 0000000..e69de29
diff --git a/tests/twisted/connect/test-fail.py b/tests/twisted/connect/test-fail.py
new file mode 100644
index 0000000..a7c5e3e
--- /dev/null
+++ b/tests/twisted/connect/test-fail.py
@@ -0,0 +1,17 @@
+
+"""
+Test network error handling.
+"""
+
+import dbus
+
+from gabbletest import exec_test
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])
+
+if __name__ == '__main__':
+    exec_test(test, {'port': dbus.UInt32(4243)})
+
diff --git a/tests/twisted/connect/test-nonblocking-tls.py b/tests/twisted/connect/test-nonblocking-tls.py
new file mode 100644
index 0000000..4b6289a
--- /dev/null
+++ b/tests/twisted/connect/test-nonblocking-tls.py
@@ -0,0 +1,133 @@
+
+"""
+Test connecting to a server with 2 accounts. Check one account does not block
+the second account.
+"""
+
+import os
+import sys
+import dbus
+import servicetest
+
+import twisted
+from twisted.words.xish import domish, xpath
+from twisted.words.protocols.jabber import xmlstream
+
+from gabbletest import make_connection, make_stream, JabberAuthenticator, \
+                       XmppAuthenticator, \
+                       XmppXmlStream, JabberXmlStream
+
+NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls'
+NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
+
+
+print "FIXME: test-connect-twice.py disabled due to a bug in Loudmouth:"
+print "       http://developer.imendio.com/issues/browse/LM-44"
+print "       https://bugs.freedesktop.org/show_bug.cgi?id=14341"
+# exiting 77 causes automake to consider the test to have been skipped
+raise SystemExit(77)
+
+
+class BlockForeverTlsAuthenticator(xmlstream.Authenticator):
+    """A TLS stream authenticator that is deliberately broken. It sends
+    <proceed/> to the client but then do nothing, so the TLS handshake will
+    not work. Useful for testing regression of bug #14341."""
+
+    def __init__(self, username, password):
+        xmlstream.Authenticator.__init__(self)
+        self.username = username
+        self.password = password
+        self.authenticated = False
+
+    def streamStarted(self, root=None):
+        if root:
+            self.xmlstream.sid = root.getAttribute('id')
+
+        self.xmlstream.sendHeader()
+
+        features = domish.Element((xmlstream.NS_STREAMS, 'features'))
+        mechanisms = features.addElement((NS_XMPP_SASL, 'mechanisms'))
+        mechanism = mechanisms.addElement('mechanism', content='DIGEST-MD5')
+        starttls = features.addElement((NS_XMPP_TLS, 'starttls'))
+        starttls.addElement('required')
+        self.xmlstream.send(features)
+
+        self.xmlstream.addOnetimeObserver("/starttls", self.auth)
+
+    def auth(self, auth):
+        proceed = domish.Element((NS_XMPP_TLS, 'proceed'))
+        self.xmlstream.send(proceed)
+
+        return; # auth blocks
+
+        self.xmlstream.reset()
+        self.authenticated = True
+
+
+def test(q, bus, conn1, conn2, stream1, stream2):
+    # Connection 1
+    conn1.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+
+    # Connection 1 blocks because the fake jabber server behind conn1 does not
+    # proceed to the tls handshake. The second connection is independant and
+    # should work.
+
+    # Connection 2
+    conn2.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+    q.expect('stream-authenticated')
+    q.expect('dbus-signal', signal='PresenceUpdate',
+        args=[{1L: (0L, {u'available': {}})}])
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+    # Disconnection 2
+    conn2.Disconnect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+    return True
+
+if __name__ == '__main__':
+    queue = servicetest.IteratingEventQueue(None)
+    queue.verbose = (
+        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
+        or '-v' in sys.argv)
+
+    bus = dbus.SessionBus()
+
+    params = {
+        'account': 'test1 at localhost/Resource',
+        'password': 'pass',
+        'resource': 'Resource',
+        'server': 'localhost',
+        'port': dbus.UInt32(4242),
+        }
+    conn1 = make_connection(bus, queue.append, params)
+    authenticator = BlockForeverTlsAuthenticator('test1', 'pass')
+    stream1 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
+                          port=4242)
+
+    params = {
+        'account': 'test2 at localhost/Resource',
+        'password': 'pass',
+        'resource': 'Resource',
+        'server': 'localhost',
+        'port': dbus.UInt32(4343),
+        }
+    conn2 = make_connection(bus, queue.append, params)
+    authenticator = XmppAuthenticator('test2', 'pass')
+    stream2 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
+                          port=4343)
+
+    try:
+        test(queue, bus, conn1, conn2, stream1, stream2)
+    finally:
+        try:
+            conn1.Disconnect()
+            conn2.Disconnect()
+            # second call destroys object
+            conn1.Disconnect()
+            conn2.Disconnect()
+        except dbus.DBusException, e:
+            pass
+
diff --git a/tests/twisted/connect/test-success.py b/tests/twisted/connect/test-success.py
new file mode 100644
index 0000000..1ab1d2e
--- /dev/null
+++ b/tests/twisted/connect/test-success.py
@@ -0,0 +1,21 @@
+
+"""
+Test connecting to a server.
+"""
+
+from gabbletest import exec_test
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+    q.expect('stream-authenticated')
+    q.expect('dbus-signal', signal='PresenceUpdate',
+        args=[{1L: (0L, {u'available': {}})}])
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+    conn.Disconnect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+    return True
+
+if __name__ == '__main__':
+    exec_test(test)
+
diff --git a/tests/twisted/connect/test-twice.py b/tests/twisted/connect/test-twice.py
new file mode 100644
index 0000000..731f8c1
--- /dev/null
+++ b/tests/twisted/connect/test-twice.py
@@ -0,0 +1,90 @@
+
+"""
+Test connecting to a server with 2 accounts, testing XmppAuthenticator and
+JabberAuthenticator
+"""
+
+import os
+import sys
+import dbus
+import servicetest
+
+import twisted
+from twisted.words.xish import domish, xpath
+from twisted.words.protocols.jabber import xmlstream
+
+from gabbletest import make_connection, make_stream, JabberAuthenticator, \
+                       XmppAuthenticator, \
+                       XmppXmlStream, JabberXmlStream
+
+def test(q, bus, conn1, conn2, stream1, stream2):
+    # Connection 1
+    conn1.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+    q.expect('stream-authenticated')
+    q.expect('dbus-signal', signal='PresenceUpdate',
+        args=[{1L: (0L, {u'available': {}})}])
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+    # Connection 2
+    conn2.Connect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
+    q.expect('stream-authenticated')
+    q.expect('dbus-signal', signal='PresenceUpdate',
+        args=[{1L: (0L, {u'available': {}})}])
+    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+    # Disconnection 1
+    conn1.Disconnect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+    # Disconnection 2
+    conn2.Disconnect()
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+    return True
+
+if __name__ == '__main__':
+    queue = servicetest.IteratingEventQueue(None)
+    queue.verbose = (
+        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
+        or '-v' in sys.argv)
+
+    bus = dbus.SessionBus()
+
+    params = {
+        'account': 'test1 at localhost/Resource',
+        'password': 'pass',
+        'resource': 'Resource',
+        'server': 'localhost',
+        'port': dbus.UInt32(4242),
+        }
+    conn1 = make_connection(bus, queue.append, params)
+    authenticator = JabberAuthenticator('test1', 'pass')
+    stream1 = make_stream(queue.append, authenticator, protocol=JabberXmlStream,
+                          port=4242)
+
+    params = {
+        'account': 'test2 at localhost/Resource',
+        'password': 'pass',
+        'resource': 'Resource',
+        'server': 'localhost',
+        'port': dbus.UInt32(4343),
+        }
+    conn2 = make_connection(bus, queue.append, params)
+    authenticator = XmppAuthenticator('test2', 'pass')
+    stream2 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
+                          port=4343)
+
+    try:
+        test(queue, bus, conn1, conn2, stream1, stream2)
+    finally:
+        try:
+            conn1.Disconnect()
+            conn2.Disconnect()
+            # second call destroys object
+            conn1.Disconnect()
+            conn2.Disconnect()
+        except dbus.DBusException, e:
+            pass
+
diff --git a/tests/twisted/test-connect-fail.py b/tests/twisted/test-connect-fail.py
deleted file mode 100644
index a7c5e3e..0000000
--- a/tests/twisted/test-connect-fail.py
+++ /dev/null
@@ -1,17 +0,0 @@
-
-"""
-Test network error handling.
-"""
-
-import dbus
-
-from gabbletest import exec_test
-
-def test(q, bus, conn, stream):
-    conn.Connect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])
-
-if __name__ == '__main__':
-    exec_test(test, {'port': dbus.UInt32(4243)})
-
diff --git a/tests/twisted/test-connect-twice.py b/tests/twisted/test-connect-twice.py
deleted file mode 100644
index 4b6289a..0000000
--- a/tests/twisted/test-connect-twice.py
+++ /dev/null
@@ -1,133 +0,0 @@
-
-"""
-Test connecting to a server with 2 accounts. Check one account does not block
-the second account.
-"""
-
-import os
-import sys
-import dbus
-import servicetest
-
-import twisted
-from twisted.words.xish import domish, xpath
-from twisted.words.protocols.jabber import xmlstream
-
-from gabbletest import make_connection, make_stream, JabberAuthenticator, \
-                       XmppAuthenticator, \
-                       XmppXmlStream, JabberXmlStream
-
-NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls'
-NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
-
-
-print "FIXME: test-connect-twice.py disabled due to a bug in Loudmouth:"
-print "       http://developer.imendio.com/issues/browse/LM-44"
-print "       https://bugs.freedesktop.org/show_bug.cgi?id=14341"
-# exiting 77 causes automake to consider the test to have been skipped
-raise SystemExit(77)
-
-
-class BlockForeverTlsAuthenticator(xmlstream.Authenticator):
-    """A TLS stream authenticator that is deliberately broken. It sends
-    <proceed/> to the client but then do nothing, so the TLS handshake will
-    not work. Useful for testing regression of bug #14341."""
-
-    def __init__(self, username, password):
-        xmlstream.Authenticator.__init__(self)
-        self.username = username
-        self.password = password
-        self.authenticated = False
-
-    def streamStarted(self, root=None):
-        if root:
-            self.xmlstream.sid = root.getAttribute('id')
-
-        self.xmlstream.sendHeader()
-
-        features = domish.Element((xmlstream.NS_STREAMS, 'features'))
-        mechanisms = features.addElement((NS_XMPP_SASL, 'mechanisms'))
-        mechanism = mechanisms.addElement('mechanism', content='DIGEST-MD5')
-        starttls = features.addElement((NS_XMPP_TLS, 'starttls'))
-        starttls.addElement('required')
-        self.xmlstream.send(features)
-
-        self.xmlstream.addOnetimeObserver("/starttls", self.auth)
-
-    def auth(self, auth):
-        proceed = domish.Element((NS_XMPP_TLS, 'proceed'))
-        self.xmlstream.send(proceed)
-
-        return; # auth blocks
-
-        self.xmlstream.reset()
-        self.authenticated = True
-
-
-def test(q, bus, conn1, conn2, stream1, stream2):
-    # Connection 1
-    conn1.Connect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
-
-    # Connection 1 blocks because the fake jabber server behind conn1 does not
-    # proceed to the tls handshake. The second connection is independant and
-    # should work.
-
-    # Connection 2
-    conn2.Connect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
-    q.expect('stream-authenticated')
-    q.expect('dbus-signal', signal='PresenceUpdate',
-        args=[{1L: (0L, {u'available': {}})}])
-    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
-
-    # Disconnection 2
-    conn2.Disconnect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-    return True
-
-if __name__ == '__main__':
-    queue = servicetest.IteratingEventQueue(None)
-    queue.verbose = (
-        os.environ.get('CHECK_TWISTED_VERBOSE', '') != ''
-        or '-v' in sys.argv)
-
-    bus = dbus.SessionBus()
-
-    params = {
-        'account': 'test1 at localhost/Resource',
-        'password': 'pass',
-        'resource': 'Resource',
-        'server': 'localhost',
-        'port': dbus.UInt32(4242),
-        }
-    conn1 = make_connection(bus, queue.append, params)
-    authenticator = BlockForeverTlsAuthenticator('test1', 'pass')
-    stream1 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
-                          port=4242)
-
-    params = {
-        'account': 'test2 at localhost/Resource',
-        'password': 'pass',
-        'resource': 'Resource',
-        'server': 'localhost',
-        'port': dbus.UInt32(4343),
-        }
-    conn2 = make_connection(bus, queue.append, params)
-    authenticator = XmppAuthenticator('test2', 'pass')
-    stream2 = make_stream(queue.append, authenticator, protocol=XmppXmlStream,
-                          port=4343)
-
-    try:
-        test(queue, bus, conn1, conn2, stream1, stream2)
-    finally:
-        try:
-            conn1.Disconnect()
-            conn2.Disconnect()
-            # second call destroys object
-            conn1.Disconnect()
-            conn2.Disconnect()
-        except dbus.DBusException, e:
-            pass
-
diff --git a/tests/twisted/test-connect.py b/tests/twisted/test-connect.py
deleted file mode 100644
index 1ab1d2e..0000000
--- a/tests/twisted/test-connect.py
+++ /dev/null
@@ -1,21 +0,0 @@
-
-"""
-Test connecting to a server.
-"""
-
-from gabbletest import exec_test
-
-def test(q, bus, conn, stream):
-    conn.Connect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
-    q.expect('stream-authenticated')
-    q.expect('dbus-signal', signal='PresenceUpdate',
-        args=[{1L: (0L, {u'available': {}})}])
-    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
-    conn.Disconnect()
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-    return True
-
-if __name__ == '__main__':
-    exec_test(test)
-
-- 
1.5.6.3




More information about the Telepathy-commits mailing list