incubator-heraldry-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=493310
Log:
[python-to-heraldry @ FIX #1504: Add support for OpenID2-specific error response fields]

Original author: cygnus@janrain.com
Date: 2006-12-14 00:49:19+00:00

Modified:
    incubator/heraldry/libraries/python/openid/trunk/openid/consumer/consumer.py
    incubator/heraldry/libraries/python/openid/trunk/openid/server/server.py
    incubator/heraldry/libraries/python/openid/trunk/openid/test/test_consumer.py
    incubator/heraldry/libraries/python/openid/trunk/openid/test/test_server.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=493310&r1=493309&r2=493310
==============================================================================
--- 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:18:50 2007
@@ -445,7 +445,16 @@
             return CancelResponse(endpoint)
         elif mode == 'error':
             error = message.getArg(OPENID_NS, 'error')
-            return FailureResponse(endpoint, error)
+
+            contact = reference = None
+            # Only look at extra error response values if using OpenID
+            # 2.
+            if message.getOpenIDNamespace() == OPENID2_NS:
+                contact = message.getArg(OPENID_NS, 'contact')
+                reference = message.getArg(OPENID_NS, 'reference')
+
+            return FailureResponse(endpoint, error, contact=contact,
+                                   reference=reference)
         elif mode == 'id_res':
             try:
                 response = self._doIdRes(message, endpoint)
@@ -1016,9 +1025,12 @@
 
     status = FAILURE
 
-    def __init__(self, endpoint, message=None):
+    def __init__(self, endpoint, message=None, contact=None,
+                 reference=None):
         self.setEndpoint(endpoint)
         self.message = message
+        self.contact = contact
+        self.reference = reference
 
     def __repr__(self):
         return "<%s.%s id=%r message=%r>" % (

Modified: incubator/heraldry/libraries/python/openid/trunk/openid/server/server.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/trunk/openid/server/server.py?view=diff&rev=493310&r1=493309&r2=493310
==============================================================================
--- incubator/heraldry/libraries/python/openid/trunk/openid/server/server.py (original)
+++ incubator/heraldry/libraries/python/openid/trunk/openid/server/server.py Fri Jan  5 21:18:50
2007
@@ -1313,7 +1313,7 @@
     @type message: openid.message.Message
     """
 
-    def __init__(self, message, text=None):
+    def __init__(self, message, text=None, reference=None, contact=None):
         """When an error occurs.
 
         @param message: The message that is failing to be a valid
@@ -1324,6 +1324,8 @@
         @type text: str
         """
         self.openid_message = message
+        self.reference = reference
+        self.contact = contact
         assert type(message) not in [str, unicode]
         Exception.__init__(self, text)
 
@@ -1353,6 +1355,15 @@
         reply = Message(namespace)
         reply.setArg(OPENID_NS, 'mode', 'error')
         reply.setArg(OPENID_NS, 'error', str(self))
+
+        # Send contact and reference if using OpenID 2
+        if namespace == OPENID2_NS:
+            if self.contact is not None:
+                reply.setArg(OPENID_NS, 'contact', str(self.contact))
+
+            if self.reference is not None:
+                reply.setArg(OPENID_NS, 'reference', str(self.reference))
+
         return reply
 
     # implements IEncodable

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=493310&r1=493309&r2=493310
==============================================================================
--- 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:18:50 2007
@@ -347,6 +347,34 @@
         self.failUnless(r.identity_url == self.endpoint.identity_url)
         self.failUnlessEqual(r.message, msg)
 
+    def test_errorWithNoOptionalKeys(self):
+        msg = 'an error message'
+        message = Message.fromPostArgs({'openid.mode': 'error',
+                 'openid.error': msg, 'openid.reference': 'a ref',
+                 'openid.contact': 'some contact info here',
+                 })
+        r = self.consumer.complete(message, self.endpoint)
+        self.failUnlessEqual(r.status, FAILURE)
+        self.failUnless(r.identity_url == self.endpoint.identity_url)
+        self.failUnless(r.contact is None)
+        self.failUnless(r.reference is None)
+        self.failUnlessEqual(r.message, msg)
+
+    def test_errorWithOptionalKeys(self):
+        msg = 'an error message'
+        contact = 'me'
+        reference = 'support ticket'
+        message = Message.fromPostArgs({'openid.mode': 'error',
+                 'openid.error': msg, 'openid.reference': reference,
+                 'openid.contact': contact, 'openid.ns': OPENID2_NS,
+                 })
+        r = self.consumer.complete(message, self.endpoint)
+        self.failUnlessEqual(r.status, FAILURE)
+        self.failUnless(r.identity_url == self.endpoint.identity_url)
+        self.failUnless(r.contact == contact)
+        self.failUnless(r.reference == reference)
+        self.failUnlessEqual(r.message, msg)
+
     def test_noMode(self):
         message = Message.fromPostArgs({})
         r = self.consumer.complete(message, self.endpoint)

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=493310&r1=493309&r2=493310
==============================================================================
--- 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:18:50 2007
@@ -868,7 +868,7 @@
         invalid_s1_2 = {'openid.assoc_type':'ROBOT-NINJA',
                       'openid.session_type':'DH-SHA1',}
         invalid_s1_2.update(s1_session.getRequest())
-        
+
         bad_request_argss = [
             {'openid.assoc_type':'Wha?'},
             invalid_s1,
@@ -880,6 +880,39 @@
             self.failUnlessRaises(server.ProtocolError,
                                   server.AssociateRequest.fromMessage,
                                   message)
+
+    def test_protoErrorFields(self):
+
+        contact = 'user@example.invalid'
+        reference = 'Trac ticket number MAX_INT'
+        error = 'poltergeist'
+
+        openid1_args = {
+            'openid.identitiy': 'invalid',
+            'openid.mode': 'checkid_setup',
+            }
+
+        openid2_args = dict(openid1_args)
+        openid2_args.update({'openid.ns': OPENID2_NS})
+
+        openid1_msg = Message.fromPostArgs(openid1_args)
+        p = server.ProtocolError(openid1_msg, error,
+                                 contact=contact, reference=reference)
+        reply = p.toMessage()
+
+        # Should be None if the message is an openid1 message
+        self.failUnlessEqual(reply.getArg(OPENID_NS, 'reference'), None)
+        self.failUnlessEqual(reply.getArg(OPENID_NS, 'contact'), None)
+
+        openid2_msg = Message.fromPostArgs(openid2_args)
+        p = server.ProtocolError(openid2_msg, error,
+                                 contact=contact, reference=reference)
+        reply = p.toMessage()
+
+        # Should be present (in this case) if the message is an
+        # openid2 message
+        self.failUnlessEqual(reply.getArg(OPENID_NS, 'reference'), reference)
+        self.failUnlessEqual(reply.getArg(OPENID_NS, 'contact'), contact)
 
     def test_plaintext(self):
         self.assoc = self.signatory.createAssociation(dumb=False, assoc_type='HMAC-SHA1')



Mime
View raw message