Back to index

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

List of all members.

Public Member Functions

def test_empty
def test_addRole
def test_addRole_duplicate_check
def test_removeRole_nonesuch
def test_removeRole_valid_id
def test_enumerateRoles_no_criteria
def test_enumerateRoles_exact
def test_enumerateRoles_partial
def test_enumerateRoles_multiple
def test_enumerateRoles_exact_nonesuch
def test_assignRoleToPrincipal_nonesuch
def test_assignRoleToPrincipal_user
def test_assignRoleToPrincipal_group
def test_assignRoleToPrincipal_new
def test_assignRoleToPrincipal_already
def test_assignRoleBeforeRemovingPrincipal
def test_removeRoleFromPrincipal_nonesuch
def test_removeRoleFromPrincipal_existing
def test_removeRoleFromPrincipal_noop
def test_updateRole_nonesuch
def test_updateRole_normal
def test_removeRole_then_addRole
def testPOSTProtections

Private Member Functions

def _getTargetClass
def _makeOne

Detailed Description

Definition at line 31 of file test_ZODBRoleManager.py.


Member Function Documentation

Definition at line 33 of file test_ZODBRoleManager.py.

00033 
00034     def _getTargetClass( self ):
00035 
00036         from Products.PluggableAuthService.plugins.ZODBRoleManager \
00037             import ZODBRoleManager
00038 
00039         return ZODBRoleManager

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

Definition at line 40 of file test_ZODBRoleManager.py.

00040 
00041     def _makeOne( self, id='test', *args, **kw ):
00042 
00043         return self._getTargetClass()( id=id, *args, **kw )

Definition at line 55 of file test_ZODBRoleManager.py.

00055 
00056     def test_addRole( self ):
00057 
00058         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00059             import FauxRoot
00060 
00061         root = FauxRoot()
00062         zrm = self._makeOne().__of__( root )
00063 
00064         zrm.addRole( 'roleid', 'Role', 'This is a role' )
00065 
00066         role_ids = zrm.listRoleIds()
00067         self.assertEqual( len( role_ids ), 1 )
00068         self.assertEqual( role_ids[0], 'roleid' )
00069 
00070         info_list = zrm.enumerateRoles()
00071         self.assertEqual( len( info_list ), 1 )
00072         info = info_list[ 0 ]
00073         self.assertEqual( info[ 'id' ], 'roleid' )

Definition at line 74 of file test_ZODBRoleManager.py.

00074 
00075     def test_addRole_duplicate_check( self ):
00076 
00077         zrm = self._makeOne()
00078 
00079         zrm.addRole( 'roleid', 'Role', 'This is a role' )
00080 
00081         self.assertRaises( KeyError, zrm.addRole
00082                          , 'roleid', 'Alias', 'duplicate' )

Definition at line 340 of file test_ZODBRoleManager.py.

00340 
00341     def test_assignRoleBeforeRemovingPrincipal( self ):
00342 
00343         root = FauxSmartPAS()
00344         root.user_ids['foo'] = 'foo'
00345 
00346         zrm = self._makeOne( id='assign_before_remove' ).__of__( root )
00347 
00348         zrm.addRole( 'test' )
00349         self.assertEqual( len( zrm.listAssignedPrincipals( 'test' ) ), 0 )
00350 
00351         new = zrm.assignRoleToPrincipal( 'test', 'foo' )
00352 
00353         self.failUnless( new )
00354 
00355         assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
00356 
00357         self.assertEqual( len( assigned ), 1 )
00358         self.assertEqual( assigned[0], 'foo' )
00359 
00360         del root.user_ids['foo']
00361 
00362         assigned = [x[1] for x in zrm.listAssignedPrincipals( 'test' )]
00363 
00364         self.assertEqual( len( assigned ), 1 )
00365         self.assertEqual( assigned[0], '<foo: not found>' )

Definition at line 323 of file test_ZODBRoleManager.py.

00323 
00324     def test_assignRoleToPrincipal_already( self ):
00325 
00326         root = FauxPAS()
00327         zrm = self._makeOne( id='assign_already' ).__of__( root )
00328 
00329         zrm.addRole( 'test' )
00330 
00331         zrm.assignRoleToPrincipal( 'test', 'foo' )
00332         new = zrm.assignRoleToPrincipal( 'test', 'foo' )
00333 
00334         self.failIf( new )
00335 
00336         assigned = [x[0] for x in zrm.listAssignedPrincipals( 'test' )]
00337 
00338         self.assertEqual( len( assigned ), 1 )
00339         self.assertEqual( assigned[0], 'foo' )

Definition at line 286 of file test_ZODBRoleManager.py.

00286 
00287     def test_assignRoleToPrincipal_group( self ):
00288 
00289         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00290             import FauxRoot
00291 
00292         root = FauxRoot()
00293         zrm = self._makeOne( id='assign_user' ).__of__( root )
00294         zrm.addRole( 'test1' )
00295         zrm.addRole( 'test2' )
00296         user = DummyUser( 'foo', ( 'qux', ) )
00297 
00298         roles = zrm.getRolesForPrincipal( user )
00299         self.assertEqual( len( roles ), 0 )
00300 
00301         zrm.assignRoleToPrincipal( 'test1', 'qux' )
00302 
00303         roles = zrm.getRolesForPrincipal( user )
00304         self.assertEqual( len( roles ), 1 )
00305         self.failUnless( 'test1' in roles )

Definition at line 306 of file test_ZODBRoleManager.py.

00306 
00307     def test_assignRoleToPrincipal_new( self ):
00308 
00309         root = FauxPAS()
00310         zrm = self._makeOne( id='assign_new' ).__of__( root )
00311 
00312         zrm.addRole( 'test' )
00313         self.assertEqual( len( zrm.listAssignedPrincipals( 'test' ) ), 0 )
00314 
00315         new = zrm.assignRoleToPrincipal( 'test', 'foo' )
00316 
00317         self.failUnless( new )
00318 
00319         assigned = [x[0] for x in zrm.listAssignedPrincipals( 'test' )]
00320 
00321         self.assertEqual( len( assigned ), 1 )
00322         self.assertEqual( assigned[0], 'foo' )

Definition at line 249 of file test_ZODBRoleManager.py.

00249 
00250     def test_assignRoleToPrincipal_nonesuch( self ):
00251 
00252         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00253             import FauxRoot
00254 
00255         root = FauxRoot()
00256         zrm = self._makeOne( id='assign_nonesuch' ).__of__( root )
00257 
00258         self.assertRaises( KeyError, zrm.assignRoleToPrincipal, 'test', 'foo' )

Definition at line 259 of file test_ZODBRoleManager.py.

00259 
00260     def test_assignRoleToPrincipal_user( self ):
00261 
00262         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00263             import FauxRoot
00264 
00265         root = FauxRoot()
00266         zrm = self._makeOne( id='assign_user' ).__of__( root )
00267         zrm.addRole( 'test1' )
00268         zrm.addRole( 'test2' )
00269         user = DummyUser( 'foo' )
00270 
00271         roles = zrm.getRolesForPrincipal( user )
00272         self.assertEqual( len( roles ), 0 )
00273 
00274         zrm.assignRoleToPrincipal( 'test1', 'foo' )
00275 
00276         roles = zrm.getRolesForPrincipal( user )
00277         self.assertEqual( len( roles ), 1 )
00278         self.failUnless( 'test1' in roles )
00279 
00280         zrm.assignRoleToPrincipal( 'test2', 'foo' )
00281 
00282         roles = zrm.getRolesForPrincipal( user )
00283         self.assertEqual( len( roles ), 2 )
00284         self.failUnless( 'test1' in roles )
00285         self.failUnless( 'test2' in roles )

Definition at line 44 of file test_ZODBRoleManager.py.

00044 
00045     def test_empty( self ):
00046 
00047         zrm = self._makeOne()
00048 
00049         self.assertEqual( len( zrm.listRoleIds() ), 0 )
00050         self.assertEqual( len( zrm.enumerateRoles() ), 0 )
00051 
00052         user = DummyUser( 'userid' )
00053         roles = zrm.getRolesForPrincipal( user )
00054         self.assertEqual( len( roles ), 0 )

Definition at line 138 of file test_ZODBRoleManager.py.

00138 
00139     def test_enumerateRoles_exact( self ):
00140 
00141         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00142             import FauxRoot
00143 
00144         root = FauxRoot()
00145         zrm = self._makeOne( id='exact' ).__of__( root )
00146 
00147         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00148 
00149         for id in ID_LIST:
00150 
00151             zrm.addRole( id, 'Role %s' % id, 'This is role, %s' % id )
00152 
00153         info_list = zrm.enumerateRoles( id='bar', exact_match=True )
00154 
00155         self.assertEqual( len( info_list ), 1 )
00156         info = info_list[ 0 ]
00157 
00158         self.assertEqual( info[ 'id' ], 'bar' )
00159         self.assertEqual( info[ 'pluginid' ], 'exact' )
00160         self.assertEqual( info[ 'properties_url' ]
00161                         , 'exact/manage_roles?role_id=bar' )
00162         self.assertEqual( info[ 'members_url' ]
00163                         , 'exact/manage_roles?role_id=bar&assign=1' )
00164         self.assertEqual( info[ 'title' ], 'Role bar' )
00165         self.assertEqual( info[ 'description' ], 'This is role, bar' )
00166 

Definition at line 232 of file test_ZODBRoleManager.py.

00232 
00233     def test_enumerateRoles_exact_nonesuch( self ):
00234 
00235         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00236             import FauxRoot
00237 
00238         root = FauxRoot()
00239         zgm = self._makeOne( id='exact_nonesuch' ).__of__( root )
00240 
00241         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00242 
00243         for id in ID_LIST:
00244 
00245             zgm.addRole( id, 'Role %s' % id, 'This is role, %s' % id )
00246 
00247         self.assertEquals( zgm.enumerateRoles( id='qux', exact_match=True )
00248                          , () )

Definition at line 202 of file test_ZODBRoleManager.py.

00202 
00203     def test_enumerateRoles_multiple( self ):
00204 
00205         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00206             import FauxRoot
00207 
00208         root = FauxRoot()
00209         zrm = self._makeOne( id='partial' ).__of__( root )
00210 
00211         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00212 
00213         for id in ID_LIST:
00214 
00215             zrm.addRole( id, 'Role %s' % id, 'This is role, %s' % id )
00216 
00217         info_list = zrm.enumerateRoles( id=ID_LIST )
00218 
00219         self.assertEqual( len( info_list ), len( ID_LIST ) )
00220 
00221         for info in info_list:
00222             self.failUnless( info[ 'id' ] in ID_LIST )
00223 
00224         SUBSET = ID_LIST[:3]
00225 
00226         info_list = zrm.enumerateRoles( id=SUBSET )
00227 
00228         self.assertEqual( len( info_list ), len( SUBSET ) )
00229 
00230         for info in info_list:
00231             self.failUnless( info[ 'id' ] in SUBSET )

Definition at line 107 of file test_ZODBRoleManager.py.

00107 
00108     def test_enumerateRoles_no_criteria( self ):
00109 
00110         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00111             import FauxRoot
00112 
00113         root = FauxRoot()
00114         zrm = self._makeOne( id='no_crit' ).__of__( root )
00115 
00116         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00117 
00118         for id in ID_LIST:
00119 
00120             zrm.addRole( id, 'Role %s' % id, 'This is role, %s' % id )
00121 
00122         info_list = zrm.enumerateRoles()
00123 
00124         self.assertEqual( len( info_list ), len( ID_LIST ) )
00125 
00126         sorted = list( ID_LIST )
00127         sorted.sort()
00128 
00129         for i in range( len( sorted ) ):
00130 
00131             self.assertEqual( info_list[ i ][ 'id' ], sorted[ i ] )
00132             self.assertEqual( info_list[ i ][ 'pluginid' ], 'no_crit' )
00133             self.assertEqual( info_list[ i ][ 'properties_url' ]
00134                             , 'no_crit/manage_roles?role_id=%s' % sorted[ i ])
00135             self.assertEqual( info_list[ i ][ 'members_url' ]
00136                             , 'no_crit/manage_roles?role_id=%s&assign=1'
00137                                 % sorted[ i ])

Definition at line 167 of file test_ZODBRoleManager.py.

00167 
00168     def test_enumerateRoles_partial( self ):
00169 
00170         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00171             import FauxRoot
00172 
00173         root = FauxRoot()
00174         zrm = self._makeOne( id='partial' ).__of__( root )
00175 
00176         ID_LIST = ( 'foo', 'bar', 'baz', 'bam' )
00177 
00178         for id in ID_LIST:
00179 
00180             zrm.addRole( id, 'Role %s' % id, 'This is role, %s' % id )
00181 
00182         info_list = zrm.enumerateRoles( id='ba', exact_match=False )
00183 
00184         self.assertEqual( len( info_list ), len( ID_LIST ) - 1 ) # no 'foo'
00185 
00186         sorted = list( ID_LIST )
00187         sorted.sort()
00188 
00189         for i in range( len( sorted ) - 1 ):
00190 
00191             self.assertEqual( info_list[ i ][ 'id' ], sorted[ i ] )
00192             self.assertEqual( info_list[ i ][ 'pluginid' ], 'partial' )
00193             self.assertEqual( info_list[ i ][ 'properties_url' ]
00194                             , 'partial/manage_roles?role_id=%s' % sorted[ i ])
00195             self.assertEqual( info_list[ i ][ 'members_url' ]
00196                             , 'partial/manage_roles?role_id=%s&assign=1' 
00197                                 % sorted[ i ])
00198             self.assertEqual( info_list[ i ][ 'title' ]
00199                             , 'Role %s' % sorted[ i ] )
00200             self.assertEqual( info_list[ i ][ 'description' ]
00201                             , 'This is role, %s' % sorted[ i ] )

Definition at line 83 of file test_ZODBRoleManager.py.

00083 
00084     def test_removeRole_nonesuch( self ):
00085 
00086         zrm = self._makeOne()
00087 
00088         self.assertRaises( KeyError, zrm.removeRole, 'nonesuch' )

Definition at line 456 of file test_ZODBRoleManager.py.

00456 
00457     def test_removeRole_then_addRole( self ):
00458 
00459         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00460             import FauxRoot
00461 
00462         root = FauxRoot()
00463         zrm = self._makeOne( id='remove_then_add' ).__of__( root )
00464         user = DummyUser( 'foo' )
00465 
00466         zrm.addRole( 'test' )
00467         zrm.assignRoleToPrincipal( 'test', 'foo' )
00468         self.failUnless( 'test' in zrm.getRolesForPrincipal( user ) )
00469 
00470         zrm.removeRole( 'test' )
00471         zrm.addRole( 'test' )
00472 
00473         self.failIf( 'test' in zrm.getRolesForPrincipal( user ) )

Definition at line 89 of file test_ZODBRoleManager.py.

00089 
00090     def test_removeRole_valid_id( self ):
00091 
00092         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00093             import FauxRoot
00094 
00095         root = FauxRoot()
00096         zrm = self._makeOne().__of__( root )
00097 
00098         zrm.addRole( 'roleid', 'Role', 'This is a role' )
00099         zrm.addRole( 'doomed', 'Fatal', 'rust never sleeps' )
00100 
00101         zrm.removeRole( 'doomed' )
00102 
00103         role_ids = zrm.listRoleIds()
00104         self.assertEqual( len( role_ids ), 1 )
00105         self.assertEqual( len( zrm.enumerateRoles() ), 1 )
00106         self.assertEqual( role_ids[0], 'roleid' )

