Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
PluggableAuthService.plugins.tests.test_CookieAuthHelper.CookieAuthHelperTests Class Reference
Inheritance diagram for PluggableAuthService.plugins.tests.test_CookieAuthHelper.CookieAuthHelperTests:
Inheritance graph
[legend]
Collaboration diagram for PluggableAuthService.plugins.tests.test_CookieAuthHelper.CookieAuthHelperTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_extractCredentials_no_creds
def test_extractCredentials_with_form_creds
def test_extractCredentials_with_deleted_cookie
def test_challenge
def test_resetCredentials
def test_loginWithoutCredentialsUpdate
def test_extractCredentials_from_cookie_with_colon_in_password

Private Member Functions

def _getTargetClass
def _makeOne
def _makeTree

Detailed Description

Definition at line 57 of file test_CookieAuthHelper.py.


Member Function Documentation

Definition at line 59 of file test_CookieAuthHelper.py.

00059 
00060     def _getTargetClass( self ):
00061 
00062         from Products.PluggableAuthService.plugins.CookieAuthHelper \
00063             import CookieAuthHelper
00064 
00065         return CookieAuthHelper

def PluggableAuthService.plugins.tests.test_CookieAuthHelper.CookieAuthHelperTests._makeOne (   self,
  id = 'test',
  args,
  kw 
) [private]

Definition at line 66 of file test_CookieAuthHelper.py.

00066 
00067     def _makeOne( self, id='test', *args, **kw ):
00068 
00069         return self._getTargetClass()( id=id, *args, **kw )

Definition at line 70 of file test_CookieAuthHelper.py.

00070 
00071     def _makeTree( self ):
00072 
00073         rc = FauxObject( 'rc' )
00074         root = FauxRoot( 'root' ).__of__( rc )
00075         folder = FauxContainer( 'folder' ).__of__( root )
00076         object = FauxObject( 'object' ).__of__( folder )
00077 
00078         return rc, root, folder, object

Here is the caller graph for this function:

Definition at line 119 of file test_CookieAuthHelper.py.

00119 
00120     def test_challenge( self ):
00121         from zExceptions import Unauthorized
00122         rc, root, folder, object = self._makeTree()
00123         response = FauxCookieResponse()
00124         request = FauxRequest(RESPONSE=response)
00125         root.REQUEST = request
00126 
00127         helper = self._makeOne().__of__(root)
00128 
00129         helper.challenge(request, response)
00130         self.assertEqual(response.status, 302)
00131         self.assertEqual(len(response.headers), 1)
00132 

Definition at line 154 of file test_CookieAuthHelper.py.

00154 
00155     def test_extractCredentials_from_cookie_with_colon_in_password(self): 
00156         # http://www.zope.org/Collectors/PAS/51
00157         # Passwords with ":" characters broke authentication
00158         from base64 import encodestring 
00159 
00160         helper = self._makeOne() 
00161         response = FauxCookieResponse() 
00162         request = FauxSettableRequest(RESPONSE=response) 
00163 
00164         cookie_str = '%s:%s' % ('foo'.encode('hex'), 'b:ar'.encode('hex'))
00165         cookie_val = encodestring(cookie_str)
00166         cookie_val = cookie_val.rstrip() 
00167         request.set(helper.cookie_name, cookie_val) 
00168 
00169         self.assertEqual(helper.extractCredentials(request), 
00170                         {'login': 'foo', 
00171                          'password': 'b:ar', 
00172                          'remote_host': '', 
00173                          'remote_address': ''}) 
00174 

Definition at line 79 of file test_CookieAuthHelper.py.

00079 
00080     def test_extractCredentials_no_creds( self ):
00081 
00082         helper = self._makeOne()
00083         response = FauxCookieResponse()
00084         request = FauxRequest(RESPONSE=response)
00085 
00086         self.assertEqual( helper.extractCredentials( request ), {} )

Definition at line 103 of file test_CookieAuthHelper.py.

00103 
00104     def test_extractCredentials_with_deleted_cookie(self):
00105         # http://www.zope.org/Collectors/PAS/43
00106         # Edge case: The ZPublisher sets a cookie's value to "deleted"
00107         # in the current request if expireCookie is called. If we hit
00108         # extractCredentials in the same request after this, it would 
00109         # blow up trying to deal with the invalid cookie value.
00110         helper = self._makeOne()
00111         response = FauxCookieResponse()
00112         req_data = { helper.cookie_name : 'deleted'
00113                    , 'RESPONSE' : response
00114                    }
00115         request = FauxSettableRequest(**req_data)
00116         self.assertEqual(len(response.cookies), 0)
00117 
00118         self.assertEqual(helper.extractCredentials(request), {})

Definition at line 87 of file test_CookieAuthHelper.py.

00087 
00088     def test_extractCredentials_with_form_creds( self ):
00089 
00090         helper = self._makeOne()
00091         response = FauxCookieResponse()
00092         request = FauxSettableRequest(__ac_name='foo',
00093                                       __ac_password='b:ar',
00094                                       RESPONSE=response)
00095 
00096         self.assertEqual(len(response.cookies), 0)
00097         self.assertEqual(helper.extractCredentials(request),
00098                         {'login': 'foo',
00099                          'password': 'b:ar',
00100                          'remote_host': '',
00101                          'remote_address': ''})
00102         self.assertEqual(len(response.cookies), 0)

Definition at line 141 of file test_CookieAuthHelper.py.

00141 
00142     def test_loginWithoutCredentialsUpdate( self ):
00143         helper = self._makeOne()
00144         response = FauxCookieResponse()
00145         request = FauxSettableRequest( __ac_name='foo'
00146                                      , __ac_password='bar'
00147                                      , RESPONSE=response
00148                                      )
00149         request.form['came_from'] = ''
00150         helper.REQUEST = request
00151 
00152         helper.login()
00153         self.assertEqual(len(response.cookies), 0)

Definition at line 133 of file test_CookieAuthHelper.py.

00133 
00134     def test_resetCredentials( self ):
00135         helper = self._makeOne()
00136         response = FauxCookieResponse()
00137         request = FauxRequest(RESPONSE=response)
00138 
00139         helper.resetCredentials(request, response)
00140         self.assertEqual(len(response.cookies), 0)


The documentation for this class was generated from the following file: