Skip to content

Commit d4e1f83

Browse files
author
Ralf Schlatterbeck
committed
Proper handling of 'Create' permissions in both mail gateway...
...(earlier commit 2009-12-07 00:13:[email protected] by Richard) and web interface, this used to check 'Edit' permission previously. See http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5133 Add regression tests for proper handling of 'Create' and 'Edit' permissions.
1 parent a015f84 commit d4e1f83

File tree

4 files changed

+99
-9
lines changed

4 files changed

+99
-9
lines changed

CHANGES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

4+
2010-XX-XX 1.4.12 (rXXXX)
5+
6+
Fixes:
7+
- Proper handling of 'Create' permissions in both mail gateway (earlier
8+
commit r4405 by Richard) and web interface, this used to check 'Edit'
9+
permission previously. See
10+
http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5133
11+
Add regression tests for proper handling of 'Create' and 'Edit'
12+
permissions.
13+
414
2009-12-21 1.4.11 (r4411)
515

616
Features:

doc/upgrading.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ steps.
1313

1414
.. contents::
1515

16+
Migrating from 1.4.x to 1.4.12
17+
==============================
18+
19+
Item creation now checks the "Create" permission instead of the "Edit"
20+
permission for individual properties. If you have modified your tracker
21+
permissions from the default distribution, you should check that
22+
"Create" permissions exist for all properties you want users to be able
23+
to create.
24+
1625
Migrating from 1.4.x to 1.4.11
1726
==============================
1827

roundup/cgi/actions.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,11 @@ def newItemPermission(self, props, classname=None):
551551
if not self.hasPermission('Create', classname=classname):
552552
return 0
553553

