def check(permission, raw_acl, **context): # log.debug('check for %r in %s' % (permission, pformat(context))) for state, predicate, permission_set in parse_acl(raw_acl): pred_match = predicate(**context) perm_match = is_permission_in_set(permission, permission_set) if pred_match and perm_match: return state
def test_containers(self): self.assertTrue(is_permission_in_set('xxx', ('a', 'xxx', 'b'))) self.assertTrue(is_permission_in_set('xxx', ['a', 'xxx', 'b'])) self.assertTrue(is_permission_in_set('xxx', set(['a', 'xxx', 'b']))) self.assertFalse(is_permission_in_set('xxx', ('a', 'b'))) self.assertFalse(is_permission_in_set('xxx', ['a', 'b'])) self.assertFalse(is_permission_in_set('xxx', set(['a', 'b'])))
def check(permission, raw_acl, **context): # log.debug('check for %r in %s' % (permission, pformat(context))) for state, predicate, permission_set in parse_acl(raw_acl): pred_match = predicate(**context) perm_match = is_permission_in_set(permission, permission_set) # log.debug('can %s %r(%s) %r%s' % ( # 'ALLOW' if state else 'DENY', # predicate, pred_match, # permission_set, # ' -> ' + ('ALLOW' if state else 'DENY') + ' ' + permission if (pred_match and perm_match) else '', # )) if pred_match and perm_match: return state
def test_strings(self): self.assertTrue(is_permission_in_set('xxx', 'xxx')) self.assertFalse(is_permission_in_set('xxx', 'axxx')) self.assertFalse(is_permission_in_set('xxx', 'xxxb'))
def test_callables(self): self.assertTrue(is_permission_in_set('xxx', lambda p: True)) self.assertTrue(is_permission_in_set('xxx', lambda p: 'x' in p)) self.assertFalse(is_permission_in_set('xxx', lambda p: 'X' in p))