[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ Added class
FormChallenge to browserplugins.py (not yet functional)
Helmut Merz
helmutm at cy55.de
Sun Oct 10 15:34:28 EDT 2004
Log message for revision 27936:
Added class FormChallenge to browserplugins.py (not yet functional)
Changed:
U Zope3/trunk/src/zope/app/pas/browserplugins.py
U Zope3/trunk/src/zope/app/pas/tests.py
-=-
Modified: Zope3/trunk/src/zope/app/pas/browserplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-10 19:27:22 UTC (rev 27935)
+++ Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-10 19:34:28 UTC (rev 27936)
@@ -17,44 +17,50 @@
$Id$
"""
-import zope.interface
+from zope.interface import implements
+from persistent import Persistent
+from zope.app.component import hooks
+from zope.app.container.contained import Contained
+from zope.app.traversing.browser.interfaces import IAbsoluteURL
+from zope.app import zapi
from zope.app.session.interfaces import ISession
-from zope.app.pas import interfaces
-class SessionExtractor:
- """ session-based credential extractor
- """
- zope.interface.implements(interfaces.IExtractionPlugin)
+from zope.app.pas.interfaces import IExtractionPlugin, IChallengePlugin
- def extractCredentials(self, request):
- """ Extract the credentials that are referenced in the
- request by looking them up in the session.
+class SessionExtractor(Persistent, Contained):
+ """ session-based credential extractor.
- >>> from zope.app.session.session import RAMSessionDataContainer
- >>> from zope.app.session.session import Session
- >>> from tests import sessionSetUp, createTestRequest
+ Extract the credentials that are referenced in the
+ request by looking them up in the session.
- >>> sessionSetUp(RAMSessionDataContainer)
- >>> se = SessionExtractor()
+ >>> from zope.app.session.session import RAMSessionDataContainer
+ >>> from zope.app.session.session import Session
+ >>> from tests import sessionSetUp, createTestRequest
- No credentials available:
- >>> request = createTestRequest()
- >>> se.extractCredentials(request)
+ >>> sessionSetUp(RAMSessionDataContainer)
+ >>> se = SessionExtractor()
- If the session does not contain the credentials check
- the request for form variables.
- >>> request = createTestRequest(username='scott', password='tiger')
+ No credentials available:
+ >>> request = createTestRequest()
+ >>> se.extractCredentials(request)
- >>> se.extractCredentials(request)
- {'username': 'scott', 'password': 'tiger'}
+ If the session does not contain the credentials check
+ the request for form variables.
+ >>> request = createTestRequest(username='scott', password='tiger')
- >>> request = createTestRequest()
- >>> sessionData = Session(request)['pas_credentials']
- >>> sessionData['username'] = 'scott'
- >>> sessionData['password'] = 'tiger'
- >>> se.extractCredentials(request)
- {'username': 'scott', 'password': 'tiger'}
- """
+ >>> se.extractCredentials(request)
+ {'username': 'scott', 'password': 'tiger'}
+
+ >>> request = createTestRequest()
+ >>> sessionData = Session(request)['pas_credentials']
+ >>> sessionData['username'] = 'scott'
+ >>> sessionData['password'] = 'tiger'
+ >>> se.extractCredentials(request)
+ {'username': 'scott', 'password': 'tiger'}
+ """
+ implements(IExtractionPlugin)
+
+ def extractCredentials(self, request):
sessionData = ISession(request)['pas_credentials']
if not sessionData:
un = request.get('username', None)
@@ -68,3 +74,37 @@
'password': sessionData['password']}
+class FormChallenger(Persistent, Contained):
+ """ Query the user for credentials using a browser form.
+
+ First we need a request and a response.
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> response = request.response
+
+ Then we create a FormAuthChallenger and call it.
+ >>> fc = FormChallenger()
+ >>> fc.challenge(request, response)
+ True
+
+ The response's headers should now contain the URL to redirect to.
+ >>> headers = response.getHeaders()
+ >>> headers['Location']
+ 'http://127.0.0.1'
+
+ """
+
+ implements(IChallengePlugin)
+
+ def challenge(self, request, response):
+ """ Response shuold redirect to login page cause Credebtials
+ could not have been extracted.
+ """
+ site = hooks.getSite()
+ #url = zapi.getView(site, zapi.name(site), request, providing=IAbsoluteURL,
+ # context=site)
+ url = request.getApplicationURL()
+ response.redirect(url)
+
+ return True
Modified: Zope3/trunk/src/zope/app/pas/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/tests.py 2004-10-10 19:27:22 UTC (rev 27935)
+++ Zope3/trunk/src/zope/app/pas/tests.py 2004-10-10 19:34:28 UTC (rev 27936)
@@ -20,6 +20,7 @@
from zope.testing import doctest
from zope.app.tests import placelesssetup, ztapi
from zope.app.event.tests.placelesssetup import getEvents
+from zope.app.tests.setup import placefulSetUp, placefulTearDown
from zope.app.session.interfaces import \
IClientId, IClientIdManager, ISession, ISessionDataContainer, \
@@ -40,6 +41,12 @@
sdc = session_data_container_class()
ztapi.provideUtility(ISessionDataContainer, sdc, 'pas_credentials')
+def formAuthSetUp(self):
+ placefulSetUp(site=True)
+
+def formAuthTearDown(self):
+ placefulTearDown()
+
def createTestRequest(**kw):
return TestRequest(**kw)
@@ -52,7 +59,9 @@
globs={'provideUtility': ztapi.provideUtility,
'getEvents': getEvents,
}),
- doctest.DocTestSuite('zope.app.pas.browserplugins'),
+ doctest.DocTestSuite('zope.app.pas.browserplugins',
+ setUp=formAuthSetUp,
+ tearDown=formAuthTearDown),
))
if __name__ == '__main__':
More information about the Zope3-Checkins
mailing list