incubator-heraldry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ket...@apache.org
Subject svn commit: r493395 - in /incubator/heraldry/libraries/python/openid/trunk/openid: consumer/consumer.py test/test_consumer.py
Date Sat, 06 Jan 2007 05:27:37 GMT
Author: keturn
Date: Fri Jan  5 21:27:37 2007
New Revision: 493395

URL: http://svn.apache.org/viewvc?view=rev&rev=493395
Log:
[python-to-heraldry @ Add consumer-side session negotiation tests, and consumer fixes]

Original author: cygnus@janrain.com
Date: 2006-12-27 23:36:45+00:00

Modified:
    incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py
    incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py

Modified: incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py?view=diff&rev=493395&r1=493394&r2=493395
==============================================================================
--- incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py (original)
+++ incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py Fri Jan 
5 21:27:37 2007
@@ -840,10 +840,11 @@
         except ServerError, why:
             # Any error message whose code is not 'unsupported-type'
             # should be considered a total failure.
-            if e.error_code != 'unsupported-type':
+            if why.error_code != 'unsupported-type' or \
+                   why.message.isOpenID1():
                 oidutil.log(
                     'Server error when requesting an association from %r: %s'
-                    % (endpoint.server_url, e.error_text))
+                    % (endpoint.server_url, why.error_text))
                 return None
 
             # The server didn't like the association/session type
@@ -880,6 +881,8 @@
                                 'type: session_type=%s, assoc_type=%s'
                                 % (session_type, assoc_type))
                     return None
+                else:
+                    return assoc
         else:
             return assoc
 

Modified: incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py?view=diff&rev=493395&r1=493394&r2=493395
==============================================================================
--- incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py (original)
+++ incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py Fri Jan
 5 21:27:37 2007
@@ -13,7 +13,7 @@
      AuthRequest, GenericConsumer, SUCCESS, FAILURE, CANCEL, SETUP_NEEDED, \
      SuccessResponse, FailureResponse, SetupNeededResponse, CancelResponse, \
      DiffieHellmanSHA1ConsumerSession, Consumer, PlainTextConsumerSession, \
-     SetupNeededError, DiffieHellmanSHA256ConsumerSession
+     SetupNeededError, DiffieHellmanSHA256ConsumerSession, ServerError
 from openid import association
 from openid.server.server import \
      PlainTextServerSession, DiffieHellmanSHA1ServerSession
@@ -1480,6 +1480,78 @@
         message_namespace = OPENID2_NS
 else:
     warnings.warn("Not running SHA256 association session tests.")
+
+class ErrorRaisingConsumer(GenericConsumer):
+    return_messages = []
+
+    def _requestAssociation(self, endpoint, assoc_type, session_type):
+        m = self.return_messages.pop(0)
+        if isinstance(m, Message):
+            raise ServerError(m)
+        else:
+            return m
+
+class TestOpenID2SessionNegotiation(unittest.TestCase):
+    def setUp(self):
+        self.consumer = ErrorRaisingConsumer(store=None)
+
+        self.endpoint = OpenIDServiceEndpoint()
+        self.endpoint.type_uris = [OPENID2_NS]
+        self.endpoint.server_url = 'bogus'
+
+    def testBadResponse(self):
+        self.consumer.return_messages = [Message(self.endpoint.preferredNamespace())]
+        self.assertEqual(self.consumer._negotiateAssociation(self.endpoint), None)
+
+    def testEmptyAssocType(self):
+        msg = Message(self.endpoint.preferredNamespace())
+        msg.setArg(OPENID_NS, 'error', 'Unsupported type')
+        msg.setArg(OPENID_NS, 'error_code', 'unsupported-type')
+        msg.setArg(OPENID_NS, 'assoc_type', None)
+        msg.setArg(OPENID_NS, 'session_type', 'new-session-type')
+
+        self.consumer.return_messages = [msg]
+        self.assertEqual(self.consumer._negotiateAssociation(self.endpoint), None)
+
+    def testEmptySessionType(self):
+        msg = Message(self.endpoint.preferredNamespace())
+        msg.setArg(OPENID_NS, 'error', 'Unsupported type')
+        msg.setArg(OPENID_NS, 'error_code', 'unsupported-type')
+        msg.setArg(OPENID_NS, 'assoc_type', 'new-assoc-type')
+        msg.setArg(OPENID_NS, 'session_type', None)
+
+        self.consumer.return_messages = [msg]
+        self.assertEqual(self.consumer._negotiateAssociation(self.endpoint), None)
+
+    def testNotAllowed(self):
+        allowed_types = [
+            ('assoc_bogus', 'session_bogus'),
+            ]
+
+        negotiator = association.SessionNegotiator(allowed_types)
+        self.consumer.negotiator = negotiator
+
+        msg = Message(self.endpoint.preferredNamespace())
+        msg.setArg(OPENID_NS, 'error', 'Unsupported type')
+        msg.setArg(OPENID_NS, 'error_code', 'unsupported-type')
+        msg.setArg(OPENID_NS, 'assoc_type', 'not-allowed')
+        msg.setArg(OPENID_NS, 'session_type', 'not-allowed')
+
+        self.consumer.return_messages = [msg]
+        self.assertEqual(self.consumer._negotiateAssociation(self.endpoint), None)
+
+    def testUnsupportedWithRetry(self):
+        msg = Message(self.endpoint.preferredNamespace())
+        msg.setArg(OPENID_NS, 'error', 'Unsupported type')
+        msg.setArg(OPENID_NS, 'error_code', 'unsupported-type')
+        msg.setArg(OPENID_NS, 'assoc_type', 'HMAC-SHA1')
+        msg.setArg(OPENID_NS, 'session_type', 'DH-SHA1')
+
+        assoc = association.Association(
+            'handle', 'secret', 'issued', 10000, 'HMAC-SHA1')
+
+        self.consumer.return_messages = [msg, assoc]
+        self.assertTrue(self.consumer._negotiateAssociation(self.endpoint) is assoc)
 
 if __name__ == '__main__':
     unittest.main()



Mime
View raw message