def test19_search_perms(self): """ Search for perms that match the characters passed into with wildcard appended. Will return zero or more records, one for each user in result set. """ print_test_name() try: perms = review.find_perms(Perm(obj_name='ShoppingCart*', op_name='*')) for perm in perms: print_perm(perm) except RbacError as e: print_exception(e) self.fail()
def process_perm(args): perm = load_entity(Perm(), args) print(args.entity + ' ' + args.operation) if args.operation == ADD: admin.add_perm(perm) elif args.operation == UPDATE: admin.update_perm(perm) elif args.operation == DELETE: admin.delete_perm(perm) elif args.operation == GRANT: role_nm = args.role print('role=' + role_nm) admin.grant(perm, Role(name=role_nm)) elif args.operation == REVOKE: role_nm = args.role print('role=' + role_nm) admin.revoke(perm, Role(name=role_nm)) elif args.operation == READ: print_entity(review.read_perm(perm), perm.obj_name + '.' + perm.op_name) pass elif args.operation == SEARCH: role_nm = args.role userid = args.uid prms = [] label = '' if userid: label = userid prms = review.user_perms(User(uid=userid)) elif role_nm: label = role_nm prms = review.role_perms(Role(name=role_nm)) else: if perm.obj_name: perm.obj_name += '*' else: perm.obj_name = '*' if perm.op_name: perm.op_name += '*' else: perm.op_name = '*' label = perm.obj_name + '.' + perm.op_name prms = review.find_perms(perm) if len(prms) > 0: for idx, prm in enumerate(prms): print_entity(prm, label + ':' + str(idx)) else: print_ln('No matching records found matching filter: ' + label) else: print('process_perm failed, invalid operation=' + args.operation) return False return True
def test02_delete_perm(self): """ Test the perm delete object method """ print_ln('test_delete_perm') try: pList = review.find_perms(Perm(obj_name='py-obj*', op_name='*')) for perm in pList: entity = admin.delete_perm(perm) print_ln("Delete Perm obj name=" + entity.obj_name + ', op=' + entity.op_name + ', id=' + entity.obj_id) except Exception as e: self.fail('test_delete_perm failed, exception=' + e.msg)
def test01_revoke(self): """ Test the revoke method """ print_ln('test_revoke') try: pList = review.find_perms(Perm(obj_name='py-obj*', op_name='*')) rles = role_test_data.get_test_roles('py-role', 10) for perm in pList: for rle in rles: admin.revoke(perm, rle) print_ln("Revoke Perm obj name=" + perm.obj_name + ', op=' + perm.op_name + ', id=' + perm.obj_id + ', Role=' + rle.name) except Exception as e: pass
def test03_perm_roles(self): """ Test the perm roles method """ print_ln('test16_perm_roles') try: pList = review.find_perms(Perm(obj_name='py-obj*', op_name='*')) for perm in pList: print_ln("Role Perm obj name=" + perm.obj_name + ', op=' + perm.op_name + ', id=' + perm.obj_id) rList = review.perm_roles(perm) for role in rList: print_ln("Assigned role=" + role, 1) except Exception as e: self.fail('test16_perm_roles failed, exception=' + e.msg)
def test06_perm_users(self): """ Test the perm users method """ print_ln('test_perm_users') try: pList = review.find_perms(Perm(obj_name='py-obj*', op_name='*')) for perm in pList: print_ln("Perm obj name=" + perm.obj_name + ', op=' + perm.op_name + ', id=' + perm.obj_id) uList = review.perm_users(perm) for user in uList: print_ln("Assigned user=" + user.uid, 1) except Exception as e: self.fail('test_perm_users failed, exception=' + e.msg)