554-
# Check Edit permission for each property, to avoid being able
554+
# Check Create permission for each property, to avoid being able
555555
# to set restricted ones on new item creation
556556
for key in props:
557-
if not self.hasPermission('Edit', classname=classname,
557+
if not self.hasPermission('Create', classname=classname,
558558
property=key):
559-
# We restrict by default and special-case allowed properties
560-
if key == 'date' or key == 'content':
561-
continue
562-
elif key == 'author' and props[key] == self.userid:
563-
continue
564559
return 0
565560
return 1
566561

test/test_cgi.py

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,13 @@ def _make_client(self, form, classname='user', nodeid='1', userid='2'):
620620
cl = client.Client(self.instance, None, {'PATH_INFO':'/',
621621
'REQUEST_METHOD':'POST'}, makeForm(form))
622622
cl.classname = 'user'
623-
cl.nodeid = nodeid
623+
if nodeid is not None:
624+
cl.nodeid = nodeid
624625
cl.db = self.db
625626
cl.userid = userid
626627
cl.language = ('en',)
628+
cl.error_message = []
629+
cl.template = 'item'
627630
return cl
628631

629632
def testClassPermission(self):
@@ -636,18 +639,91 @@ def testClassPermission(self):
636639

637640
def testCheckAndPropertyPermission(self):
638641
self.db.security.permissions = {}
639-
def own_record(db, userid, itemid): return userid == itemid
642+
def own_record(db, userid, itemid):
643+
return userid == itemid
640644
p = self.db.security.addPermission(name='Edit', klass='user',
641645
check=own_record, properties=("password", ))
642646
self.db.security.addPermissionToRole('User', p)
643647

644648
cl = self._make_client(dict(username='bob'))
645649
self.assertRaises(exceptions.Unauthorised,
646650
actions.EditItemAction(cl).handle)
651+
cl = self._make_client(dict(roles='User,Admin'), userid='4', nodeid='4')
652+
self.assertRaises(exceptions.Unauthorised,
653+
actions.EditItemAction(cl).handle)
654+
cl = self._make_client(dict(roles='User,Admin'), userid='4')
655+
self.assertRaises(exceptions.Unauthorised,
656+
actions.EditItemAction(cl).handle)
657+
cl = self._make_client(dict(roles='User,Admin'))
658+
self.assertRaises(exceptions.Unauthorised,
659+
actions.EditItemAction(cl).handle)
660+
# working example, mary may change her pw
661+
cl = self._make_client({'password':'ob', '@confirm@password':'ob'},
662+
nodeid='4', userid='4')
663+
self.assertRaises(exceptions.Redirect,
664+
actions.EditItemAction(cl).handle)
647665
cl = self._make_client({'password':'bob', '@confirm@password':'bob'})
648666
self.failUnlessRaises(exceptions.Unauthorised,
649667
actions.EditItemAction(cl).handle)
650668

669+
def testCreatePermission(self):
670+
# this checks if we properly differentiate between create and
671+
# edit permissions
672+
self.db.security.permissions = {}
673+
self.db.security.addRole(name='UserAdd')
674+
# Don't allow roles
675+
p = self.db.security.addPermission(name='Create', klass='user',
676+
properties=("username", "password", "address",
677+
"alternate_address", "realname", "phone", "organisation",
678+
"timezone"))
679+
self.db.security.addPermissionToRole('UserAdd', p)
680+
# Don't allow roles *and* don't allow username
681+
p = self.db.security.addPermission(name='Edit', klass='user',
682+
properties=("password", "address", "alternate_address",
683+
"realname", "phone", "organisation", "timezone"))
684+
self.db.security.addPermissionToRole('UserAdd', p)
685+
self.db.user.set('4', roles='UserAdd')
686+
687+
# anonymous may not
688+
cl = self._make_client({'username':'new_user', 'password':'secret',
689+
'@confirm@password':'secret', 'address':'[email protected]',
690+
'roles':'Admin'}, nodeid=None, userid='2')
691+
self.assertRaises(exceptions.Unauthorised,
692+
actions.NewItemAction(cl).handle)
693+
# Don't allow creating new user with roles
694+
cl = self._make_client({'username':'new_user', 'password':'secret',
695+
'@confirm@password':'secret', 'address':'[email protected]',
696+
'roles':'Admin'}, nodeid=None, userid='4')
697+
self.assertRaises(exceptions.Unauthorised,
698+
actions.NewItemAction(cl).handle)
699+
self.assertEqual(cl.error_message,[])
700+
# this should work
701+
cl = self._make_client({'username':'new_user', 'password':'secret',
702+
'@confirm@password':'secret', 'address':'[email protected]'},
703+
nodeid=None, userid='4')
704+
self.assertRaises(exceptions.Redirect,
705+
actions.NewItemAction(cl).handle)
706+
self.assertEqual(cl.error_message,[])
707+
# don't allow changing (my own) username (in this example)
708+
cl = self._make_client(dict(username='new_user42'), userid='4')
709+
self.assertRaises(exceptions.Unauthorised,
710+
actions.EditItemAction(cl).handle)
711+
cl = self._make_client(dict(username='new_user42'), userid='4',
712+
nodeid='4')
713+
self.assertRaises(exceptions.Unauthorised,
714+
actions.EditItemAction(cl).handle)
715+
# don't allow changing (my own) roles
716+
cl = self._make_client(dict(roles='User,Admin'), userid='4',
717+
nodeid='4')
718+
self.assertRaises(exceptions.Unauthorised,
719+
actions.EditItemAction(cl).handle)
720+
cl = self._make_client(dict(roles='User,Admin'), userid='4')
721+
self.assertRaises(exceptions.Unauthorised,
722+
actions.EditItemAction(cl).handle)
723+
cl = self._make_client(dict(roles='User,Admin'))
724+
self.assertRaises(exceptions.Unauthorised,
725+
actions.EditItemAction(cl).handle)
726+
651727
def testRoles(self):
652728
cl = self._make_client({})
653729
self.db.user.set('1', roles='aDmin, uSer')

0 commit comments

Comments
 (0)