Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Attributes
PluggableAuthService.tests.test_UserFolder.UserFolderTests Class Reference
Inheritance diagram for PluggableAuthService.tests.test_UserFolder.UserFolderTests:
Inheritance graph
[legend]
Collaboration diagram for PluggableAuthService.tests.test_UserFolder.UserFolderTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def testGetUser
def testGetBadUser
def testGetUserById
def testGetBadUserById
def NOTIMPLEMENTED_testGetUsers
def NOTIMPLEMENTED_testGetUserNames
def NOTIMPLEMENTED_testIdentify
def testGetRoles
def testGetRolesInContext
def testHasRole
def testHasLocalRole
def testHasPermission
def testHasLocalRolePermission
def NOTIMPLEMENTED_testAuthenticate
def testValidate
def testNotValidateWithoutAuth
def testValidateWithoutRoles
def testNotValidateWithEmptyRoles
def testNotValidateWithWrongRoles
def testAllowAccessToUser
def testDenyAccessToAnonymous
def testMaxListUsers
def test__doAddUser_with_not_yet_encrypted_passwords
def test__doAddUser_with_preencrypted_passwords
def test_manage_zmi_logout

Public Attributes

 uf
 doc
 basic
 maxlistusers
 users
 acl_users

Private Attributes

 __allow_groups__

Detailed Description

Definition at line 43 of file test_UserFolder.py.


Member Function Documentation

Definition at line 45 of file test_UserFolder.py.

00045 
00046     def afterSetUp(self):
00047         # Set up roles and a user
00048         self.uf = self.folder.acl_users
00049         self.folder._addRole('role1')
00050         self.folder.manage_role('role1', [View])
00051         self.uf.roles.addRole('role1')
00052         self.folder._addRole('role2')
00053         self.folder.manage_role('role2', [View])
00054         self.uf.roles.addRole('role2')
00055         self.uf._doAddUser('user1', 'secret', ['role1'], [])
00056         # Set up a published object accessible to user
00057         self.folder.addDTMLMethod('doc', file='the document')
00058         self.doc = self.folder.doc
00059         self.doc.manage_permission(View, ['role1'], acquire=0)
00060         # Rig the REQUEST so it looks like we traversed to doc
00061         self.app.REQUEST['PUBLISHED'] = self.doc
00062         self.app.REQUEST['PARENTS'] = [self.app, self.folder]
00063         self.app.REQUEST.steps = list(self.doc.getPhysicalPath())
00064         self.basic = 'Basic %s' % base64.encodestring('user1:secret').rstrip()
00065         # Make sure we are not logged in
00066         self.logout()

Definition at line 130 of file test_UserFolder.py.

00130 
00131     def NOTIMPLEMENTED_testAuthenticate(self):
00132         user = self.uf.getUser('user1')
00133         self.failUnless(user.authenticate('secret', self.app.REQUEST))

Definition at line 84 of file test_UserFolder.py.

00084 
00085     def NOTIMPLEMENTED_testGetUserNames(self):
00086         names = self.uf.getUserNames()
00087         self.failUnless(names)
00088         self.assertEqual(names[0], 'user1')

Definition at line 79 of file test_UserFolder.py.

00079 
00080     def NOTIMPLEMENTED_testGetUsers(self):
00081         users = self.uf.getUsers()
00082         self.failUnless(users)
00083         self.assertEqual(users[0].getUserName(), 'user1')

Definition at line 89 of file test_UserFolder.py.

00089 
00090     def NOTIMPLEMENTED_testIdentify(self):
00091         name, password = self.uf.identify(self.basic)
00092         self.assertEqual(name, 'user1')
00093         self.assertEqual(password, 'secret')

Definition at line 221 of file test_UserFolder.py.

00221 
00222     def test__doAddUser_with_not_yet_encrypted_passwords(self):
00223         # See collector #1869 && #1926
00224         from AccessControl.AuthEncoding import is_encrypted
00225 
00226         USER_ID = 'not_yet_encrypted'
00227         PASSWORD = 'password'
00228 
00229         self.failIf(is_encrypted(PASSWORD))
00230 
00231         self.uf._doAddUser(USER_ID, PASSWORD, [], [])
00232 
00233         uid_and_info = self.uf.users.authenticateCredentials(
00234                                 { 'login': USER_ID
00235                                 , 'password': PASSWORD
00236                                 })
00237 
00238         self.assertEqual(uid_and_info, (USER_ID, USER_ID))

Definition at line 239 of file test_UserFolder.py.

00239 
00240     def test__doAddUser_with_preencrypted_passwords(self):
00241         # See collector #1869 && #1926
00242         from AccessControl.AuthEncoding import pw_encrypt
00243 
00244         USER_ID = 'already_encrypted'
00245         PASSWORD = 'password'
00246 
00247         ENCRYPTED = pw_encrypt(PASSWORD)
00248 
00249         self.uf._doAddUser(USER_ID, ENCRYPTED, [], [])
00250 
00251         uid_and_info = self.uf.users.authenticateCredentials(
00252                                 { 'login': USER_ID
00253                                 , 'password': PASSWORD
00254                                 })
00255 
00256         self.assertEqual(uid_and_info, (USER_ID, USER_ID))

Definition at line 257 of file test_UserFolder.py.

00257 
00258     def test_manage_zmi_logout(self):
00259         request = self.app.REQUEST
00260         response = request.RESPONSE
00261         self.folder.manage_zmi_logout(request, response)
00262         self.assertEqual(response.status, 401)
00263         self.assertEqual(response.headers.get('WWW-Authenticate'),
00264                          'basic realm="%s"' % response.realm)
00265 

Definition at line 171 of file test_UserFolder.py.

00171 
00172     def testAllowAccessToUser(self):
00173         self.login('user1')
00174         try:
00175             self.folder.restrictedTraverse('doc')
00176         except Unauthorized:
00177             self.fail('Unauthorized')

Here is the call graph for this function:

Definition at line 178 of file test_UserFolder.py.

00178 
00179     def testDenyAccessToAnonymous(self):
00180         self.assertRaises(Unauthorized, self.folder.restrictedTraverse, 'doc')

Definition at line 70 of file test_UserFolder.py.

00070 
00071     def testGetBadUser(self):
00072         self.assertEqual(self.uf.getUser('user2'), None)

Definition at line 76 of file test_UserFolder.py.

00076 
00077     def testGetBadUserById(self):
00078         self.assertEqual(self.uf.getUserById('user2'), None)

Definition at line 94 of file test_UserFolder.py.

00094 
00095     def testGetRoles(self):
00096         user = self.uf.getUser('user1')
00097         self.failUnless('role1' in user.getRoles())
00098         self.failIf('role2' in user.getRoles())

Definition at line 99 of file test_UserFolder.py.

00099 
00100     def testGetRolesInContext(self):
00101         user = self.uf.getUser('user1')
00102         self.folder.manage_addLocalRoles('user1', ['role2'])
00103         roles = user.getRolesInContext(self.folder)
00104         self.failUnless('role1' in roles)
00105         self.failUnless('role2' in roles)

Here is the call graph for this function:

Definition at line 67 of file test_UserFolder.py.

00067 
00068     def testGetUser(self):
00069         self.failIfEqual(self.uf.getUser('user1'), None)

Definition at line 73 of file test_UserFolder.py.

00073 
00074     def testGetUserById(self):
00075         self.failIfEqual(self.uf.getUserById('user1'), None)

Definition at line 110 of file test_UserFolder.py.

00110 
00111     def testHasLocalRole(self):
00112         user = self.uf.getUser('user1')
00113         self.failIf(user.has_role('role2', self.folder))
00114         self.folder.manage_addLocalRoles('user1', ['role2'])
00115         self.failUnless(user.has_role('role2', self.folder))

Here is the call graph for this function:

Definition at line 123 of file test_UserFolder.py.

00123 
00124     def testHasLocalRolePermission(self):
00125         user = self.uf.getUser('user1')
00126         self.folder.manage_role('role2', [AddFolders])
00127         self.failIf(user.has_permission(AddFolders, self.folder))
00128         self.folder.manage_addLocalRoles('user1', ['role2'])
00129         self.failUnless(user.has_permission(AddFolders, self.folder))

Here is the call graph for this function:

Definition at line 116 of file test_UserFolder.py.

00116 
00117     def testHasPermission(self):
00118         user = self.uf.getUser('user1')
00119         self.failUnless(user.has_permission(View, self.folder))
00120         self.failIf(user.has_permission(AddFolders, self.folder))
00121         self.folder.manage_role('role1', [AddFolders])
00122         self.failUnless(user.has_permission(AddFolders, self.folder))

