def test_authorize_asterisk_action(self): _, context, auth = self.get_basic_permission_params() pycan.can('*', context, auth) app_context = self.get_basic_context() try: pycan.authorize('foo', context, app_context) except Exception: self.fail("authorize raised UnauthorizedResourceError")
def test_authorize_sucess(self): action, context, _, get_auth_resource, load_after = self.get_full_permission_params( ) auth = lambda user, context, resource: user == 'gandalf' and context[ 'location'] == 'middle earth' pycan.can(action, context, auth, get_auth_resource, load_after) auth_resource, resource = pycan.authorize(action, context, 'gandalf', self.get_basic_context()) self.assertTrue(auth_resource) self.assertTrue(resource)
def test_revoke(self): pycan.can('a', 'b', pycan.allow_to_all) try: auth_resource, _ = pycan.authorize('a', 'b', 'gandalf', self.get_basic_context()) except Exception: self.fail("authorize raised UnauthorizedResourceError") pycan.revoke('a', 'b') self.assertRaises(pycan.exceptions.UnauthorizedResourceError, pycan.authorize, 'a', 'b', 'elrond', self.get_basic_context())