Skip to content

Commit 0297f30

Browse files
author
Richard Jones
committed
add tests for through-the-web permission checking
1 parent 92457cc commit 0297f30

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

test/test_cgi.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_cgi.py,v 1.32 2007-09-16 02:45:11 jpend Exp $
11+
# $Id: test_cgi.py,v 1.33 2007-10-05 03:07:14 richard Exp $
1212

1313
import unittest, os, shutil, errno, sys, difflib, cgi, re
1414

15-
from roundup.cgi import client
15+
from roundup.cgi import client, actions, exceptions
1616
from roundup.cgi.exceptions import FormError
1717
from roundup.cgi.templating import HTMLItem
1818
from roundup.cgi.form_parser import FormParser
@@ -595,6 +595,41 @@ def testBackwardsCompat(self):
595595
'name': 'foo.txt', 'type': 'text/plain'}},
596596
[('issue', None, 'files', [('file', '-1')])]))
597597

598+
#
599+
# SECURITY
600+
#
601+
# XXX test all default permissions
602+
def _make_client(self, form, classname='user', nodeid='2', userid='2'):
603+
cl = client.Client(self.instance, None, {'PATH_INFO':'/'},
604+
makeForm(form))
605+
cl.classname = 'user'
606+
cl.nodeid = '1'
607+
cl.db = self.db
608+
cl.userid = '2'
609+
return cl
610+
611+
def testClassPermission(self):
612+
cl = self._make_client(dict(username='bob'))
613+
self.failUnlessRaises(exceptions.Unauthorised,
614+
actions.EditItemAction(cl).handle)
615+
cl.nodeid = '1'
616+
self.assertRaises(exceptions.Unauthorised,
617+
actions.EditItemAction(cl).handle)
618+
619+
def testCheckAndPropertyPermission(self):
620+
self.db.security.permissions = {}
621+
def own_record(db, userid, itemid): return userid == itemid
622+
p = self.db.security.addPermission(name='Edit', klass='user',
623+
check=own_record, properties=("password", ))
624+
self.db.security.addPermissionToRole('User', p)
625+
626+
cl = self._make_client(dict(username='bob'))
627+
self.assertRaises(exceptions.Unauthorised,
628+
actions.EditItemAction(cl).handle)
629+
cl = self._make_client({'password':'bob', '@confirm@password':'bob'})
630+
self.failUnlessRaises(exceptions.Unauthorised,
631+
actions.EditItemAction(cl).handle)
632+
598633
def test_suite():
599634
suite = unittest.TestSuite()
600635
suite.addTest(unittest.makeSuite(FormTestCase))

0 commit comments

Comments
 (0)