Definition at line 377 of file test_ZODBRoleManager.py.

00377 
00378     def test_removeRoleFromPrincipal_existing( self ):
00379 
00380         root = FauxPAS()
00381         zrm = self._makeOne( id='remove_existing' ).__of__( root )
00382 
00383         zrm.addRole( 'test' )
00384 
00385         zrm.assignRoleToPrincipal( 'test', 'foo' )
00386         zrm.assignRoleToPrincipal( 'test', 'bar' )
00387         zrm.assignRoleToPrincipal( 'test', 'baz' )
00388 
00389         assigned = [x[0] for x in zrm.listAssignedPrincipals( 'test' )]
00390         self.assertEqual( len( assigned ), 3 )
00391         self.failUnless( 'foo' in assigned )
00392         self.failUnless( 'bar' in assigned )
00393         self.failUnless( 'baz' in assigned )
00394 
00395         removed = zrm.removeRoleFromPrincipal( 'test', 'bar' )
00396 
00397         self.failUnless( removed )
00398 
00399         assigned = [x[0] for x in zrm.listAssignedPrincipals( 'test' )]
00400         self.assertEqual( len( assigned ), 2 )
00401         self.failUnless( 'foo' in assigned )
00402         self.failIf( 'bar' in assigned )
00403         self.failUnless( 'baz' in assigned )

Definition at line 366 of file test_ZODBRoleManager.py.

00366 
00367     def test_removeRoleFromPrincipal_nonesuch( self ):
00368 
00369         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00370             import FauxRoot
00371 
00372         root = FauxRoot()
00373         zrm = self._makeOne( id='remove_nonesuch' ).__of__( root )
00374 
00375         self.assertRaises( KeyError, zrm.removeRoleFromPrincipal
00376                          , 'test', 'foo' )

Definition at line 404 of file test_ZODBRoleManager.py.

00404 
00405     def test_removeRoleFromPrincipal_noop( self ):
00406 
00407         root = FauxPAS()
00408         zrm = self._makeOne( id='remove_noop' ).__of__( root )
00409 
00410         zrm.addRole( 'test' )
00411 
00412         zrm.assignRoleToPrincipal( 'test', 'foo' )
00413         zrm.assignRoleToPrincipal( 'test', 'baz' )
00414 
00415         assigned = [x[0] for x in zrm.listAssignedPrincipals( 'test' )]
00416         self.assertEqual( len( assigned ), 2 )
00417         self.failUnless( 'foo' in assigned )
00418         self.failUnless( 'baz' in assigned )
00419 
00420         removed = zrm.removeRoleFromPrincipal( 'test', 'bar' )
00421 
00422         self.failIf( removed )

Definition at line 423 of file test_ZODBRoleManager.py.

00423 
00424     def test_updateRole_nonesuch( self ):
00425 
00426         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00427             import FauxRoot
00428 
00429         root = FauxRoot()
00430         zrm = self._makeOne( id='update_nonesuch' ).__of__( root )
00431 
00432         self.assertRaises( KeyError, zrm.updateRole
00433                          , 'nonesuch', 'title', 'description' )

Definition at line 434 of file test_ZODBRoleManager.py.

00434 
00435     def test_updateRole_normal( self ):
00436 
00437         from Products.PluggableAuthService.tests.test_PluggableAuthService \
00438             import FauxRoot
00439 
00440         root = FauxRoot()
00441         zrm = self._makeOne( id='update_normal' ).__of__( root )
00442 
00443         zrm.addRole( 'role', 'Original Title', 'Original description' )
00444 
00445         info = zrm.getRoleInfo( 'role' )
00446         self.assertEqual( info[ 'id' ], 'role' )
00447         self.assertEqual( info[ 'title' ], 'Original Title' )
00448         self.assertEqual( info[ 'description' ], 'Original description' )
00449 
00450         zrm.updateRole( 'role', 'Updated Title', 'Updated description' )
00451 
00452         info = zrm.getRoleInfo( 'role' )
00453         self.assertEqual( info[ 'id' ], 'role' )
00454         self.assertEqual( info[ 'title' ], 'Updated Title' )
00455         self.assertEqual( info[ 'description' ], 'Updated description' )

