[Zope-CVS] CVS: Products/PluggableAuthService/tests -
test_PluggableAuthService.py:1.15
Jens Vagelpohl
jens at dataflake.org
Sat Nov 20 15:02:20 EST 2004
Update of /cvs-repository/Products/PluggableAuthService/tests
In directory cvs.zope.org:/tmp/cvs-serv20664/tests
Modified Files:
test_PluggableAuthService.py
Log Message:
- Add a publicly callable "logout" method on the PluggableAuthService
instance that will call resetCredentials on all activated
ICredentialsRest plugins, thus effecting a logout.
=== Products/PluggableAuthService/tests/test_PluggableAuthService.py 1.14 => 1.15 ===
--- Products/PluggableAuthService/tests/test_PluggableAuthService.py:1.14 Mon Nov 8 17:35:45 2004
+++ Products/PluggableAuthService/tests/test_PluggableAuthService.py Sat Nov 20 15:02:20 2004
@@ -106,6 +106,29 @@
response.challenger = self
return True
+class DummyCredentialsStore(DummyPlugin):
+
+ def __init__(self, id):
+ self.id = id
+ self.creds = {}
+
+ def updateCredentials(self, request, response, login, password):
+ self.creds[login] = password
+
+ def resetCredentials(self, request, response):
+ login = request['login']
+ del self.creds[login]
+
+ def extractCredentials(self, request):
+ creds = {}
+ login = request['login']
+
+ if self.creds.get(login) is not None:
+ creds['login'] = login
+ creds['password'] = self.creds.get(login)
+
+ return creds
+
class DummyBadChallenger( DummyChallenger ):
def challenge(self, request, response):
@@ -181,6 +204,9 @@
self._unauthorized()
return "An error has occurred."
+ def redirect(self, *ignore, **ignored):
+ pass
+
class FauxObject( Implicit ):
def __init__( self, id=None ):
@@ -1641,9 +1667,49 @@
zcuf(self, request)
- self.failUnlessRaises( Unauthorized, response.unauthorized)
+ self.failUnlessRaises(Unauthorized, response.unauthorized)
self.assertEqual(counter.count, 1)
+
+ def test_logout(self):
+ from Products.PluggableAuthService.interfaces.plugins \
+ import IExtractionPlugin, \
+ ICredentialsUpdatePlugin, \
+ ICredentialsResetPlugin
+ plugins = self._makePlugins()
+ zcuf = self._makeOne(plugins)
+ creds_store = DummyCredentialsStore('creds')
+ zcuf._setObject('creds', creds_store)
+ creds_store = zcuf._getOb('creds')
+
+ plugins = zcuf._getOb('plugins')
+ #import pdb; pdb.set_trace()
+ directlyProvides( creds_store
+ , ( IExtractionPlugin
+ , ICredentialsUpdatePlugin
+ , ICredentialsResetPlugin
+ )
+ )
+ plugins.activatePlugin(IExtractionPlugin, 'creds')
+ plugins.activatePlugin(ICredentialsUpdatePlugin, 'creds')
+ plugins.activatePlugin(ICredentialsResetPlugin, 'creds')
+
+ response = FauxResponse()
+ request = FauxRequest(RESPONSE=response)
+ zcuf.REQUEST = request
+
+ # Put a user in the credentials store
+ creds_store.updateCredentials(request, response, 'foo', 'bar')
+ request['login'] = 'foo'
+ request['HTTP_REFERER'] = ''
+ extracted = creds_store.extractCredentials(request)
+ self.failIf(len(extracted.keys()) == 0)
+
+ # Now call the logout method - the credentials should go away
+ newSecurityManager(None, FauxUser('foo', 'foo'))
+ zcuf.logout(request)
+ extracted = creds_store.extractCredentials(request)
+ self.failUnless(len(extracted.keys()) == 0)
if __name__ == "__main__":
unittest.main()
More information about the Zope-CVS
mailing list