def test_slice_name_validation(self): xproto = """ policy test_policy < not obj.id -> {{ obj.name.startswith(obj.site.login_base) }} > """ args = XOSProcessorArgs() args.inputs = xproto args.target = self.target output = XOSProcessor.process(args) obj = FakeObject() obj.isolation = "container" obj.kind = "not a container" exec(output) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i3 = obj.id i4 = obj.name.startswith(obj.site.login_base) i2 = ((not i3) or i4) i1 = (not i2) if (not i1): raise ValidationError('Necessary Failure') """ with self.assertRaises(Exception): policy_output_validator(obj, {})
def test_slice_name_validation(self): xproto = """ policy test_policy < not obj.id -> {{ obj.name.startswith(obj.site.login_base) }} > """ args = XOSProcessorArgs() args.inputs = xproto args.target = self.target output = XOSProcessor.process(args) obj = FakeObject() obj.isolation = "container" obj.kind = "not a container" exec(output) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i3 = obj.id i4 = obj.name.startswith(obj.site.login_base) i2 = ((not i3) or i4) i1 = (not i2) if (not i1): raise ValidationError('Necessary Failure') """ with self.assertRaises(Exception): policy_output_validator(obj, {})
def test_instance_container(self): xproto = """ policy test_policy < (obj.isolation = "container" | obj.isolation = "container_vm" ) -> (obj.image.kind = "container") > """ args = XOSProcessorArgs() args.inputs = xproto args.target = self.target output = XOSProcessor.process(args) obj = FakeObject() obj.isolation = "container" obj.kind = "not a container" exec(output) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i4 = (obj.isolation == 'container') i5 = (self.isolation == 'container_vm') i2 = (i4 or i5) i3 = (obj.image.kind == 'container') i1 = (i2 or i3) return i1 """ with self.assertRaises(Exception): policy_output_validator(obj, {})
def test_instance_container(self): xproto = """ policy test_policy < (obj.isolation = "container" | obj.isolation = "container_vm" ) -> (obj.image.kind = "container") > """ args = XOSProcessorArgs() args.inputs = xproto args.target = self.target output = XOSProcessor.process(args) obj = FakeObject() obj.isolation = "container" obj.kind = "not a container" exec(output) # This loads the generated function, which should look like this: """ def policy_output_validator(obj, ctx): i4 = (obj.isolation == 'container') i5 = (self.isolation == 'container_vm') i2 = (i4 or i5) i3 = (obj.image.kind == 'container') i1 = (i2 or i3) return i1 """ with self.assertRaises(Exception): policy_output_validator(obj, {})