CORD-1385: Autogenerate validation code
Change-Id: I8dda8f78482b382cd5d9c5397070266324d4fab9
diff --git a/lib/xos-genx/tests/general_security_test.py b/lib/xos-genx/tests/general_security_test.py
index f2dd857..d5f3e79 100644
--- a/lib/xos-genx/tests/general_security_test.py
+++ b/lib/xos-genx/tests/general_security_test.py
@@ -1,12 +1,11 @@
import unittest
from xosgenx.generator import XOSGenerator
from helpers import FakeArgs, XProtoTestHelpers
-import pdb
-"""The function below is for eliminating warnings arising due to the missing policy_output_0,
+"""The function below is for eliminating warnings arising due to the missing policy_output_enforcer,
which is generated and loaded dynamically.
"""
-def policy_output_0(x, y):
+def policy_output_enforcer(x, y):
raise Exception("Security enforcer not generated. Test failed.")
return False
@@ -16,7 +15,7 @@
"""
class XProtoSecurityTest(unittest.TestCase):
def setUp(self):
- self.target = XProtoTestHelpers.write_tmp_target("{{ xproto_fol_to_python_test(proto.policies.test_policy, None, '0') }}")
+ self.target = XProtoTestHelpers.write_tmp_target("{{ xproto_fol_to_python_test('output', proto.policies.test_policy, None, '0') }}")
def test_constant(self):
xproto = \
@@ -32,12 +31,12 @@
exec(output) # This loads the generated function, which should look like this:
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i1 = True
return i1
"""
- verdict = policy_output_0({}, {})
+ verdict = policy_output_enforcer({}, {})
self.assertTrue(verdict)
def test_equal(self):
@@ -55,7 +54,7 @@
exec(output) # This loads the generated function, which should look like this:
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i1 = (ctx.user == obj.user)
return i1
"""
@@ -65,7 +64,7 @@
ctx = FakeArgs()
ctx.user = 1
- verdict = policy_output_0(obj, ctx)
+ verdict = policy_output_enforcer(obj, ctx)
def test_bin(self):
xproto = \
@@ -81,7 +80,7 @@
exec(output) # This loads the generated function, which should look like this:
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i2 = (ctx.is_admin == True)
i3 = (obj.empty == True)
i1 = (i2 or i3)
@@ -94,7 +93,7 @@
ctx = FakeArgs()
ctx.is_admin = True
- verdict = policy_output_0(obj, ctx)
+ verdict = policy_output_enforcer(obj, ctx)
self.assertTrue(verdict)
@@ -112,12 +111,12 @@
exec(output) # This loads the generated function, which should look like this:
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i1 = Privilege.objects.filter(object_id=obj.id)
return i1
"""
- self.assertTrue(policy_output_0 is not None)
+ self.assertTrue(policy_output_enforcer is not None)
def test_python(self):
xproto = \
@@ -131,13 +130,13 @@
exec(output) # This loads the generated function, which should look like this:
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i2 = ('jack' in ['the', 'box'])
i1 = (i2 == False)
return i1
"""
- self.assertTrue(policy_output_0({}, {}) is True)
+ self.assertTrue(policy_output_enforcer({}, {}) is True)
def test_forall(self):
# This one we only parse
@@ -146,15 +145,13 @@
policy test_policy < forall Credential: Credential.obj_id = obj_id >
"""
- target = XProtoTestHelpers.write_tmp_target("{{ xproto_fol_to_python_test(proto.policies.test_policy, None, '0') }}")
-
args = FakeArgs()
args.inputs = xproto
- args.target = target
+ args.target = self.target
output = XOSGenerator.generate(args)
"""
- def policy_output_0(obj, ctx):
+ def policy_output_enforcer(obj, ctx):
i2 = Credential.objects.filter((~ Q(obj_id=obj_id)))[0]
i1 = (not i2)
return i1