Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
5ca49ca4
Commit
5ca49ca4
authored
Jan 30, 2004
by
Stefan H. Holek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the new user folder tests to HEAD as well. Please see
http://zope.org/Collectors/Zope/1210
parent
65e36a70
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
11 deletions
+148
-11
lib/python/AccessControl/tests/testUserFolder.py
lib/python/AccessControl/tests/testUserFolder.py
+148
-11
No files found.
lib/python/AccessControl/tests/testUserFolder.py
View file @
5ca49ca4
...
...
@@ -13,18 +13,155 @@
"""User folder tests
"""
__rcs_id__
=
'$Id: testUserFolder.py,v 1.
7 2003/01/21 02:58:58 chrism
Exp $'
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: testUserFolder.py,v 1.
8 2004/01/30 14:00:32 shh
Exp $'
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
import
os
,
sys
,
unittest
import
os
,
sys
,
base64
,
unittest
from
Testing.makerequest
import
makerequest
import
Zope
Zope
.
startup
()
from
AccessControl
import
Unauthorized
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
noSecurityManager
from
AccessControl.User
import
BasicUserFolder
from
AccessControl.User
import
User
# XXX: Uncomment to enforce C implementation
#from AccessControl.SecurityManager import setSecurityPolicy
#from AccessControl.cAccessControl import ZopeSecurityPolicy
#setSecurityPolicy(ZopeSecurityPolicy(True, True))
import
ZODB
from
AccessControl
import
User
,
Unauthorized
from
AccessControl.User
import
BasicUserFolder
,
UserFolder
,
User
from
ExtensionClass
import
Base
class
UserFolderTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
get_transaction
().
begin
()
self
.
app
=
makerequest
(
Zope
.
app
())
try
:
# Set up a user and role
self
.
uf
=
self
.
app
.
acl_users
self
.
uf
.
_doAddUser
(
'user1'
,
'secret'
,
[
'role1'
],
[])
self
.
app
.
_addRole
(
'role1'
)
self
.
app
.
manage_role
(
'role1'
,
[
'View'
])
# Set up a published object accessible to user
self
.
app
.
addDTMLMethod
(
'doc'
,
file
=
''
)
self
.
app
.
doc
.
manage_permission
(
'View'
,
[
'role1'
],
acquire
=
0
)
# Rig the REQUEST so it looks like we traversed to doc
self
.
app
.
REQUEST
.
set
(
'PUBLISHED'
,
self
.
app
.
doc
)
self
.
app
.
REQUEST
.
set
(
'PARENTS'
,
[
self
.
app
])
self
.
app
.
REQUEST
.
steps
=
[
'doc'
]
self
.
basic
=
'Basic %s'
%
base64
.
encodestring
(
'user1:secret'
)
except
:
self
.
tearDown
()
raise
def
tearDown
(
self
):
noSecurityManager
()
get_transaction
().
abort
()
self
.
app
.
_p_jar
.
close
()
def
login
(
self
,
name
):
user
=
self
.
uf
.
getUserById
(
name
)
user
=
user
.
__of__
(
self
.
uf
)
newSecurityManager
(
None
,
user
)
def
testGetUser
(
self
):
self
.
failIfEqual
(
self
.
uf
.
getUser
(
'user1'
),
None
)
def
testGetBadUser
(
self
):
self
.
assertEqual
(
self
.
uf
.
getUser
(
'user2'
),
None
)
def
testGetUserById
(
self
):
self
.
failIfEqual
(
self
.
uf
.
getUserById
(
'user1'
),
None
)
def
testGetBadUserById
(
self
):
self
.
assertEqual
(
self
.
uf
.
getUserById
(
'user2'
),
None
)
def
testGetUsers
(
self
):
users
=
self
.
uf
.
getUsers
()
self
.
failUnless
(
users
)
self
.
assertEqual
(
users
[
0
].
getUserName
(),
'user1'
)
def
testGetUserNames
(
self
):
names
=
self
.
uf
.
getUserNames
()
self
.
failUnless
(
names
)
self
.
assertEqual
(
names
[
0
],
'user1'
)
def
testIdentify
(
self
):
name
,
password
=
self
.
uf
.
identify
(
self
.
basic
)
self
.
assertEqual
(
name
,
'user1'
)
self
.
assertEqual
(
password
,
'secret'
)
def
testGetRoles
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
failUnless
(
'role1'
in
user
.
getRoles
())
def
testGetRolesInContext
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
app
.
manage_addLocalRoles
(
'user1'
,
[
'Owner'
])
roles
=
user
.
getRolesInContext
(
self
.
app
)
self
.
failUnless
(
'role1'
in
roles
)
self
.
failUnless
(
'Owner'
in
roles
)
def
testHasRole
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
failUnless
(
user
.
has_role
(
'role1'
,
self
.
app
))
def
testHasLocalRole
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
app
.
manage_addLocalRoles
(
'user1'
,
[
'Owner'
])
self
.
failUnless
(
user
.
has_role
(
'Owner'
,
self
.
app
))
def
testHasPermission
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
failUnless
(
user
.
has_permission
(
'View'
,
self
.
app
))
self
.
app
.
manage_role
(
'role1'
,
[
'Add Folders'
])
self
.
failUnless
(
user
.
has_permission
(
'Add Folders'
,
self
.
app
))
def
testHasLocalRolePermission
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
app
.
manage_role
(
'Owner'
,
[
'Add Folders'
])
self
.
app
.
manage_addLocalRoles
(
'user1'
,
[
'Owner'
])
self
.
failUnless
(
user
.
has_permission
(
'Add Folders'
,
self
.
app
))
def
testAuthenticate
(
self
):
user
=
self
.
uf
.
getUser
(
'user1'
)
self
.
failUnless
(
user
.
authenticate
(
'secret'
,
self
.
app
.
REQUEST
))
def
testValidate
(
self
):
user
=
self
.
uf
.
validate
(
self
.
app
.
REQUEST
,
self
.
basic
,
[
'role1'
])
self
.
failIfEqual
(
user
,
None
)
self
.
assertEqual
(
user
.
getUserName
(),
'user1'
)
def
testNotValidateWithoutAuth
(
self
):
user
=
self
.
uf
.
validate
(
self
.
app
.
REQUEST
,
''
,
[
'role1'
])
self
.
assertEqual
(
user
,
None
)
def
testNotValidateWithoutRoles
(
self
):
user
=
self
.
uf
.
validate
(
self
.
app
.
REQUEST
,
self
.
basic
)
self
.
assertEqual
(
user
,
None
)
def
testNotValidateWithEmptyRoles
(
self
):
user
=
self
.
uf
.
validate
(
self
.
app
.
REQUEST
,
self
.
basic
,
[])
self
.
assertEqual
(
user
,
None
)
def
testNotValidateWithWrongRoles
(
self
):
user
=
self
.
uf
.
validate
(
self
.
app
.
REQUEST
,
self
.
basic
,
[
'Manager'
])
self
.
assertEqual
(
user
,
None
)
def
testAllowAccessToUser
(
self
):
self
.
login
(
'user1'
)
try
:
self
.
app
.
restrictedTraverse
(
'doc'
)
except
Unauthorized
:
self
.
fail
(
'Unauthorized'
)
def
testDenyAccessToAnonymous
(
self
):
self
.
assertRaises
(
Unauthorized
,
self
.
app
.
restrictedTraverse
,
'doc'
)
def
testMaxListUsers
(
self
):
# create a folder-ish thing which contains a roleManager,
# then put an acl_users object into the folde-ish thing
...
...
@@ -65,6 +202,7 @@ class UserFolderTests(unittest.TestCase):
except
OverflowError
:
assert
0
,
"Raised overflow error erroneously"
class
UserTests
(
unittest
.
TestCase
):
def
testGetUserName
(
self
):
...
...
@@ -93,14 +231,13 @@ class UserTests(unittest.TestCase):
f
=
User
(
'chris'
,
'123'
,
[
'Manager'
],
[])
self
.
assertEqual
(
f
.
getDomains
(),
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UserFolderTests
))
suite
.
addTest
(
unittest
.
makeSuite
(
UserTests
))
return
suite
def
main
():
unittest
.
TextTestRunner
().
run
(
test_suite
())
if
__name__
==
'__main__'
:
main
()
unittest
.
main
(
defaultTest
=
'test_suite'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment