[Telepathy-commits] [telepathy-gabble/master] Twisted tests: add TlsAuthenticator that blocks after the <proceed/>
Alban Crequy
alban.crequy at collabora.co.uk
Tue Aug 19 10:52:53 PDT 2008
20080603151738-a41c0-02ed1e8a9b5feb8f74371bc451b9ab306454ac8b.gz
---
tests/twisted/gabbletest.py | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index d727e57..efce71a 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -19,6 +19,7 @@ import dbus
NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
NS_XMPP_BIND = 'urn:ietf:params:xml:ns:xmpp-bind'
+NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls'
def make_result_iq(stream, iq):
result = IQ(stream, "result")
@@ -85,6 +86,40 @@ class JabberAuthenticator(xmlstream.Authenticator):
self.xmlstream.send(result)
self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)
+class TlsAuthenticator(xmlstream.Authenticator):
+ "Tls stream authenticator that blocks after the <proceed/>."
+
+ 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
+
+
class XmppAuthenticator(xmlstream.Authenticator):
def __init__(self, username, password):
xmlstream.Authenticator.__init__(self)
--
1.5.6.3
More information about the Telepathy-commits
mailing list