Skip to content

Commit 8f9b5ee

Browse files
committed
bug: Fix roundup-admin security command. Lowercase optionalarg.
Roles are indexed by lower case role name. So 'security User' and 'security user' should generate the same output. Also add testing for this case. Thread: https://sourceforge.net/p/roundup/mailman/roundup-users/thread/CAH-41398iTPhze7D_pZB8tqTBHF%3Dq6HYonbcG%2B%2BYN-ioDssXBw%40mail.gmail.com/#msg41557225 starting from: https://sourceforge.net/p/roundup/mailman/message/41557225/
1 parent 0c7cf54 commit 8f9b5ee

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Fixed:
5050
- issue2551293 - remove schema_hook from Tracker instance. Looks like
5151
it was an obsolete hook used for testing. Never documented and not
5252
accessible from schema.py.
53+
- Fix roundup-admin security command. Lowercase its optional
54+
argument. Roles are indexed by lower case role name. So 'security
55+
User' and 'security user' should generate the same output. (John
56+
Rouillard from issue on mailing list by Chuck Cunningham)
5357

5458
Features:
5559

roundup/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,8 @@ def do_security(self, args):
17151715
if len(args) == 1:
17161716
role = args[0]
17171717
try:
1718-
roles = [(args[0], self.db.security.role[args[0]])]
1718+
roles = [(args[0].lower(),
1719+
self.db.security.role[args[0].lower()])]
17191720
except KeyError:
17201721
sys.stdout.write(_('No such Role "%(role)s"\n') % locals())
17211722
return 1

test/test_admin.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,77 @@ def disabletestHelpInitopts(self):
11641164
self.assertTrue(expected[0] in out)
11651165
self.assertTrue("Back ends:" in out)
11661166

1167-
def testSecurity(self):
1167+
def testSecurityListOne(self):
1168+
self.install_init()
1169+
self.admin=AdminTool()
1170+
1171+
with captured_output() as (out, err):
1172+
# make sure UsEr returns result for user. Roles are
1173+
# lower cased interally
1174+
sys.argv=['main', '-i', self.dirname, 'security', "user" ]
1175+
ret = self.admin.main()
1176+
1177+
result = """Role "user":
1178+
User may access the web interface (Web Access)
1179+
User may use the email interface (Email Access)
1180+
User may access the rest interface (Rest Access)
1181+
User may access the xmlrpc interface (Xmlrpc Access)
1182+
User is allowed to access issue (View for "issue" only)
1183+
User is allowed to edit issue (Edit for "issue" only)
1184+
User is allowed to create issue (Create for "issue" only)
1185+
User is allowed to access file (View for "file" only)
1186+
User is allowed to edit file (Edit for "file" only)
1187+
User is allowed to create file (Create for "file" only)
1188+
User is allowed to access msg (View for "msg" only)
1189+
User is allowed to edit msg (Edit for "msg" only)
1190+
User is allowed to create msg (Create for "msg" only)
1191+
User is allowed to access keyword (View for "keyword" only)
1192+
User is allowed to edit keyword (Edit for "keyword" only)
1193+
User is allowed to create keyword (Create for "keyword" only)
1194+
User is allowed to access priority (View for "priority" only)
1195+
User is allowed to access status (View for "status" only)
1196+
(View for "user": ('id', 'organisation', 'phone', 'realname', 'timezone', 'username') only)
1197+
User is allowed to view their own user details (View for "user" only)
1198+
User is allowed to edit their own user details (Edit for "user": ('username', 'password', 'address', 'realname', 'phone', 'organisation', 'alternate_addresses', 'queries', 'timezone') only)
1199+
User is allowed to view their own and public queries (View for "query" only)
1200+
(Search for "query" only)
1201+
User is allowed to edit their queries (Edit for "query" only)
1202+
User is allowed to retire their queries (Retire for "query" only)
1203+
User is allowed to restore their queries (Restore for "query" only)
1204+
User is allowed to create queries (Create for "query" only)
1205+
"""
1206+
print(out.getvalue())
1207+
1208+
self.assertEqual(result, out.getvalue())
1209+
self.assertEqual(ret, 0)
1210+
1211+
1212+
# test 2 all role names are lower case, make sure
1213+
# any role name is correctly lower cased
1214+
self.admin=AdminTool()
1215+
with captured_output() as (out, err):
1216+
sys.argv=['main', '-i', self.dirname, 'security', "UsEr" ]
1217+
ret = self.admin.main()
1218+
1219+
print(out.getvalue())
1220+
1221+
self.assertEqual(result, out.getvalue())
1222+
self.assertEqual(ret, 0)
1223+
1224+
# test 3 Check error if role does not exist
1225+
self.admin=AdminTool()
1226+
with captured_output() as (out, err):
1227+
sys.argv=['main', '-i', self.dirname, 'security', "NoSuch Role" ]
1228+
ret = self.admin.main()
1229+
1230+
result='No such Role "NoSuch Role"\n'
1231+
print('>', out.getvalue())
1232+
1233+
self.assertEqual(result, out.getvalue())
1234+
self.assertEqual(ret, 1)
1235+
1236+
1237+
def testSecurityListAll(self):
11681238
''' Note the tests will fail if you run this under pdb.
11691239
the context managers capture the pdb prompts and this screws
11701240
up the stdout strings with (pdb) prefixed to the line.

0 commit comments

Comments
 (0)