Skip to content

Commit a4bccec

Browse files
author
Richard Jones
committed
Fix some security assertions and tests.
Fix some security assertions in mailgw to only assert Edit permissions if the user is editing an existing db node. If not then check Create. Fix some tests that were broken by the new assertions, the Create -> Register change and finally for the new "not registered" message.
1 parent f3884c7 commit a4bccec

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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-
2009-XX-XX 1.4.XX (rXXXX)
4+
2009-12-XX 1.4.11 (rXXXX)
55

66
Features:
77
- Generic class editor may now restore retired items (thanks Ralf Hemmecke)

roundup/mailgw.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,8 @@ def pgp_role():
12961296
#
12971297
# handle the attachments
12981298
#
1299-
if properties.has_key('files'):
1300-
files = []
1299+
files = []
1300+
if attachments and properties.has_key('files'):
13011301
for (name, mime_type, data) in attachments:
13021302
if not self.db.security.hasPermission('Create', author, 'file'):
13031303
raise Unauthorized, _(
@@ -1311,8 +1311,8 @@ def pgp_role():
13111311
pass
13121312
else:
13131313
files.append(fileid)
1314-
# attach the files to the issue
1315-
if not self.db.security.hasPermission('Edit', author,
1314+
# allowed to attach the files to an existing node?
1315+
if nodeid and not self.db.security.hasPermission('Edit', author,
13161316
classname, 'files'):
13171317
raise Unauthorized, _(
13181318
'You are not permitted to add files to %(classname)s.'
@@ -1345,8 +1345,8 @@ def pgp_role():
13451345
Mail message was rejected by a detector.
13461346
%(error)s
13471347
""") % locals()
1348-
# attach the message to the node
1349-
if not self.db.security.hasPermission('Edit', author,
1348+
# allowed to attach the message to the existing node?
1349+
if nodeid and not self.db.security.hasPermission('Edit', author,
13501350
classname, 'messages'):
13511351
raise Unauthorized, _(
13521352
'You are not permitted to add messages to %(classname)s.'
@@ -1372,16 +1372,21 @@ def pgp_role():
13721372
if not props.has_key(prop) :
13731373
props[prop] = issue_props[prop]
13741374

1375-
# Check permissions for each property
1376-
for prop in props.keys():
1377-
if not self.db.security.hasPermission('Edit', author,
1378-
classname, prop):
1379-
raise Unauthorized, _('You are not permitted to edit '
1380-
'property %(prop)s of class %(classname)s.') % locals()
1381-
13821375
if nodeid:
1376+
# Check permissions for each property
1377+
for prop in props.keys():
1378+
if not self.db.security.hasPermission('Edit', author,
1379+
classname, prop):
1380+
raise Unauthorized, _('You are not permitted to edit '
1381+
'property %(prop)s of class %(classname)s.') % locals()
13831382
cl.set(nodeid, **props)
13841383
else:
1384+
# Check permissions for each property
1385+
for prop in props.keys():
1386+
if not self.db.security.hasPermission('Create', author,
1387+
classname, prop):
1388+
raise Unauthorized, _('You are not permitted to set '
1389+
'property %(prop)s of class %(classname)s.') % locals()
13851390
nodeid = cl.create(**props)
13861391
except (TypeError, IndexError, ValueError, exceptions.Reject), message:
13871392
raise MailUsageError, _("""

test/db_test_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ def setupSchema(db, create, module):
113113
priority.create(name="bug", order="1")
114114
db.commit()
115115

116+
# nosy tests require this
117+
db.security.addPermissionToRole('User', 'View', 'msg')
118+
116119
class MyTestCase(unittest.TestCase):
117120
def tearDown(self):
118121
if hasattr(self, 'db'):

test/test_mailgw.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def hook (db, **kw):
10461046
# Add Web Access role to anonymous, and try again to make sure
10471047
# we get a "please register at:" message this time.
10481048
p = [
1049-
db.security.getPermission('Create', 'user'),
1049+
db.security.getPermission('Register', 'user'),
10501050
db.security.getPermission('Web Access', None),
10511051
]
10521052
db.security.role['anonymous'].permissions=p
@@ -1078,7 +1078,7 @@ def hook (db, **kw):
10781078
''' set up callback for db open '''
10791079
# now with the permission
10801080
p = [
1081-
db.security.getPermission('Create', 'user'),
1081+
db.security.getPermission('Register', 'user'),
10821082
db.security.getPermission('Email Access', None),
10831083
]
10841084
db.security.role['anonymous'].permissions=p
@@ -1088,7 +1088,7 @@ def hook (db, **kw):
10881088
m.sort()
10891089
self.assertNotEqual(l, m)
10901090

1091-
def testNewUserAuthorHighBit(self):
1091+
def testNewUserAuthorEncodedName(self):
10921092
l = set(self.db.user.list())
10931093
# From: name has Euro symbol in it
10941094
message = '''Content-Type: text/plain;
@@ -1103,10 +1103,12 @@ def testNewUserAuthorHighBit(self):
11031103
def hook (db, **kw):
11041104
''' set up callback for db open '''
11051105
p = [
1106-
db.security.getPermission('Create', 'user'),
1106+
db.security.getPermission('Register', 'user'),
11071107
db.security.getPermission('Email Access', None),
1108+
db.security.getPermission('Create', 'issue'),
1109+
db.security.getPermission('Create', 'msg'),
11081110
]
1109-
db.security.role['anonymous'].permissions=p
1111+
db.security.role['anonymous'].permissions = p
11101112
self.instance.schema_hook = hook
11111113
self._handle_mail(message)
11121114
m = set(self.db.user.list())
@@ -1153,7 +1155,11 @@ def testUnknownUser(self):
11531155
11541156
11551157
1156-
You are not a registered user.
1158+
You are not a registered user. Please register at:
1159+
1160+
http://tracker.example/cgi-bin/roundup.cgi/bugs/user?template=register
1161+
1162+
...before sending mail to the tracker.
11571163
11581164
Unknown address: [email protected]
11591165

0 commit comments

Comments
 (0)