incubator-heraldry-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=493389
Log:
[python-to-heraldry @ Add SHA1/256 association session response tests for OpenID 1/2]

Original author: cygnus@janrain.com
Date: 2006-12-27 20:51:46+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=493389&r1=493388&r2=493389
==============================================================================
--- 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:07 2007
@@ -1,6 +1,7 @@
 import urlparse
 import cgi
 import time
+import warnings
 
 from openid.message import Message, OPENID_NS, OPENID2_NS, IDENTIFIER_SELECT, \
      OPENID1_NS
@@ -12,7 +13,7 @@
      AuthRequest, GenericConsumer, SUCCESS, FAILURE, CANCEL, SETUP_NEEDED, \
      SuccessResponse, FailureResponse, SetupNeededResponse, CancelResponse, \
      DiffieHellmanSHA1ConsumerSession, Consumer, PlainTextConsumerSession, \
-     SetupNeededError
+     SetupNeededError, DiffieHellmanSHA256ConsumerSession
 from openid import association
 from openid.server.server import \
      PlainTextServerSession, DiffieHellmanSHA1ServerSession
@@ -1412,5 +1413,73 @@
         self.failUnlessEqual(expected, args)
 
     # XXX: test the other types
+
+class TestDiffieHellmanResponseParameters(object):
+    session_cls = None
+    message_namespace = None
+
+    def setUp(self):
+        # Pre-compute DH with small prime so tests run quickly.
+        self.server_dh = DiffieHellman(100389557, 2)
+        self.consumer_dh = DiffieHellman(100389557, 2)
+
+        # base64(btwoc(g ^ xb mod p))
+        self.dh_server_public = cryptutil.longToBase64(self.server_dh.public)
+
+        self.secret = cryptutil.randomString(self.session_cls.secret_size)
+
+        self.enc_mac_key = oidutil.toBase64(
+            self.server_dh.xorSecret(self.consumer_dh.public,
+                                     self.secret,
+                                     self.session_cls.hash_func))
+
+        self.consumer_session = self.session_cls(self.consumer_dh)
+
+        self.msg = Message(self.message_namespace)
+
+    def testExtractSecret(self):
+        self.msg.setArg(OPENID_NS, 'dh_server_public', self.dh_server_public)
+        self.msg.setArg(OPENID_NS, 'enc_mac_key', self.enc_mac_key)
+
+        extracted = self.consumer_session.extractSecret(self.msg)
+        self.failUnlessEqual(extracted, self.secret)
+
+    def testAbsentServerPublic(self):
+        self.msg.setArg(OPENID_NS, 'enc_mac_key', self.enc_mac_key)
+
+        self.failUnlessRaises(KeyError, self.consumer_session.extractSecret, self.msg)
+
+    def testAbsentMacKey(self):
+        self.msg.setArg(OPENID_NS, 'dh_server_public', self.dh_server_public)
+
+        self.failUnlessRaises(KeyError, self.consumer_session.extractSecret, self.msg)
+
+    def testInvalidBase64Public(self):
+        self.msg.setArg(OPENID_NS, 'dh_server_public', 'n o t b a s e 6 4.')
+        self.msg.setArg(OPENID_NS, 'enc_mac_key', self.enc_mac_key)
+
+        self.failUnlessRaises(ValueError, self.consumer_session.extractSecret, self.msg)
+
+    def testInvalidBase64MacKey(self):
+        self.msg.setArg(OPENID_NS, 'dh_server_public', self.dh_server_public)
+        self.msg.setArg(OPENID_NS, 'enc_mac_key', 'n o t base 64')
+
+        self.failUnlessRaises(ValueError, self.consumer_session.extractSecret, self.msg)
+
+class TestOpenID1SHA1(TestDiffieHellmanResponseParameters, unittest.TestCase):
+    session_cls = DiffieHellmanSHA1ConsumerSession
+    message_namespace = OPENID1_NS
+
+class TestOpenID2SHA1(TestDiffieHellmanResponseParameters, unittest.TestCase):
+    session_cls = DiffieHellmanSHA1ConsumerSession
+    message_namespace = OPENID2_NS
+
+if cryptutil.SHA256_AVAILABLE:
+    class TestOpenID2SHA256(TestDiffieHellmanResponseParameters, unittest.TestCase):
+        session_cls = DiffieHellmanSHA256ConsumerSession
+        message_namespace = OPENID2_NS
+else:
+    warnings.warn("Not running SHA256 association session tests.")
+
 if __name__ == '__main__':
     unittest.main()



Mime
View raw message