incubator-heraldry-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=493400
Log:
[python-to-heraldry @ Add OpenID1-specific session negotiation tests]

Original author: cygnus@janrain.com
Date: 2006-12-28 00:12:59+00:00

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

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=493400&r1=493399&r2=493400
==============================================================================
--- 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:59 2007
@@ -1575,5 +1575,85 @@
         self.assertTrue(self.consumer._negotiateAssociation(self.endpoint) is assoc)
         self.failUnlessLogEmpty()
 
+class TestOpenID1SessionNegotiation(unittest.TestCase, CatchLogs):
+    def setUp(self):
+        CatchLogs.setUp(self)
+        self.consumer = ErrorRaisingConsumer(store=None)
+
+        self.endpoint = OpenIDServiceEndpoint()
+        self.endpoint.type_uris = [OPENID1_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)
+        self.failUnlessLogMatches('Server error when requesting an association')
+
+    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)
+
+        self.failUnlessLogMatches('Server error when requesting an association')
+
+    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)
+
+        self.failUnlessLogMatches('Server error when requesting an association')
+
+    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)
+
+        self.failUnlessLogMatches('Server error when requesting an association')
+
+    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 None)
+
+        self.failUnlessLogMatches('Server error when requesting an association')
+
+    def testValid(self):
+        assoc = association.Association(
+            'handle', 'secret', 'issued', 10000, 'HMAC-SHA1')
+
+        self.consumer.return_messages = [assoc]
+        self.assertTrue(self.consumer._negotiateAssociation(self.endpoint) is assoc)
+        self.failUnlessLogEmpty()
+
 if __name__ == '__main__':
     unittest.main()



Mime
View raw message