[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ browserplugins.py: SessionExtractor may use form data

Helmut Merz helmutm at cyberconcepts.de
Sun Oct 10 10:52:23 EDT 2004


Log message for revision 27912:
  browserplugins.py: SessionExtractor may use form data


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 14:39:57 UTC (rev 27911)
+++ Zope3/trunk/src/zope/app/pas/browserplugins.py	2004-10-10 14:52:23 UTC (rev 27912)
@@ -32,17 +32,38 @@
 
             >>> from zope.app.session.session import RAMSessionDataContainer
             >>> from zope.app.session.session import Session
-            >>> from tests import sessionSetUp
-            >>> request = sessionSetUp(RAMSessionDataContainer)
+            >>> from tests import sessionSetUp, createTestRequest
+
+            >>> sessionSetUp(RAMSessionDataContainer)
+            >>> se = SessionExtractor()
+
+            No credentials available:
+            >>> request = createTestRequest()
+            >>> se.extractCredentials(request)
+
+            If the session does not contain the credentials check
+            the request for form variables.
+            >>> request = createTestRequest(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 = SessionExtractor()
             >>> se.extractCredentials(request)
             {'username': 'scott', 'password': 'tiger'}
         """
         sessionData = ISession(request)['pas_credentials']
+        if not sessionData:
+            un = request.get('username', None)
+            pw = request.get('password', None)
+            if un and pw:
+                sessionData['username'] = un
+                sessionData['password'] = pw
+            else:
+                return None
         return {'username': sessionData['username'],
                 'password': sessionData['password']}
 

Modified: Zope3/trunk/src/zope/app/pas/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/tests.py	2004-10-10 14:39:57 UTC (rev 27911)
+++ Zope3/trunk/src/zope/app/pas/tests.py	2004-10-10 14:52:23 UTC (rev 27912)
@@ -30,7 +30,7 @@
 from zope.app.session.http import CookieClientIdManager
 
 from zope.publisher.interfaces import IRequest
-from zope.publisher.http import HTTPRequest
+from zope.publisher.tests.httprequest import TestRequest
 
 def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
     placelesssetup.setUp()
@@ -39,9 +39,9 @@
     ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
     sdc = session_data_container_class()
     ztapi.provideUtility(ISessionDataContainer, sdc, 'pas_credentials')
-    request = HTTPRequest(None, None, {}, None)
-    return request
 
+def createTestRequest(**kw):
+    return TestRequest(**kw)
 
 def test_suite():
     return unittest.TestSuite((



More information about the Zope3-Checkins mailing list