Back to index

plone3  3.1.7
consumer.py
Go to the documentation of this file.
00001 
00002 from openid.consumer.consumer import FAILURE, SUCCESS
00003 
00004 class MockAuthRequest:
00005     """Amock OpenID AuthRequest.
00006     """
00007     def __init__(self, status=None, identity_url=None, message=None):
00008         self.status=status
00009         self.identity_url=identity_url
00010         self.message=message
00011 
00012 
00013     def redirectURL(self, trust_root, return_to):
00014         return return_to
00015 
00016 
00017 class MockConsumer:
00018     """A mock OpenID consumerclass.
00019     """
00020 
00021     def begin(self, identity):
00022         self.identity=identity
00023         return MockAuthRequest()
00024 
00025     def complete(self, credentials, current_url):
00026         status=SUCCESS
00027         message="authentication completed succesfully"
00028         
00029         if credentials.has_key("openid.identity") and credentials["openid.identity"] == "":
00030             # if the python openid is passed an identity of an empty string
00031             # an IndexError is raised in the depths of its XRI identification
00032             # see: http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xri
00033 
00034             # an empty string is common when the submit button of the
00035             # openid login is clicked prior to providing an identity url
00036             # we simulate openid's response here in our mock object
00037             message="invalid identity"
00038             status=FAILURE
00039         else:
00040             for field in [ "openid.source", "nonce", "openid.identity",
00041                     "openid.assoc_handle", "openid.return_to", "openid.signed",
00042                     "openid.sig", "openid.invalidate_handle", "openid.mode"]:
00043                 if field not in credentials:
00044                     message="field missing"
00045                     status=FAILURE
00046                 
00047 
00048         return MockAuthRequest(status=status,
00049                                 message=message,
00050                                 identity_url=credentials["openid.identity"])
00051 
00052 def PatchPlugin(plugin):
00053     def getConsumer(self):
00054         return MockConsumer()
00055 
00056     plugin.getConsumer=getConsumer
00057