incubator-heraldry-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=493393
Log:
[python-to-heraldry @ Add allowable slop to checking of expires_in field]
The test was failing occasionally because it was being run on the edge
of a second, so it can be off by up to one second.

Original author: Josh Hoyt <josh@janrain.com>
Date: 2006-12-27 23:23:01+00:00

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

Modified: incubator/heraldry/libraries/python/openid/trunk/openid/test/test_server.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/trunk/openid/test/test_server.py?view=diff&rev=493393&r1=493392&r2=493393
==============================================================================
--- incubator/heraldry/libraries/python/openid/trunk/openid/test/test_server.py (original)
+++ incubator/heraldry/libraries/python/openid/trunk/openid/test/test_server.py Fri Jan  5
21:27:27 2007
@@ -3,7 +3,7 @@
 from openid.server import server
 from openid import association, cryptutil, oidutil
 from openid.message import Message, OPENID_NS, OPENID2_NS, OPENID1_NS, \
-     IDENTIFIER_SELECT
+     IDENTIFIER_SELECT, no_default
 import _memstore
 import cgi
 
@@ -911,6 +911,20 @@
         self.failUnlessEqual(reply.getArg(OPENID_NS, 'reference'), reference)
         self.failUnlessEqual(reply.getArg(OPENID_NS, 'contact'), contact)
 
+    def failUnlessExpiresInMatches(self, msg, expected_expires_in):
+        expires_in_str = msg.getArg(OPENID_NS, 'expires_in', no_default)
+        expires_in = int(expires_in_str)
+
+        # Slop is necessary because the tests can sometimes get run
+        # right on a second boundary
+        slop = 1 # second
+        difference = expected_expires_in - expires_in
+
+        error_message = ('"expires_in" value not within %s of expected: '
+                         'expected=%s, actual=%s' %
+                         (slop, expected_expires_in, expires_in))
+        self.failUnless(0 <= difference <= slop, error_message)
+
     def test_plaintext(self):
         self.assoc = self.signatory.createAssociation(dumb=False, assoc_type='HMAC-SHA1')
         response = self.request.answer(self.assoc)
@@ -919,8 +933,9 @@
         self.failUnlessEqual(rfg("assoc_type"), "HMAC-SHA1")
         self.failUnlessEqual(rfg("assoc_handle"), self.assoc.handle)
 
-        self.failUnlessEqual(
-            rfg("expires_in"), "%d" % (self.signatory.SECRET_LIFETIME,))
+        self.failUnlessExpiresInMatches(
+            response.fields, self.signatory.SECRET_LIFETIME)
+
         self.failUnlessEqual(
             rfg("mac_key"), oidutil.toBase64(self.assoc.secret))
         self.failIf(rfg("session_type"))
@@ -935,8 +950,9 @@
         self.failUnlessEqual(rfg("assoc_type"), "HMAC-SHA1")
         self.failUnlessEqual(rfg("assoc_handle"), self.assoc.handle)
 
-        self.failUnlessEqual(
-            rfg("expires_in"), "%d" % (self.signatory.SECRET_LIFETIME,))
+        self.failUnlessExpiresInMatches(
+            response.fields, self.signatory.SECRET_LIFETIME)
+
         self.failUnlessEqual(
             rfg("mac_key"), oidutil.toBase64(self.assoc.secret))
         self.failIf(rfg("session_type"))



Mime
View raw message