diff --git a/README.md b/README.md index 4a0ebff3..c059f592 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ to simulate the `--all` flag. ## Changelog +* 2.16.0 - Add workflow description validator * 2.15.0 - Fix issue in title validator, Add title validator for workflows, clean up requirements * 2.14.0 - Fix issue where InputOutput validator would fail when missing required key * 2.13.0 - Add screenshot validator diff --git a/icon_validator/rules/__init__.py b/icon_validator/rules/__init__.py index 87ba9122..3505b26d 100644 --- a/icon_validator/rules/__init__.py +++ b/icon_validator/rules/__init__.py @@ -49,6 +49,7 @@ from icon_validator.rules.workflow_validators.workflow_icon_filename_validator import * from icon_validator.rules.workflow_validators.workflow_screenshot_validator import * from icon_validator.rules.workflow_validators.workflow_title_validator import * +from icon_validator.rules.workflow_validators.workflow_description_validator import * # The order of this list is the execution order of the validators. VALIDATORS = [ @@ -100,5 +101,6 @@ WorkflowICONFileNameValidator(), WorkflowScreenshotValidator(), WorkflowTitleValidator(), + WorkflowDescriptionValidator(), WorkflowProfanityValidator() ] diff --git a/icon_validator/rules/workflow_validators/workflow_description_validator.py b/icon_validator/rules/workflow_validators/workflow_description_validator.py new file mode 100644 index 00000000..05ef65b1 --- /dev/null +++ b/icon_validator/rules/workflow_validators/workflow_description_validator.py @@ -0,0 +1,27 @@ +from icon_validator.rules.validator import KomandPluginValidator +from icon_validator.exceptions import ValidationException + + +class WorkflowDescriptionValidator(KomandPluginValidator): + + @staticmethod + def validate_workflow_description_exists(spec): + if "description" not in spec.spec_dictionary(): + raise ValidationException("Workflow description in yaml is missing.") + + description = spec.spec_dictionary()["description"] + if description == "": + raise ValidationException("Workflow description in yaml can not be blank") + + @staticmethod + def validate_workflow_description_punctuation(description): + if not description.endswith("."): + raise ValidationException("Description does not end with a period when it should.") + if description[0].islower(): + raise ValidationException("Description should not start with a lower case letter.") + if description[0].isspace(): + raise ValidationException("Description should not start with a whitespace character.") + + def validate(self, spec): + WorkflowDescriptionValidator.validate_workflow_description_exists(spec) + WorkflowDescriptionValidator.validate_workflow_description_punctuation(spec.spec_dictionary()["description"]) diff --git a/setup.py b/setup.py index 497ce06a..14a304b8 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ long_description = fh.read() setup(name="insightconnect_integrations_validators", - version="2.15.0", + version="2.16.0", description="Validator tooling for InsightConnect integrations", long_description=long_description, long_description_content_type="text/markdown", diff --git a/unit_test/test_validate.py b/unit_test/test_validate.py index 2b18ab1f..da159cc9 100644 --- a/unit_test/test_validate.py +++ b/unit_test/test_validate.py @@ -17,6 +17,7 @@ from icon_validator.rules.workflow_validators.workflow_icon_filename_validator import WorkflowICONFileNameValidator from icon_validator.rules.workflow_validators.workflow_screenshot_validator import WorkflowScreenshotValidator from icon_validator.rules.workflow_validators.workflow_title_validator import WorkflowTitleValidator +from icon_validator.rules.workflow_validators.workflow_description_validator import WorkflowDescriptionValidator class TestPluginValidate(unittest.TestCase): @@ -151,3 +152,22 @@ def test_title_validator(self): file_to_test = "workflow_bad_caps.spec.yaml" result = validate(directory_to_test, file_to_test, False, True, [WorkflowTitleValidator()]) self.assertTrue(result) + + def test_description_validator(self): + # Test bad workflows. This will test the workflow_description_validator + directory_to_test = "workflow_examples/description_tests" + file_to_test = "workflow_no_description.spec.yaml" + result = validate(directory_to_test, file_to_test, False, True, [WorkflowDescriptionValidator()]) + self.assertTrue(result) + file_to_test = "workflow_no_period.spec.yaml" + result = validate(directory_to_test, file_to_test, False, True, [WorkflowDescriptionValidator()]) + self.assertTrue(result) + file_to_test = "workflow_whitespace.spec.yaml" + result = validate(directory_to_test, file_to_test, False, True, [WorkflowDescriptionValidator()]) + self.assertTrue(result) + file_to_test = "workflow_blank_description.spec.yaml" + result = validate(directory_to_test, file_to_test, False, True, [WorkflowDescriptionValidator()]) + self.assertTrue(result) + file_to_test = "workflow_lower_case.spec.yaml" + result = validate(directory_to_test, file_to_test, False, True, [WorkflowDescriptionValidator()]) + self.assertTrue(result) diff --git a/unit_test/workflow_examples/description_tests/workflow_blank_description.spec.yaml b/unit_test/workflow_examples/description_tests/workflow_blank_description.spec.yaml new file mode 100644 index 00000000..2c521f66 --- /dev/null +++ b/unit_test/workflow_examples/description_tests/workflow_blank_description.spec.yaml @@ -0,0 +1,21 @@ +extension: workflow +products: ["insightconnect"] +name: Automated_Indicator_Enrichment +title: "Automated Indicator Enrichment" +description: "" +version: 1.0.0 +vendor: rapid7 +support: rapid7 +status: [] +hub_tags: + use_cases: [alerting_and_notifications, threat_detection_and_response] + keywords: [enrichment, slack, url, ip] + features: [] +resources: + source_url: https://github.com/rapid7/insightconnect-workflows/tree/master/workflows/Automated_Indicator_Enrichment + license_url: https://github.com/rapid7/insightconnect-workflows/blob/master/LICENSE + screenshots: + - name: Automated_Indicator_Enrichment_Job.png + title: Example Job Output + - name: Automated_Indicator_Enrichment_Snapshot.png + title: Workflow View diff --git a/unit_test/workflow_examples/description_tests/workflow_lower_case.spec.yaml b/unit_test/workflow_examples/description_tests/workflow_lower_case.spec.yaml new file mode 100644 index 00000000..e8e421b9 --- /dev/null +++ b/unit_test/workflow_examples/description_tests/workflow_lower_case.spec.yaml @@ -0,0 +1,21 @@ +extension: workflow +products: ["insightconnect"] +name: Automated_Indicator_Enrichment +title: "Automated Indicator Enrichment" +description: "this workflow triggers from directly slack messaging the chatbot to \"!investigate\" the defined indicator. To date, this workflow supports automatically looking up URLs and IPs in open source threat intelligence such as VirusTotal and Whois. Lastly, the workflow will post back results to the specific user." +version: 1.0.0 +vendor: rapid7 +support: rapid7 +status: [] +hub_tags: + use_cases: [alerting_and_notifications, threat_detection_and_response] + keywords: [enrichment, slack, url, ip] + features: [] +resources: + source_url: https://github.com/rapid7/insightconnect-workflows/tree/master/workflows/Automated_Indicator_Enrichment + license_url: https://github.com/rapid7/insightconnect-workflows/blob/master/LICENSE + screenshots: + - name: Automated_Indicator_Enrichment_Job.png + title: Example Job Output + - name: Automated_Indicator_Enrichment_Snapshot.png + title: Workflow View diff --git a/unit_test/workflow_examples/description_tests/workflow_no_description.spec.yaml b/unit_test/workflow_examples/description_tests/workflow_no_description.spec.yaml new file mode 100644 index 00000000..12ad562c --- /dev/null +++ b/unit_test/workflow_examples/description_tests/workflow_no_description.spec.yaml @@ -0,0 +1,20 @@ +extension: workflow +products: ["insightconnect"] +name: Automated_Indicator_Enrichment +title: "Automated Indicator Enrichment" +version: 1.0.0 +vendor: rapid7 +support: rapid7 +status: [] +hub_tags: + use_cases: [alerting_and_notifications, threat_detection_and_response] + keywords: [enrichment, slack, url, ip] + features: [] +resources: + source_url: https://github.com/rapid7/insightconnect-workflows/tree/master/workflows/Automated_Indicator_Enrichment + license_url: https://github.com/rapid7/insightconnect-workflows/blob/master/LICENSE + screenshots: + - name: Automated_Indicator_Enrichment_Job.png + title: Example Job Output + - name: Automated_Indicator_Enrichment_Snapshot.png + title: Workflow View diff --git a/unit_test/workflow_examples/description_tests/workflow_no_period.spec.yaml b/unit_test/workflow_examples/description_tests/workflow_no_period.spec.yaml new file mode 100644 index 00000000..1c67aa76 --- /dev/null +++ b/unit_test/workflow_examples/description_tests/workflow_no_period.spec.yaml @@ -0,0 +1,21 @@ +extension: workflow +products: ["insightconnect"] +name: Automated_Indicator_Enrichment +title: "Automated Indicator Enrichment" +description: "This workflow triggers from directly slack messaging the chatbot to \"!investigate\" the defined indicator. To date, this workflow supports automatically looking up URLs and IPs in open source threat intelligence such as VirusTotal and Whois. Lastly, the workflow will post back results to the specific user" +version: 1.0.0 +vendor: rapid7 +support: rapid7 +status: [] +hub_tags: + use_cases: [alerting_and_notifications, threat_detection_and_response] + keywords: [enrichment, slack, url, ip] + features: [] +resources: + source_url: https://github.com/rapid7/insightconnect-workflows/tree/master/workflows/Automated_Indicator_Enrichment + license_url: https://github.com/rapid7/insightconnect-workflows/blob/master/LICENSE + screenshots: + - name: Automated_Indicator_Enrichment_Job.png + title: Example Job Output + - name: Automated_Indicator_Enrichment_Snapshot.png + title: Workflow View diff --git a/unit_test/workflow_examples/description_tests/workflow_whitespace.spec.yaml b/unit_test/workflow_examples/description_tests/workflow_whitespace.spec.yaml new file mode 100644 index 00000000..93e671b0 --- /dev/null +++ b/unit_test/workflow_examples/description_tests/workflow_whitespace.spec.yaml @@ -0,0 +1,21 @@ +extension: workflow +products: ["insightconnect"] +name: Automated_Indicator_Enrichment +title: "Automated Indicator Enrichment" +description: " This workflow triggers from directly slack messaging the chatbot to \"!investigate\" the defined indicator. To date, this workflow supports automatically looking up URLs and IPs in open source threat intelligence such as VirusTotal and Whois. Lastly, the workflow will post back results to the specific user." +version: 1.0.0 +vendor: rapid7 +support: rapid7 +status: [] +hub_tags: + use_cases: [alerting_and_notifications, threat_detection_and_response] + keywords: [enrichment, slack, url, ip] + features: [] +resources: + source_url: https://github.com/rapid7/insightconnect-workflows/tree/master/workflows/Automated_Indicator_Enrichment + license_url: https://github.com/rapid7/insightconnect-workflows/blob/master/LICENSE + screenshots: + - name: Automated_Indicator_Enrichment_Job.png + title: Example Job Output + - name: Automated_Indicator_Enrichment_Snapshot.png + title: Workflow View