def test_equal(self): xproto = """ policy output < not (ctx.user = obj.user) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec( output ) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i2 = (ctx.user == obj.user) i1 = (not i2) if (not i1): raise Exception('Necessary Failure') """ obj = FakeObject() obj.user = 1 ctx = FakeObject() ctx.user = 1 with self.assertRaises(Exception): policy_output_validator(obj, ctx)
def test_equal(self): xproto = """ policy output < not (ctx.user = obj.user) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i2 = (ctx.user == obj.user) i1 = (not i2) if (not i1): raise Exception('Necessary Failure') """ obj = FakeObject() obj.user = 1 ctx = FakeObject() ctx.user = 1 with self.assertRaises(Exception): policy_output_validator(obj, ctx)
def test_call_policy(self): xproto = """ policy sub_policy < ctx.user = obj.user > policy output < *sub_policy(child) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output, globals( )) # This loads the generated function, which should look like this: """ def policy_sub_policy_validator(obj, ctx): i1 = (ctx.user == obj.user) if (not i1): raise ValidationError('Necessary Failure') def policy_output_validator(obj, ctx): i1 = policy_sub_policy_validator(obj.child, ctx) if (not i1): raise ValidationError('Necessary Failure') """ obj = FakeObject() obj.child = FakeObject() obj.child.user = 1 ctx = FakeObject() ctx.user = 1 with self.assertRaises(Exception): verdict = policy_output_enforcer(obj, ctx)
def test_call_policy(self): xproto = """ policy sub_policy < ctx.user = obj.user > policy output < *sub_policy(child) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output, globals()) # This loads the generated function, which should look like this: """ def sub_policy_security_check(obj, ctx): i1 = (ctx.user == obj.user) return i1 def output_security_check(obj, ctx): if obj.child: i1 = sub_policy_security_check(obj.child, ctx) else: i1 = True return i1 """ obj = FakeObject() obj.child = FakeObject() obj.child.user = 1 ctx = FakeObject() ctx.user = 1 verdict = output_security_check(obj, ctx) self.assertTrue(verdict)
def test_call_policy(self): xproto = """ policy sub_policy < ctx.user = obj.user > policy output < *sub_policy(child) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec( output, globals() ) # This loads the generated function, which should look like this: """ def policy_sub_policy_validator(obj, ctx): i1 = (ctx.user == obj.user) if (not i1): raise ValidationError('Necessary Failure') def policy_output_validator(obj, ctx): i1 = policy_sub_policy_validator(obj.child, ctx) if (not i1): raise ValidationError('Necessary Failure') """ obj = FakeObject() obj.child = FakeObject() obj.child.user = 1 ctx = FakeObject() ctx.user = 1 with self.assertRaises(Exception): verdict = policy_output_enforcer(obj, ctx)
def test_call_policy(self): xproto = """ policy sub_policy < ctx.user = obj.user > policy output < *sub_policy(child) > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output, globals( )) # This loads the generated function, which should look like this: """ def sub_policy_security_check(obj, ctx): i1 = (ctx.user == obj.user) return i1 def output_security_check(obj, ctx): if obj.child: i1 = sub_policy_security_check(obj.child, ctx) else: i1 = True return i1 """ obj = FakeObject() obj.child = FakeObject() obj.child.user = 1 ctx = FakeObject() ctx.user = 1 verdict = output_security_check(obj, ctx) self.assertTrue(verdict)
def test_equal(self): xproto = """ policy slice_user < slice.user = obj.user > """ target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = "******" obj = FakeObject() obj.user = "******" (op, operands), = eval(output).items() expr = op.join(operands).replace("=", "==") self.assertTrue(eval(expr))
def test_equal(self): xproto = """ policy output < ctx.user = obj.user > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output, globals( )) # This loads the generated function, which should look like this: """ def output_security_check(obj, ctx): i1 = (ctx.user == obj.user) return i1 """ obj = FakeObject() obj.user = 1 ctx = FakeObject() ctx.user = 1 verdict = output_security_check(obj, ctx)
def test_equal(self): xproto = """ policy output < ctx.user = obj.user > """ args = XOSProcessorArgs(inputs=xproto, target=self.target) output = XOSProcessor.process(args) exec(output, globals()) # This loads the generated function, which should look like this: """ def output_security_check(obj, ctx): i1 = (ctx.user == obj.user) return i1 """ obj = FakeObject() obj.user = 1 ctx = FakeObject() ctx.user = 1 verdict = output_security_check(obj, ctx)
def test_equal(self): xproto = """ policy slice_user < slice.user = obj.user > """ target = XProtoTestHelpers.write_tmp_target( "{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = "******" obj = FakeObject() obj.user = "******" (op, operands), = eval(output).items() expr = op.join(operands).replace("=", "==") self.assertTrue(eval(expr))
def test_num_constant(self): xproto = """ policy slice_user < slice.user.age = 57 > """ target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = FakeObject() slice.user.is_admin = True expr = eval(output) self.assertTrue(expr)
def test_function_term(self): xproto = """ policy slice_user < slice.user.compute_is_admin() > """ target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = FakeObject() slice.user.compute_is_admin = lambda: True expr = eval(output) self.assertTrue(expr)
def test_num_constant(self): xproto = """ policy slice_user < slice.user.age = 57 > """ target = XProtoTestHelpers.write_tmp_target( "{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = FakeObject() slice.user.is_admin = True expr = eval(output) self.assertTrue(expr)
def test_function_term(self): xproto = """ policy slice_user < slice.user.compute_is_admin() > """ target = XProtoTestHelpers.write_tmp_target( "{{ proto.policies.slice_user }}") args = XOSProcessorArgs() args.inputs = xproto args.target = target output = XOSProcessor.process(args) slice = FakeObject() slice.user = FakeObject() slice.user.compute_is_admin = lambda: True expr = eval(output) self.assertTrue(expr)