diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 82a4610d..8d450756 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -108,6 +108,12 @@ class WorkflowService(object): task_api = WorkflowService.spiff_task_to_api_task( task, add_docs_and_forms=True) # Assure we try to process the documentation, and raise those errors. + # make sure forms have a form key + if hasattr(task_api, 'form') and task_api.form is not None and task_api.form.key == '': + raise ApiError(code='missing_form_key', + message='Forms must include a Form Key.', + task_id=task.id, + task_name=task.get_name()) WorkflowService.populate_form_with_random_data(task, task_api, required_only) processor.complete_task(task) except WorkflowException as we: diff --git a/tests/data/ldap_script/ldap_script.bpmn b/tests/data/ldap_script/ldap_script.bpmn index d2ab78bf..ddda26ef 100644 --- a/tests/data/ldap_script/ldap_script.bpmn +++ b/tests/data/ldap_script/ldap_script.bpmn @@ -1,5 +1,5 @@ - + Flow_1synsig @@ -28,7 +28,7 @@ me = ldap() Flow_08n2npe - + Flow_1xlrgne Flow_11e7jgz diff --git a/tests/data/missing_form_key/missing_form_key.bpmn b/tests/data/missing_form_key/missing_form_key.bpmn new file mode 100644 index 00000000..8a94500b --- /dev/null +++ b/tests/data/missing_form_key/missing_form_key.bpmn @@ -0,0 +1,56 @@ + + + + + Flow_1dl9zdu + + + SequenceFlow_02vev7n + + + + + + + + + + + Flow_1dl9zdu + Flow_1iohvj2 + + + <h1>Hello {{ name }}</h1> + Flow_1iohvj2 + SequenceFlow_02vev7n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_missing_form_key.py b/tests/workflow/test_workflow_missing_form_key.py new file mode 100644 index 00000000..e56a4af7 --- /dev/null +++ b/tests/workflow/test_workflow_missing_form_key.py @@ -0,0 +1,13 @@ +from tests.base_test import BaseTest +import json + + +class TestMissingFormKey(BaseTest): + + def test_missing_form_key(self): + + spec_model = self.load_test_spec('missing_form_key') + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) + json_data = json.loads(rv.get_data(as_text=True)) + self.assertIn('code', json_data[0]) + self.assertEqual('missing_form_key', json_data[0]['code'])