def test_not_requires_arg_in_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [ { "name": "test", "arguments": [ { "name": "test" } ] } ] } validator.current_integration = { "commands": [ { "name": "test", "arguments": [ { "name": "test" }, { "name": "test1", } ] } ] } assert validator.is_changed_command_name_or_arg() is False, "The script validator found a backward compatibility " \ "issue although a new not required command was added"
def test_is_isarray_arguments_valid(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "commands": [ { "name": "email", "arguments": [ { "name": "email", "required": True, "default": True, "isArray": True }, { "name": "verbose" } ] } ] } } validator.old_integration = None assert validator.is_isarray_arguments() is True, \ "The integration validator found an invalid command arg configuration while it is valid"
def test_not_changed_docker_image_on_existing_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = {} assert validator.is_docker_image_changed() is False, "The script validator couldn't find the docker "\ "image as changed"
def test_not_changed_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "script": { "commands": [ { "name": "test", "arguments": [ { "name": "test" } ] } ] } } validator.current_integration = { "script": { "commands": [ { "name": "test", "arguments": [ { "name": "test" } ] } ] } } assert validator.is_changed_command_name_or_arg() is False, "The script validator found a backward compatibility " \ "issue although the commands haven't changed"
def test_not_changed_context_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" } ] } ] } validator.current_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" } ] } ] } assert validator.is_changed_context_path() is False, "The script validator found a backward compatability " \ "change although no such change was done"
def test_not_requires_arg_in_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [ { "name": "test", "arguments": [ { "name": "test" } ] } ] } validator.current_integration = { "commands": [ { "name": "test", "arguments": [ { "name": "test" }, { "name": "test1", } ] } ] } assert validator.is_changed_command_name_or_arg() is False, "The script validator found a backward compatibility " \ "issue although a new not required command was added"
def test_added_required_arg_for_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "script": { "commands": [{ "name": "test", "arguments": [{ "name": "test" }] }] } } validator.current_integration = { "script": { "commands": [{ "name": "test", "arguments": [{ "name": "test", }, { "name": "test1", "required": True }] }] } } assert validator.is_changed_command_name_or_arg(), "The script validator did not found a backward compatibility " \ "issue although the command was added with required arg"
def test_not_changed_docker_image_on_existing_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = {} assert validator.is_docker_image_changed() is False, "The script validator couldn't find the docker "\ "image as changed"
def test_added_new_command_context_path_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [{ "name": "test", "outputs": [{ "contextPath": "test" }] }] } validator.current_integration = { "commands": [{ "name": "test", "outputs": [{ "contextPath": "test" }] }, { "name": "test2", "outputs": [{ "contextPath": "new command" }] }] } assert validator.is_changed_context_path() is False, "The script validator found a backward compatibility " \ "issue although the context path has not changed"
def test_removed_docker_image_on_existing_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {"script": {"dockerimage": "test"}} validator.current_integration = {"script": {"no": "dockerimage"}} assert validator.is_docker_image_changed( ), "The script validator couldn't find the docker image as changed"
def test_is_isarray_arguments_invalid(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "commands": [ { "name": "file", "arguments": [ { "name": "file", "required": True, "default": True, "isArray": False }, { "name": "verbose" } ] } ] } } validator.old_integration = None assert validator.is_isarray_arguments() is False, \ "The integration validator did not find invalid arg configuration (needed to be isArray)"
def test_changed_context_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "script": { "commands": [{ "name": "test", "outputs": [{ "contextPath": "test" }] }] } } validator.current_integration = { "script": { "commands": [{ "name": "test", "outputs": [{ "contextPath": "changed that" }] }] } } assert validator.is_changed_context_path(), "The script validator didn't find a backward compatability " \ "issue although the context path has changed"
def test_added_context_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" } ] } ] } validator.current_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" }, { "contextPath": "changed that" } ] } ] } assert validator.is_changed_context_path() is False, "The script validator didn't find a backward compatability " \ "issue although the context path has changed"
def test_changed_required_arg_for_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "script": { "commands": [ { "name": "test", "arguments": [ { "name": "test" } ] } ] } } validator.current_integration = { "script": { "commands": [ { "name": "test", "arguments": [ { "name": "test", "required": True } ] } ] } } assert validator.is_changed_command_name_or_arg(), "The script validator did not found a backward compatibility " \ "issue although the command was added with required arg"
def test_not_changed_context_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" } ] } ] } validator.current_integration = { "commands": [ { "name": "test", "outputs": [ { "contextPath": "test" } ] } ] } assert validator.is_changed_context_path() is False, "The script validator found a backward compatability " \ "change although no such change was done"
def test_not_changed_command_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "script": { "commands": [{ "name": "test", "arguments": [{ "name": "test" }] }] } } validator.current_integration = { "script": { "commands": [{ "name": "test", "arguments": [{ "name": "test" }] }] } } assert validator.is_changed_command_name_or_arg() is False, "The script validator found a backward compatibility " \ "issue although the commands haven't changed"
def validate_modified_files(self, modified_files): """Validate the modified files from your branch. In case we encounter an invalid file we set the self._is_valid param to False. Args: modified_files (set): A set of the modified files in the current branch. """ for file_path in modified_files: old_file_path = None if isinstance(file_path, tuple): old_file_path, file_path = file_path print("Validating {}".format(file_path)) structure_validator = StructureValidator( file_path, is_added_file=False, is_renamed=True if old_file_path else False) if not structure_validator.is_file_valid(): self._is_valid = False if not self.id_set_validator.is_file_valid_in_set(file_path): self._is_valid = False elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False description_validator = DescriptionValidator(file_path) if not description_validator.is_valid(): self._is_valid = False integration_validator = IntegrationValidator( file_path, old_file_path=old_file_path) if not integration_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_validator = ScriptValidator(file_path) if not script_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, _ = get_script_package_data( os.path.dirname(file_path)) script_validator = ScriptValidator(yml_path) if not script_validator.is_backward_compatible(): self._is_valid = False elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False
def validate_modified_files(self, modified_files, is_backward_check=True): """Validate the modified files from your branch. In case we encounter an invalid file we set the self._is_valid param to False. Args: modified_files (set): A set of the modified files in the current branch. """ for file_path in modified_files: old_file_path = None if isinstance(file_path, tuple): old_file_path, file_path = file_path print("Validating {}".format(file_path)) structure_validator = StructureValidator(file_path, is_added_file=not(False or is_backward_check), is_renamed=True if old_file_path else False) if not structure_validator.is_file_valid(): self._is_valid = False if not self.id_set_validator.is_file_valid_in_set(file_path): self._is_valid = False elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False description_validator = DescriptionValidator(file_path) if not description_validator.is_valid(): self._is_valid = False integration_validator = IntegrationValidator(file_path, old_file_path=old_file_path) if is_backward_check and not integration_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_validator = ScriptValidator(file_path) if is_backward_check and not script_validator.is_backward_compatible(): self._is_valid = False elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, _ = get_script_package_data(os.path.dirname(file_path)) script_validator = ScriptValidator(yml_path) if is_backward_check and not script_validator.is_backward_compatible(): self._is_valid = False elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE): image_validator = ImageValidator(file_path) if not image_validator.is_valid(): self._is_valid = False
def test_added_docker_image_on_existing_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = { "script": { "dockerimage": "test1" } } assert validator.is_docker_image_changed(), "The script validator couldn't find the docker image as changed"
def test_unsecure_correct_display(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [{ "name": "unsecure", "type": 8, "display": "Trust any certificate (not secure)", "required": False }] } assert validator.is_insecure_configured_correctly()
def test_duplicated_params(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [{ "name": "test" }, { "name": "test", }] } assert validator.is_there_duplicate_params(), \ "The integration validator did not find duplicated params although there are duplicates"
def test_valid_subtype_lies(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "type": "python", "subtype": "lies" } } validator.old_integration = None assert validator.is_valid_subtype() is False, \ "The integration validator found valid subtype while it is invalid"
def test_proxy_wrong_display(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [{ "name": "proxy", "type": 8, "display": "bla", "required": False }] } assert validator.is_proxy_configured_correctly() is False
def test_unsecure_wrong_display(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [{ "name": "unsecure", "type": 8, "display": "Use system proxy settings", "required": False }] } assert validator.is_insecure_configured_correctly() is False
def test_proxy_sanity_check(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [{ "name": "proxy", "type": 8, "display": "Use system proxy settings", "required": False }] } assert validator.is_proxy_configured_correctly()
def test_valid_new_beta_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = { "commonfields": { "id": "newIntegration" }, "name": "newIntegration", "display": "newIntegration (Beta)", "beta": True, } assert validator.is_valid_beta_integration(is_new=True) is True, \ "The Beta validator did not validate a new valid integration"
def test_duplicated_params(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "configuration": [ { "name": "test" }, { "name": "test", } ] } assert validator.is_there_duplicate_params(), \ "The integration validator did not find duplicated params although there are duplicates"
def test_new_beta_integration_missing_beta_in_display(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = { "commonfields": { "id": "newIntegration" }, "name": "newIntegration", "display": "newIntegration", "beta": True, } assert validator.is_valid_beta_integration(is_new=True) is False, \ "The Beta validator approved the integration" \ "but it should have fail it for missing beta substring in 'display' field"
def test_configuration_extraction(): validator = IntegrationValidator("temp_file", check_git=False) integration_json = { "configuration": [{ "name": "test", "required": False }, { "name": "test1", "required": True }] } expected = {"test": False, "test1": True} assert validator._get_field_to_required_dict( integration_json) == expected, "Failed to extract configuration"
def test_new_beta_integration_with_beta_substring_in_name(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = {} validator.current_integration = { "commonfields": { "id": "newIntegration" }, "name": "newIntegration beta", "display": "newIntegration (Beta)", "beta": True, } assert validator.is_valid_beta_integration(is_new=True) is False, \ "The beta validator approved the new beta integration," \ " but it should fail it because the 'name' field has a 'beta' substring in it. " \ "the validator should not allow it for new integration"
def test_is_changed_subtype_changed(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "type": "python", "subtype": "python3" } } validator.old_integration = { "script": { "type": "python", "subtype": "python2" } } assert validator.is_changed_subtype() is False, \ "The integration validator did not find changed subtype while it is changed"
def test_not_changed_required_field_scenario2_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [{ "name": "test", "required": False }] } validator.current_integration = { "configuration": [{ "name": "test", "required": False }] } assert validator.is_added_required_fields() is False, "The script validator found a backward compatability " \ "change although no such change was done"
def test_duplicated_argss(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "commands": [{ "name": "testing", "arguments": [{ "name": "test" }, { "name": "test" }] }] } } assert validator.is_there_duplicate_args(), \ "The integration validator did not find duplicated args although there are duplicates"
def test_changed_required_field_to_not_required_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [{ "name": "test", "required": True }] } validator.current_integration = { "configuration": [{ "name": "test", "required": False }] } assert validator.is_added_required_fields() is False, "The script validator found the change to not reuquired " \ "as a one who breaks backward compatability"
def test_valid_subtype_python3(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "type": "python", "subtype": "python3" } } validator.old_integration = { "script": { "type": "python", "subtype": "python3" } } assert validator.is_valid_subtype(), \ "The integration validator found invalid subtype while it is valid"
def test_added_required_field_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [{ "name": "test", "required": False }] } validator.current_integration = { "configuration": [{ "name": "test", "required": True }] } assert validator.is_added_required_fields( ), "The script validator couldn't find the new required fields"
def test_is_valid_category(): validator_siem = IntegrationValidator("temp_file", check_git=False) validator_siem.current_integration = {"category": "Analytics & SIEMM"} assert validator_siem.is_valid_category() is False validator_endpoint = IntegrationValidator("temp_file", check_git=False) validator_endpoint.current_integration = {"category": "Endpoint"} assert validator_endpoint.is_valid_category()
def test_added_required_field_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [ { "name": "test", "required": False } ] } validator.current_integration = { "configuration": [ { "name": "test", "required": True } ] } assert validator.is_added_required_fields(), "The script validator couldn't find the new required fields"
def test_changed_beta_integration_without_beta_field(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "commonfields": { "id": "newIntegration beta" }, "name": "newIntegration beta", "display": "newIntegration (Beta)", } validator.current_integration = { "commonfields": { "id": "newIntegration beta" }, "name": "newIntegration beta", "display": "newIntegration changed (Beta)", } assert validator.is_valid_beta_integration() is False, \ "The Beta validator approved the integration" \ "but it should have fail it because it is missing 'beta' field with the value true"
def test_is_default_arguments_is_required(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "commands": [{ "name": "domain", "arguments": [{ "name": "domain", "required": True, "default": True }, { "name": "verbose" }] }] } } validator.old_integration = None assert validator.is_default_arguments() is False, \ "The integration validator did not find invalid arg (need not to be required)"
def test_not_changed_required_field_scenario2_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [ { "name": "test", "required": False } ] } validator.current_integration = { "configuration": [ { "name": "test", "required": False } ] } assert validator.is_added_required_fields() is False, "The script validator found a backward compatability " \ "change although no such change was done"
def test_configuration_extraction(): validator = IntegrationValidator("temp_file", check_git=False) integration_json = { "configuration": [ { "name": "test", "required": False }, { "name": "test1", "required": True } ] } expected = { "test": False, "test1": True } assert validator._get_field_to_required_dict(integration_json) == expected, "Failed to extract configuration"
def test_changed_required_field_to_not_required_in_integration(): validator = IntegrationValidator("temp_file", check_git=False) validator.old_integration = { "configuration": [ { "name": "test", "required": True } ] } validator.current_integration = { "configuration": [ { "name": "test", "required": False } ] } assert validator.is_added_required_fields() is False, "The script validator found the change to not reuquired " \ "as a one who breaks backward compatability"
def test_duplicated_argss(): validator = IntegrationValidator("temp_file", check_git=False) validator.current_integration = { "script": { "commands": [ { "name": "testing", "arguments": [ { "name": "test" }, { "name": "test" } ] } ] } } assert validator.is_there_duplicate_args(), \ "The integration validator did not find duplicated args although there are duplicates"