[Telepathy-commits] [telepathy-idle/master] Add support for testing ssl connections with twisted tests
Jonathon Jongsma
jonathon.jongsma at collabora.co.uk
Fri Feb 13 17:43:14 PST 2009
Added a couple ssl connection tests that are just variations of the non-ssl
connection tests and really only serve to excercise the IdleSSLServerConnection
class a bit.
Added a testing-only ssl cert / key just so we're able to start a ssl irc test
server and test connections to it.
---
tests/twisted/Makefile.am | 2 ++
tests/twisted/connect/connect-fail-ssl.py | 16 ++++++++++++++++
tests/twisted/connect/connect-success-ssl.py | 22 ++++++++++++++++++++++
tests/twisted/idletest.py | 13 +++++++++++--
tests/twisted/tools/idletest.cert | 10 ++++++++++
tests/twisted/tools/idletest.key | 9 +++++++++
tests/twisted/tools/tmp-session-bus.conf.in | 8 ++------
7 files changed, 72 insertions(+), 8 deletions(-)
create mode 100644 tests/twisted/connect/connect-fail-ssl.py
create mode 100644 tests/twisted/connect/connect-success-ssl.py
create mode 100644 tests/twisted/tools/idletest.cert
create mode 100644 tests/twisted/tools/idletest.key
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 502f89b..5180cf5 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -1,6 +1,8 @@
TWISTED_TESTS = \
connect/connect-fail.py \
+ connect/connect-fail-ssl.py \
connect/connect-success.py \
+ connect/connect-success-ssl.py \
$(NULL)
TESTS =
diff --git a/tests/twisted/connect/connect-fail-ssl.py b/tests/twisted/connect/connect-fail-ssl.py
new file mode 100644
index 0000000..14d1ae9
--- /dev/null
+++ b/tests/twisted/connect/connect-fail-ssl.py
@@ -0,0 +1,16 @@
+
+"""
+Test Network error Handling with SSL servers
+"""
+
+import dbus
+from idletest import exec_test, SSLIRCServer
+
+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(5600), 'use-ssl': dbus.Boolean(True)}, protocol=SSLIRCServer)
+
diff --git a/tests/twisted/connect/connect-success-ssl.py b/tests/twisted/connect/connect-success-ssl.py
new file mode 100644
index 0000000..12367e5
--- /dev/null
+++ b/tests/twisted/connect/connect-success-ssl.py
@@ -0,0 +1,22 @@
+
+"""
+Test connecting to a SSL server.
+"""
+
+import dbus
+from idletest import exec_test, SSLIRCServer
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect_racy('dbus-signal', signal='StatusChanged', args=[1, 1])
+ q.expect_racy('irc-connected')
+ q.expect('dbus-signal', signal='SelfHandleChanged',
+ args=[1L])
+ 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, {'use-ssl':dbus.Boolean(True)}, protocol=SSLIRCServer, timeout=10)
+
diff --git a/tests/twisted/idletest.py b/tests/twisted/idletest.py
index be42580..74a368a 100644
--- a/tests/twisted/idletest.py
+++ b/tests/twisted/idletest.py
@@ -9,7 +9,7 @@ import dbus
import servicetest
import twisted
from twisted.words.protocols import irc
-from twisted.internet import reactor
+from twisted.internet import reactor, ssl
def make_irc_event(type, data):
event = servicetest.Event(type, data=data)
@@ -32,6 +32,9 @@ class BaseIRCServer(irc.IRC):
self.passwd = None
self.require_pass = False
+ def listen(self, port, factory):
+ return reactor.listenTCP(port, factory)
+
def connectionMade(self):
print ("connection Made")
self.event_func(make_connected_event())
@@ -62,6 +65,12 @@ class BaseIRCServer(irc.IRC):
def sendWelcome(self):
self.sendMessage('001', self.nick, ':Welcome to the test IRC Network', prefix='idle.test.server')
+class SSLIRCServer(BaseIRCServer):
+ def listen(self, port, factory):
+ return reactor.listenSSL(port, factory,
+ ssl.DefaultOpenSSLContextFactory("tools/idletest.key",
+ "tools/idletest.cert"))
+
def install_colourer():
def red(s):
return '\x1b[31m%s\x1b[0m' % s
@@ -95,7 +104,7 @@ def start_server(event_func, protocol=None, port=6900):
server = protocol(event_func)
factory = twisted.internet.protocol.Factory()
factory.protocol = lambda *args: server
- port = reactor.listenTCP(port, factory)
+ port = server.listen(port, factory)
return (server, port)
def make_connection(bus, event_func, params=None):
diff --git a/tests/twisted/tools/idletest.cert b/tests/twisted/tools/idletest.cert
new file mode 100644
index 0000000..655abc2
--- /dev/null
+++ b/tests/twisted/tools/idletest.cert
@@ -0,0 +1,10 @@
+-----BEGIN CERTIFICATE-----
+MIIBTzCB+gIBATANBgkqhkiG9w0BAQQFADAzMRIwEAYDVQQKEwl0ZWxlcGF0aHkx
+HTAbBgNVBAsTFHRlbGVwYXRoeSBkZXZlbG9wZXJzMB4XDTA5MDExNDE3NDc0N1oX
+DTA5MDExNDE3NDg0N1owMzESMBAGA1UEChMJdGVsZXBhdGh5MR0wGwYDVQQLExR0
+ZWxlcGF0aHkgZGV2ZWxvcGVyczBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC9z/pi
+zEMeL+bO3giJVGHGrOHLE7AfDorArwmA0u8Cgu06+J+SW+NJnkj8At4bioxREge6
+yeD6+cHCC9kzXrmXAgMBAAEwDQYJKoZIhvcNAQEEBQADQQBf1qg0gzSztx5pqqM8
+3wI5cEc7k13EzU6X2SkSCSxlMc4pF0hPdr0LuZJpeKBohIgKQ59+3Ny0LuUMEKYW
+ikGr
+-----END CERTIFICATE-----
diff --git a/tests/twisted/tools/idletest.key b/tests/twisted/tools/idletest.key
new file mode 100644
index 0000000..3a80dab
--- /dev/null
+++ b/tests/twisted/tools/idletest.key
@@ -0,0 +1,9 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIBOwIBAAJBAL3P+mLMQx4v5s7eCIlUYcas4csTsB8OisCvCYDS7wKC7Tr4n5Jb
+40meSPwC3huKjFESB7rJ4Pr5wcIL2TNeuZcCAwEAAQJBAJLaJc3qWsMwLFJAVjpp
+nnwnpUmIoeplRdRtl9yjVWeKrvD2gSh2Qz693dgJbDUGURJecJ+LSS4YMOS+8FLp
+KgECIQDhgvqh9KahKphn2/vvcCx3DKBZ7wh9lYIaaAay6IuAhwIhANd5cF48u0ID
+39kZCwfhpAKQDxvpqmbnRzB0hISjEpJxAiARfZIo24vM9jvJ2mMI6B9awGzzbLmw
+29aya50RZT3kowIhALrT2NJc5iB/K4AZbq8Ovh5auj8Bg3Zl4hvpa11154yBAiAO
+F+44Mb+YQi+r526cDv983vCuoU5EM0PbPvJxaWmwtQ==
+-----END RSA PRIVATE KEY-----
diff --git a/tests/twisted/tools/tmp-session-bus.conf.in b/tests/twisted/tools/tmp-session-bus.conf.in
index 84d8d65..39ce98e 100644
--- a/tests/twisted/tools/tmp-session-bus.conf.in
+++ b/tests/twisted/tools/tmp-session-bus.conf.in
@@ -1,5 +1,5 @@
<!-- This configuration file controls the per-user-login-session message bus.
- Add a session-local.conf and edit that rather than changing this
+ Add a session-local.conf and edit that rather than changing this
file directly. -->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
@@ -21,10 +21,6 @@
<allow own="*"/>
</policy>
- <!-- This is included last so local configuration can override what's
+ <!-- This is included last so local configuration can override what's
in this standard file -->
-
-
-
-
</busconfig>
--
1.5.6.5
More information about the telepathy-commits
mailing list