Back to index

plone3  3.1.7
testExtraction.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 TestOpenIdExtraction(FunctionalOpenIdTestCase):
00006 
00007     def testEmptyExtraction(self):
00008         """Test if we do not invent credentials out of thin air.
00009         """
00010         creds=self.folder.pas.openid.extractCredentials(self.app.REQUEST)
00011         self.assertEqual(creds, {})
00012 
00013     def testEmptyStringIdentityExtraction(self):
00014         """Test coverage for bug #7176. In the case where "" (i.e an empty
00015            string) is passed in as the identity via the request, 
00016            we essentially want to ensure that a Redirect isn't raised, which 
00017            would signify that an IOpenIdExtractionPlugin challenge was initialized.
00018            
00019            This test demonstrates our openid plugin's extractCredentials eliminates
00020            credentials that aren't in the openid.* namespace.
00021         """
00022         self.app.REQUEST.form.update(self.server_response)
00023         self.app.REQUEST.form["__ac_identity_url"]=""
00024         creds=self.folder.pas.openid.extractCredentials(self.app.REQUEST)
00025         self.failIf(creds.has_key("__ac_identity_url"))
00026         
00027 
00028     def testRedirect(self):
00029         """Test if a redirect is generated for a login attempt.
00030         This test requires a working internet connection!
00031         """
00032         self.app.REQUEST.form["__ac_identity_url"]=self.identity
00033         self.assertRaises(Redirect,
00034                 self.folder.pas.openid.extractCredentials,
00035                 self.app.REQUEST)
00036 
00037 
00038     def testPositiveOpenIdResponse(self):
00039         """Test if a positive authentication is extracted.
00040         """
00041         self.app.REQUEST.form.update(self.server_response)
00042         creds=self.folder.pas.openid.extractCredentials(self.app.REQUEST)
00043         self.assertEqual(creds["openid.identity"], self.identity)
00044         self.assertEqual(creds["openid.mode"], "id_res")
00045         self.assertEqual(creds["openid.return_to"], "return_to")
00046 
00047 
00048     def testNegativeOpenIdResponse(self):
00049         """Check if a cancelled authentication request is correctly ignored.
00050         """
00051         self.app.REQUEST.form.update(self.server_response)
00052         self.app.REQUEST.form["openid.mode"]="cancel"
00053         creds=self.folder.pas.openid.extractCredentials(self.app.REQUEST)
00054         self.assertEqual(creds, {})
00055 
00056 
00057     def testFormRedirectPriorities(self):
00058         """Check if a new login identity has preference over openid server
00059         reponse.
00060         """
00061         self.app.REQUEST.form.update(self.server_response)
00062         self.app.REQUEST.form["__ac_identity_url"]=self.identity
00063         self.assertRaises(Redirect,
00064                 self.folder.pas.openid.extractCredentials,
00065                 self.app.REQUEST)
00066 
00067 
00068 def test_suite():
00069     from unittest import TestSuite, makeSuite
00070     suite=TestSuite()
00071     suite.addTest(makeSuite(TestOpenIdExtraction))
00072     return suite