Here is the call graph for this function:

Definition at line 106 of file test_UserFolder.py.

00106 
00107     def testHasRole(self):
00108         user = self.uf.getUser('user1')
00109         self.failUnless(user.has_role('role1', self.folder))

Here is the call graph for this function:

Definition at line 181 of file test_UserFolder.py.

00181 
00182     def testMaxListUsers(self):
00183         # create a folder-ish thing which contains a roleManager,
00184         # then put an acl_users object into the folde-ish thing
00185 
00186         class Folderish(PluggableAuthService):
00187             def __init__(self, size, count):
00188                 self.maxlistusers = size
00189                 self.users = []
00190                 self.acl_users = self
00191                 self.__allow_groups__ = self
00192                 for i in xrange(count):
00193                     self.users.append("Nobody")
00194 
00195             def getUsers(self):
00196                 return self.users
00197 
00198             def user_names(self):
00199                 return self.getUsers()
00200 
00201 
00202         tinyFolderOver = Folderish(15, 20)
00203         tinyFolderUnder = Folderish(15, 10)
00204 
00205         assert tinyFolderOver.maxlistusers == 15
00206         assert tinyFolderUnder.maxlistusers == 15
00207         assert len(tinyFolderOver.user_names()) == 20
00208         assert len(tinyFolderUnder.user_names()) == 10
00209 
00210         try:
00211             list = tinyFolderOver.get_valid_userids()
00212             assert 0, "Did not raise overflow error"
00213         except OverflowError:
00214             pass
00215 
00216         try:
00217             list = tinyFolderUnder.get_valid_userids()
00218             pass
00219         except OverflowError:
00220             assert 0, "Raised overflow error erroneously"

Here is the call graph for this function:

Definition at line 159 of file test_UserFolder.py.

00159 
00160     def testNotValidateWithEmptyRoles(self):
00161         # XXX: PAS validate ignores auth argument
00162         self.app.REQUEST._auth = self.basic
00163         user = self.uf.validate(self.app.REQUEST, self.basic, [])
00164         self.assertEqual(user, None)

Definition at line 141 of file test_UserFolder.py.

00141 
00142     def testNotValidateWithoutAuth(self):
00143         # XXX: PAS validate ignores auth argument
00144         user = self.uf.validate(self.app.REQUEST, '', ['role1'])
00145         self.assertEqual(user, None)

Definition at line 165 of file test_UserFolder.py.

00165 
00166     def testNotValidateWithWrongRoles(self):
00167         # XXX: PAS validate ignores auth argument
00168         self.app.REQUEST._auth = self.basic
00169         user = self.uf.validate(self.app.REQUEST, self.basic, ['role2'])
00170         self.assertEqual(user, None)

Definition at line 134 of file test_UserFolder.py.

00134 
00135     def testValidate(self):
00136         # XXX: PAS validate ignores auth argument
00137         self.app.REQUEST._auth = self.basic
00138         user = self.uf.validate(self.app.REQUEST, self.basic, ['role1'])
00139         self.failIfEqual(user, None)
00140         self.assertEqual(user.getUserName(), 'user1')

Definition at line 146 of file test_UserFolder.py.

00146 
00147     def testValidateWithoutRoles(self):
00148         # Note - calling uf.validate without specifying roles will cause
00149         # the security machinery to determine the needed roles by looking
00150         # at the object itself (or its container). I'm putting this note
00151         # in to clarify because the original test expected failure but it
00152         # really should have expected success, since the user and the
00153         # object being checked both have the role 'role1', even though no
00154         # roles are passed explicitly to the userfolder validate method.
00155         # XXX: PAS validate ignores auth argument
00156         self.app.REQUEST._auth = self.basic
00157         user = self.uf.validate(self.app.REQUEST, self.basic)
00158         self.assertEqual(user.getUserName(), 'user1')


Member Data Documentation

Definition at line 190 of file test_UserFolder.py.

Definition at line 189 of file test_UserFolder.py.

Definition at line 63 of file test_UserFolder.py.

Definition at line 57 of file test_UserFolder.py.

Definition at line 187 of file test_UserFolder.py.

Definition at line 47 of file test_UserFolder.py.

Definition at line 188 of file test_UserFolder.py.


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