Back to index

plone3  3.1.7
testAuthentication.py
Go to the documentation of this file.
00001 from plone.openid.tests.oitestcase import FunctionalOpenIdTestCase
00002 from zExceptions import Redirect
00003 
00004 
00005 class TestOpenIdAuthentication(FunctionalOpenIdTestCase):
00006 
00007     def buildServerResponse(self):
00008         credentials={}
00009         for field in [ "nonce", "openid.assoc_handle", "openid.return_to",
00010                         "openid.signed", "openid.sig",
00011                         "openid.invalidate_handle", "openid.mode"]:
00012             credentials[field]=field
00013         credentials["openid.identity"]=self.identity
00014         credentials["openid.source"]="server"
00015         
00016         # this isn't part of the server response, but is added to the
00017         # credentials by PAS
00018         credentials["extractor"] = "openid"
00019 
00020         return credentials
00021 
00022 
00023     def testEmptyAuthentication(self):
00024         """Test if we do not invent an identity out of thin air.
00025         """
00026         creds=self.folder.pas.openid.authenticateCredentials({})
00027         self.assertEqual(creds, None)
00028 
00029     def testEmptyStringIdentityAuthentication(self):
00030         """Test coverage for bug #7176, where an 
00031            "" (i.e. an empty string) identity passed to 
00032            authenticationCredentials should return fail authentication
00033         """
00034         credentials=self.buildServerResponse()
00035         credentials["openid.identity"]=""
00036         creds=self.folder.pas.openid.authenticateCredentials(credentials)
00037         self.assertEqual(creds, None)
00038 
00039     def testUnknownOpenIdSource(self):
00040         """Test if an incorrect source does not produce unexpected exceptions.
00041         """
00042         creds=self.folder.pas.openid.authenticateCredentials({"openid.source" : "x"})
00043         self.assertEqual(creds, None)
00044 
00045 
00046     def testServerAuthentication(self):
00047         """Test authentication of OpenID server responses.
00048         """
00049         credentials=self.buildServerResponse()
00050         creds=self.folder.pas.openid.authenticateCredentials(credentials)
00051         self.assertEqual(creds, (self.identity, self.identity))
00052 
00053 
00054     def testIncompleteServerAuthentication(self):
00055         """Test authentication of OpenID server responses.
00056         """
00057         credentials=self.buildServerResponse()
00058         del credentials["openid.sig"]
00059         creds=self.folder.pas.openid.authenticateCredentials(credentials)
00060         self.assertEqual(creds, None)
00061 
00062 
00063 def test_suite():
00064     from unittest import TestSuite, makeSuite
00065     suite=TestSuite()
00066     suite.addTest(makeSuite(TestOpenIdAuthentication))
00067     return suite