Definition at line 474 of file test_ZODBRoleManager.py.

00474 
00475     def testPOSTProtections(self):
00476         from zExceptions import Forbidden
00477 
00478         USER_ID = 'testuser'
00479         ROLE_ID = 'myrole'
00480 
00481         root = FauxPAS()
00482         zrm = self._makeOne( id='remove_existing' ).__of__( root )
00483         zrm = self._makeOne()
00484         zrm.addRole(ROLE_ID)
00485 
00486         user = DummyUser( USER_ID )
00487 
00488         req, res = makeRequestAndResponse()
00489 
00490         # Fails with a GET
00491         # test assignRoleToPrincipal
00492         req.set('REQUEST_METHOD', 'GET')
00493         self.assertRaises(Forbidden, zrm.assignRoleToPrincipal,
00494                           ROLE_ID, USER_ID, REQUEST=req)
00495         # Works with a POST
00496         req.set('REQUEST_METHOD', 'POST')
00497         zrm.assignRoleToPrincipal(ROLE_ID, USER_ID, REQUEST=req)
00498 
00499         # test removeRoleFromPricipal
00500         req.set('REQUEST_METHOD', 'GET')
00501         self.assertRaises(Forbidden, zrm.removeRoleFromPrincipal,
00502                           ROLE_ID, USER_ID, REQUEST=req)
00503         req.set('REQUEST_METHOD', 'POST')
00504         zrm.removeRoleFromPrincipal(ROLE_ID, USER_ID, REQUEST=req)
00505 
00506         # test removeRole
00507         req.set('REQUEST_METHOD', 'GET')
00508         self.assertRaises(Forbidden, zrm.removeRole,
00509                           ROLE_ID, REQUEST=req)
00510         req.set('REQUEST_METHOD', 'POST')
00511         zrm.removeRole(ROLE_ID, REQUEST=req)
00512 
00513         # Readd the role for the manage_* methods
00514         zrm.addRole(ROLE_ID)
00515 
00516         # test manage_assignRoleToPrincipal
00517         req.set('REQUEST_METHOD', 'GET')
00518         self.assertRaises(Forbidden, zrm.manage_assignRoleToPrincipals,
00519                           ROLE_ID, [USER_ID], RESPONSE=res, REQUEST=req)
00520         req.set('REQUEST_METHOD', 'POST')
00521         zrm.manage_assignRoleToPrincipals(ROLE_ID, [USER_ID], RESPONSE=res,
00522                                           REQUEST=req)
00523 
00524         # test manage_removeRoleFromPricipal
00525         req.set('REQUEST_METHOD', 'GET')
00526         self.assertRaises(Forbidden, zrm.manage_removeRoleFromPrincipals,
00527                           ROLE_ID, [USER_ID], RESPONSE=res, REQUEST=req)
00528         req.set('REQUEST_METHOD', 'POST')
00529         zrm.manage_removeRoleFromPrincipals(ROLE_ID, [USER_ID], RESPONSE=res,
00530                                             REQUEST=req)
00531 
00532         # test manage_removeRoles
00533         req.set('REQUEST_METHOD', 'GET')
00534         self.assertRaises(Forbidden, zrm.manage_removeRoles,
00535                           [ROLE_ID], RESPONSE=res, REQUEST=req)
00536         req.set('REQUEST_METHOD', 'POST')
00537         zrm.manage_removeRoles([ROLE_ID], RESPONSE=res, REQUEST=req)
00538 
00539 


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