[Zope-CVS] CVS: Products/PluggableAuthService/plugins/tests - test_InlineAuthHelper.py:1.2 test_CookieAuthHelper.py:1.2 test_ZODBUserManager.py:1.6 test_ScriptablePlugin.py:1.5 test_RecursiveGroupsPlugin.py:1.5 test_HTTPBasicAuthHelper.py:1.12

Zachery Bir zbir at urbanape.com
Sat Oct 16 16:16:17 EDT 2004


Update of /cvs-repository/Products/PluggableAuthService/plugins/tests
In directory cvs.zope.org:/tmp/cvs-serv25732/plugins/tests

Modified Files:
	test_ZODBUserManager.py test_ScriptablePlugin.py 
	test_RecursiveGroupsPlugin.py test_HTTPBasicAuthHelper.py 
Added Files:
	test_InlineAuthHelper.py test_CookieAuthHelper.py 
Log Message:
Merging pre-1_0_3-zbir-challenge-branch to the head.


=== Products/PluggableAuthService/plugins/tests/test_InlineAuthHelper.py 1.1 => 1.2 ===
--- /dev/null	Sat Oct 16 16:16:17 2004
+++ Products/PluggableAuthService/plugins/tests/test_InlineAuthHelper.py	Sat Oct 16 16:15:46 2004
@@ -0,0 +1,115 @@
+##############################################################################
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights
+# Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this
+# distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest
+
+from Products.PluggableAuthService.tests.conformance \
+     import ILoginPasswordHostExtractionPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import IChallengePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsUpdatePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsResetPlugin_conformance
+
+from Products.PluggableAuthService.tests.test_PluggableAuthService \
+     import FauxRequest, FauxResponse, FauxObject, FauxRoot, FauxContainer
+
+class FauxSettableRequest(FauxRequest):
+
+    def set(self, name, value):
+        self._dict[name] = value
+
+class FauxInlineResponse(FauxResponse):
+
+    def __init__(self):
+        self.setBody("Should never see this.")
+        self.status = '200'
+        self.headers = {}
+
+    def setStatus(self, status, reason=None):
+        self.status = status
+
+    def setBody(self, body, *args, **kw):
+        self.body = body
+
+class InlineAuthHelperTests( unittest.TestCase
+                           , ILoginPasswordHostExtractionPlugin_conformance
+                           , IChallengePlugin_conformance
+                           ):
+
+    def _getTargetClass( self ):
+
+        from Products.PluggableAuthService.plugins.InlineAuthHelper \
+            import InlineAuthHelper
+
+        return InlineAuthHelper
+
+    def _makeOne( self, id='test', *args, **kw ):
+
+        return self._getTargetClass()( id=id, *args, **kw )
+
+    def _makeTree( self ):
+
+        rc = FauxObject( 'rc' )
+        root = FauxRoot( 'root' ).__of__( rc )
+        folder = FauxContainer( 'folder' ).__of__( root )
+        object = FauxObject( 'object' ).__of__( folder )
+
+        return rc, root, folder, object
+
+    def test_extractCredentials_no_creds( self ):
+
+        helper = self._makeOne()
+        response = FauxInlineResponse()
+        request = FauxRequest(RESPONSE=response)
+
+        self.assertEqual( helper.extractCredentials( request ), {} )
+
+    def test_extractCredentials_with_form_creds( self ):
+
+        helper = self._makeOne()
+        response = FauxInlineResponse()
+        request = FauxSettableRequest(__ac_name='foo',
+                                      __ac_password='bar',
+                                      RESPONSE=response)
+
+        self.assertEqual(helper.extractCredentials(request),
+                        {'login': 'foo',
+                         'password': 'bar',
+                         'remote_host': '',
+                         'remote_address': ''})
+
+    def test_challenge( self ):
+        from zExceptions import Unauthorized
+        rc, root, folder, object = self._makeTree()
+        response = FauxInlineResponse()
+        request = FauxRequest(RESPONSE=response)
+        root.REQUEST = request
+
+        helper = self._makeOne().__of__(root)
+        helper.body = "Overridden"
+
+        self.assertEqual(response.body, "Should never see this.")
+        helper.challenge(request, response)
+        self.assertEqual(response.body, "Overridden")
+
+if __name__ == "__main__":
+    unittest.main()
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite( InlineAuthHelperTests ),
+        ))
+


