telepathy-gabble: tests: share more code between XmppAuthenticator subclasses

Will Thompson wjt at kemper.freedesktop.org
Thu Dec 6 04:29:03 PST 2012


Module: telepathy-gabble
Branch: master
Commit: aae6367f43cf9fd509571e52ea87c7bee5d6124f
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=aae6367f43cf9fd509571e52ea87c7bee5d6124f

Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Nov 23 15:51:11 2012 +0000

tests: share more code between XmppAuthenticator subclasses

---

 tests/twisted/gabbletest.py             |    5 ++++-
 tests/twisted/sasl/saslutil.py          |   31 +++++--------------------------
 tests/twisted/tls/server-tls-channel.py |    2 --
 3 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index c0d4ae7..e83fdbd 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -188,6 +188,8 @@ class XmppAuthenticator(GabbleAuthenticator):
         GabbleAuthenticator.__init__(self, username, password, resource)
         self.authenticated = False
 
+        self._mechanisms = ['PLAIN']
+
     def streamInitialize(self, root):
         if root:
             self.xmlstream.sid = root.getAttribute('id')
@@ -212,7 +214,8 @@ class XmppAuthenticator(GabbleAuthenticator):
     def streamSASL(self):
         features = domish.Element((xmlstream.NS_STREAMS, 'features'))
         mechanisms = features.addElement((ns.NS_XMPP_SASL, 'mechanisms'))
-        mechanism = mechanisms.addElement('mechanism', content='PLAIN')
+        for mechanism in self._mechanisms:
+            mechanisms.addElement('mechanism', content=mechanism)
         self.xmlstream.send(features)
 
         self.xmlstream.addOnetimeObserver("/auth", self.auth)
diff --git a/tests/twisted/sasl/saslutil.py b/tests/twisted/sasl/saslutil.py
index 5ad7872..7d14614 100644
--- a/tests/twisted/sasl/saslutil.py
+++ b/tests/twisted/sasl/saslutil.py
@@ -1,5 +1,4 @@
 # hey, Python: encoding: utf-8
-from twisted.words.protocols.jabber.xmlstream import NS_STREAMS
 from gabbletest import XmppAuthenticator
 from base64 import b64decode, b64encode
 from twisted.words.xish import domish
@@ -19,31 +18,11 @@ class SaslEventAuthenticator(XmppAuthenticator):
         XmppAuthenticator.__init__(self, jid, '')
         self._mechanisms = mechanisms
 
-    def streamStarted(self, root=None):
-        if root:
-            self.xmlstream.sid = root.getAttribute('id')
+    def streamSASL(self):
+        XmppAuthenticator.streamSASL(self)
 
-        self.xmlstream.sendHeader()
-
-        if self.authenticated:
-            # Initiator authenticated itself, and has started a new stream.
-
-            features = domish.Element((NS_STREAMS, 'features'))
-            bind = features.addElement((ns.NS_XMPP_BIND, 'bind'))
-            self.xmlstream.send(features)
-
-            self.xmlstream.addOnetimeObserver(
-                "/iq/bind[@xmlns='%s']" % ns.NS_XMPP_BIND, self.bindIq)
-        else:
-            features = domish.Element((NS_STREAMS, 'features'))
-            mechanisms = features.addElement((ns.NS_XMPP_SASL, 'mechanisms'))
-            for mechanism in self._mechanisms:
-                mechanisms.addElement('mechanism', content=mechanism)
-            self.xmlstream.send(features)
-
-            self.xmlstream.addOnetimeObserver("/auth", self._auth)
-            self.xmlstream.addObserver("/response", self._response)
-            self.xmlstream.addObserver("/abort", self._abort)
+        self.xmlstream.addObserver("/response", self._response)
+        self.xmlstream.addObserver("/abort", self._abort)
 
     def failure(self, fail_str):
         reply = domish.Element((ns.NS_XMPP_SASL, 'failure'))
@@ -72,7 +51,7 @@ class SaslEventAuthenticator(XmppAuthenticator):
         reply.addContent(b64encode(data))
         self.xmlstream.send(reply)
 
-    def _auth(self, auth):
+    def auth(self, auth):
         # Special case in XMPP: '=' means a zero-byte blob, whereas an empty
         # or self-terminating XML element means no initial response.
         # (RFC 3920 §6.2 (3))
diff --git a/tests/twisted/tls/server-tls-channel.py b/tests/twisted/tls/server-tls-channel.py
index 7823eac..3007d20 100644
--- a/tests/twisted/tls/server-tls-channel.py
+++ b/tests/twisted/tls/server-tls-channel.py
@@ -47,8 +47,6 @@ class TlsAuthenticator(XmppAuthenticator):
         starttls = features.addElement((ns.NS_XMPP_TLS, 'starttls'))
         starttls.addElement('required')
 
-        mechanisms = features.addElement((ns.NS_XMPP_SASL, 'mechanisms'))
-        mechanism = mechanisms.addElement('mechanism', content='PLAIN')
         self.xmlstream.send(features)
 
         self.xmlstream.addOnetimeObserver("/starttls", self.tlsAuth)



More information about the telepathy-commits mailing list