From b71fd93dd4aef09236f4d5062cd7f9e36c699e21 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 22 Jan 2021 12:14:17 -0500 Subject: [PATCH 1/3] We now make sure that forms have a form key. Ticket 163 --- crc/services/workflow_service.py | 6 ++++++ 1 file changed, 6 insertions(+) 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: From 243877947043218a92fccfb21db5eb68fd81db18 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 22 Jan 2021 12:14:59 -0500 Subject: [PATCH 2/3] Test and workflow file for missing form key. Ticket 163 --- .../missing_form_key/missing_form_key.bpmn | 56 +++++++++++++++++++ .../test_workflow_missing_form_key.py | 13 +++++ 2 files changed, 69 insertions(+) create mode 100644 tests/data/missing_form_key/missing_form_key.bpmn create mode 100644 tests/workflow/test_workflow_missing_form_key.py 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']) From d01f8e10182160d213ab19995b54e7d83baee0fb Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 22 Jan 2021 12:16:02 -0500 Subject: [PATCH 3/3] This workflow had a form with a missing form key, so it's associated test failed after my changes in this ticket. I added a form key to the form. Test now passes. --- tests/data/ldap_script/ldap_script.bpmn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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