=== Products/PluggableAuthService/plugins/tests/test_CookieAuthHelper.py 1.1 => 1.2 ===
--- /dev/null	Sat Oct 16 16:16:17 2004
+++ Products/PluggableAuthService/plugins/tests/test_CookieAuthHelper.py	Sat Oct 16 16:15:46 2004
@@ -0,0 +1,132 @@
+##############################################################################
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights
+# Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this
+# distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest
+
+from Products.PluggableAuthService.tests.conformance \
+     import ILoginPasswordHostExtractionPlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import IChallengePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsUpdatePlugin_conformance
+from Products.PluggableAuthService.tests.conformance \
+     import ICredentialsResetPlugin_conformance
+
+from Products.PluggableAuthService.tests.test_PluggableAuthService \
+     import FauxRequest, FauxResponse, FauxObject, FauxRoot, FauxContainer
+
+class FauxSettableRequest(FauxRequest):
+
+    def set(self, name, value):
+        self._dict[name] = value
+
+class FauxCookieResponse(FauxResponse):
+
+    def __init__(self):
+        self.cookies = {}
+        self.redirected = False
+        self.status = '200'
+        self.headers = {}
+
+    def setCookie(self, cookie_name, cookie_value, path):
+        self.cookies[(cookie_name, path)] = cookie_value
+
+    def expireCookie(self, cookie_name, path):
+        if (cookie_name, path) in self.cookies:
+            del self.cookies[(cookie_name, path)]
+
+    def redirect(self, location, status=302, lock=0):
+        self.status = status
+        self.headers['Location'] = location
+
+class CookieAuthHelperTests( unittest.TestCase
+                           , ILoginPasswordHostExtractionPlugin_conformance
+                           , IChallengePlugin_conformance
+                           , ICredentialsResetPlugin_conformance
+                           ):
+
+    def _getTargetClass( self ):
+
+        from Products.PluggableAuthService.plugins.CookieAuthHelper \
+            import CookieAuthHelper
+
+        return CookieAuthHelper
+
+    def _makeOne( self, id='test', *args, **kw ):
+
+        return self._getTargetClass()( id=id, *args, **kw )
+
+    def _makeTree( self ):
+
+        rc = FauxObject( 'rc' )
+        root = FauxRoot( 'root' ).__of__( rc )
+        folder = FauxContainer( 'folder' ).__of__( root )
+        object = FauxObject( 'object' ).__of__( folder )
+
+        return rc, root, folder, object
+
+    def test_extractCredentials_no_creds( self ):
+
+        helper = self._makeOne()
+        response = FauxCookieResponse()
+        request = FauxRequest(RESPONSE=response)
+
+        self.assertEqual( helper.extractCredentials( request ), {} )
+
+    def test_extractCredentials_with_form_creds( self ):
+
+        helper = self._makeOne()
+        response = FauxCookieResponse()
+        request = FauxSettableRequest(__ac_name='foo',
+                                      __ac_password='bar',
+                                      RESPONSE=response)
+
+        self.assertEqual(len(response.cookies), 0)
+        self.assertEqual(helper.extractCredentials(request),
+                        {'login': 'foo',
+                         'password': 'bar',
+                         'remote_host': '',
+                         'remote_address': ''})
+        self.assertEqual(len(response.cookies), 0)
+
+    def test_challenge( self ):
+        from zExceptions import Unauthorized
+        rc, root, folder, object = self._makeTree()
+        response = FauxCookieResponse()
+        request = FauxRequest(RESPONSE=response)
+        root.REQUEST = request
+
+        helper = self._makeOne().__of__(root)
+
+        helper.challenge(request, response)
+        self.assertEqual(response.status, 302)
+        self.assertEqual(len(response.headers), 1)
+
+
+    def test_resetCredentials( self ):
+        helper = self._makeOne()
+        response = FauxCookieResponse()
+        request = FauxRequest(RESPONSE=response)
+
+        helper.resetCredentials(request, response)
+        self.assertEqual(len(response.cookies), 0)
+
+if __name__ == "__main__":
+    unittest.main()
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite( CookieAuthHelperTests ),
+        ))
+


=== Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py 1.5 => 1.6 ===
--- Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py:1.5	Mon Sep 13 11:14:46 2004
+++ Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py	Sat Oct 16 16:15:46 2004
@@ -364,5 +364,4 @@
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite( ZODBUserManagerTests ),
-        ))               
-    
\ No newline at end of file
+        ))


=== Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py 1.4 => 1.5 ===
--- Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py:1.4	Mon Sep 13 11:14:46 2004
+++ Products/PluggableAuthService/plugins/tests/test_ScriptablePlugin.py	Sat Oct 16 16:15:46 2004
@@ -72,7 +72,7 @@
         scriptable_plugin.manage_updateInterfaces( ['IFaux', 'IFauxTwo'] )
 
         self.assertEqual( len(scriptable_plugin.__implements__), 4 )
-    
+
     def test_withTwoOnlyOneWired( self ):
 
         parent = Folder()
@@ -110,8 +110,10 @@
         self.assertEqual( len(scriptable_plugin.__implements__), 3 )
 
 
+if __name__ == '__main__':
+    unittest.main()
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite( ScriptablePluginTests ),
-        ))               
-        
\ No newline at end of file
+        ))


=== Products/PluggableAuthService/plugins/tests/test_RecursiveGroupsPlugin.py 1.4 => 1.5 ===
--- Products/PluggableAuthService/plugins/tests/test_RecursiveGroupsPlugin.py:1.4	Mon Sep 13 11:14:46 2004
+++ Products/PluggableAuthService/plugins/tests/test_RecursiveGroupsPlugin.py	Sat Oct 16 16:15:46 2004
@@ -194,4 +194,4 @@
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite( RecursiveGroupsPluginTests ),
-        ))               
+        ))


=== Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py 1.11 => 1.12 ===
--- Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py:1.11	Fri Sep 24 12:40:48 2004
+++ Products/PluggableAuthService/plugins/tests/test_HTTPBasicAuthHelper.py	Sat Oct 16 16:15:46 2004
@@ -35,7 +35,7 @@
             return None
 
         return self._name, self._password
-    
+
     def get(self, name, default=None):
         return getattr(self, name, default)
 
@@ -45,22 +45,26 @@
     realm = 'unit test'
     debug_mode = 0
     headers = {}
-    
+
     def unauthorized( self ):
 
         self._unauthorized_called = 1
-        
+
     def setStatus(self, status, reason=None):
-        
+
         self.status = status
 
     def setHeader(self, name, value, literal=0):
-        
+
+        self.headers[name] = value
+
+    def addHeader(self, name, value):
+
         self.headers[name] = value
 
     def setBody(self, body, is_error=0):
         self.body = body
-        
+
 
 class HTTPBasicAuthHelperTests( unittest.TestCase
                               , ILoginPasswordHostExtractionPlugin_conformance
@@ -92,12 +96,12 @@
         request = FauxHTTPRequest( 'foo', 'bar' )
 
         self.assertEqual( helper.extractCredentials( request )
-                        , { 'login' : 'foo', 'password' : 'bar', 
+                        , { 'login' : 'foo', 'password' : 'bar',
                             'remote_host': '', 'remote_address': '' } )
 
     def test_challenge( self ):
         from zExceptions import Unauthorized
-        
+
         helper = self._makeOne()
         request = FauxHTTPRequest()
         response = FauxHTTPResponse()
@@ -105,9 +109,9 @@
         self.failIf( response._unauthorized_called )
         helper.challenge(request, response)
         self.failUnless(response.status, 401)
-        self.failUnless(response.headers['WWW-Authenticate'], 
+        self.failUnless(response.headers['WWW-Authenticate'],
             'basic realm="unit test"')
-            
+
 
     def test_resetCredentials( self ):
 
@@ -121,9 +125,8 @@
 
 if __name__ == "__main__":
     unittest.main()
-        
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite( HTTPBasicAuthHelperTests ),
         ))
-        
\ No newline at end of file



More information about the Zope-CVS mailing list