예제 #1
0
def test_scheme_validation_invalid_playbook():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    try:
        validator.is_valid_scheme(matching_regex=PLAYBOOK_REGEX)
    except TypeError as exc:
        pytest.raises(TypeError, exc)
예제 #2
0
    def validate_added_files(self, added_files):
        """Validate the added files from your branch.

        In case we encounter an invalid file we set the self._is_valid param to False.

        Args:
            added_files (set): A set of the modified files in the current branch.
        """
        for file_path in added_files:
            print("Validating {}".format(file_path))

            structure_validator = StructureValidator(file_path, is_added_file=True)
            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

            if self.id_set_validator.is_file_has_used_id(file_path):
                self._is_valid = False

            if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE):
                if not self.conf_json_validator.is_test_in_conf_json(collect_ids(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) or \
                    re.match(IMAGE_REGEX, file_path, re.IGNORECASE):

                image_validator = ImageValidator(file_path)
                if not image_validator.is_valid():
                    self._is_valid = False
예제 #3
0
def test_not_touched_id_validation():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "some other text"
    assert validator.is_id_not_modified(change_string=change_string), \
        "Found the ID as changed although it is not"
예제 #4
0
def test_removed_id_validation():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "-  id: text"
    assert validator.is_id_not_modified(change_string=change_string) is False, \
        "Didn't find the id as updated in file"
예제 #5
0
def test_fromversion_update_validation_json_structure():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "+ \"fromVersion\": \"123"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string) is False, \
        "Didn't find the fromVersion as updated in json file"
예제 #6
0
def test_fromversion_no_update_validation():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "some other text"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string), \
        "Didn't find the fromversion as updated in yml file"
예제 #7
0
    def validate_all_files(self):
        """Validate all files in the repo are in the right format."""
        for regex in CHECKED_TYPES_REGEXES:
            splitted_regex = regex.split(".*")
            directory = splitted_regex[0]
            for root, dirs, files in os.walk(directory):
                if root not in DIR_LIST:  # Skipping in case we entered a package
                    continue
                print_color("Validating {} directory:".format(directory), LOG_COLORS.GREEN)
                for file_name in files:
                    file_path = os.path.join(root, file_name)
                    # skipping hidden files
                    if file_name.startswith('.'):
                        continue

                    print("Validating " + file_name)
                    structure_validator = StructureValidator(file_path)
                    if not structure_validator.is_valid_scheme():
                        self._is_valid = False

                if root in PACKAGE_SUPPORTING_DIRECTORIES:
                    for inner_dir in dirs:
                        file_path = glob.glob(os.path.join(root, inner_dir, '*.yml'))[0]
                        print("Validating " + file_path)
                        structure_validator = StructureValidator(file_path)
                        if not structure_validator.is_valid_scheme():
                            self._is_valid = False
예제 #8
0
def test_fromversion_update_validation_yml_structure():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-test.yml")

    change_string = "+ fromversion: sometext"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string) is False, \
        "Didn't find the fromversion as updated in yml file"
예제 #9
0
    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
예제 #10
0
def test_invalid_file_examination():
    copyfile("./Tests/setup/integration-test.yml", "Integrations/integration-test.yml")
    validator = StructureValidator(file_path="Integrations/integration-test.yml")

    assert validator.is_file_valid() is False, \
        "Didn't find a problem in the file although it is not valid"

    os.remove("Integrations/integration-test.yml")
예제 #11
0
def test_scheme_validation_invalid_playbook():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    try:
        validator.is_valid_scheme(matching_regex=PLAYBOOK_REGEX)
    except TypeError as exc:
        pytest.raises(TypeError, exc)
예제 #12
0
def test_valid_file_examination():
    copyfile("./Tests/setup/Playbooks.playbook-test.yml", "Playbooks/playbook-test.yml")
    validator = StructureValidator(file_path="Playbooks/playbook-test.yml", is_added_file=True)

    assert validator.is_file_valid(), \
        "Found a problem in the scheme although there is no problem"

    os.remove("Playbooks/playbook-test.yml")
예제 #13
0
def test_valid_file_examination():
    copyfile("./Tests/setup/Playbooks.playbook-test.yml",
             "Playbooks/playbook-test.yml")
    validator = StructureValidator(file_path="Playbooks/playbook-test.yml",
                                   is_added_file=True)

    assert validator.is_file_valid(), \
        "Found a problem in the scheme although there is no problem"

    os.remove("Playbooks/playbook-test.yml")
예제 #14
0
def test_invalid_file_examination():
    copyfile("./Tests/setup/integration-test.yml",
             "Integrations/integration-test.yml")
    validator = StructureValidator(
        file_path="Integrations/integration-test.yml")

    assert validator.is_file_valid() is False, \
        "Didn't find a problem in the file although it is not valid"

    os.remove("Integrations/integration-test.yml")
예제 #15
0
    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
예제 #16
0
    def validate_added_files(self, added_files):
        """Validate the added files from your branch.

        In case we encounter an invalid file we set the self._is_valid param to False.

        Args:
            added_files (set): A set of the modified files in the current branch.
        """
        for file_path in added_files:
            print("Validating {}".format(file_path))

            structure_validator = StructureValidator(file_path, is_added_file=True)
            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

            if self.id_set_validator.is_file_has_used_id(file_path):
                self._is_valid = False

            if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE):
                if not self.conf_json_validator.is_test_in_conf_json(collect_ids(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) or \
                    re.match(IMAGE_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

            elif re.match(IMAGE_REGEX, file_path, re.IGNORECASE):
                image_validator = ImageValidator(file_path)
                if not image_validator.is_valid():
                    self._is_valid = False
예제 #17
0
    def validate_all_files(self):
        """Validate all files in the repo are in the right format."""
        for regex in CHECKED_TYPES_REGEXES:
            splitted_regex = regex.split('.*')
            directory = splitted_regex[0]
            for root, dirs, files in os.walk(directory):
                if root not in DIR_LIST:  # Skipping in case we entered a package
                    continue
                print_color('Validating {} directory:'.format(directory), LOG_COLORS.GREEN)
                for file_name in files:
                    file_path = os.path.join(root, file_name)
                    # skipping hidden files
                    if file_name.startswith('.'):
                        continue

                    print('Validating ' + file_name)
                    structure_validator = StructureValidator(file_path)
                    if not structure_validator.is_valid_scheme():
                        self._is_valid = False

                if root in PACKAGE_SUPPORTING_DIRECTORIES:
                    for inner_dir in dirs:
                        file_path = glob.glob(os.path.join(root, inner_dir, '*.yml'))[0]
                        print('Validating ' + file_path)
                        structure_validator = StructureValidator(file_path)
                        if not structure_validator.is_valid_scheme():
                            self._is_valid = False
예제 #18
0
    def validate_added_files(self, added_files):
        """Validate the added files from your branch.

        In case we encounter an invalid file we set the self._is_valid param to False.

        Args:
            added_files (set): A set of the modified files in the current branch.
        """
        for file_path in added_files:
            is_python_file = FilesValidator.is_py_script_or_integration(file_path)
            print('Validating {}'.format(file_path))

            structure_validator = StructureValidator(file_path, is_added_file=True)
            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

            if self.id_set_validator.is_file_has_used_id(file_path):
                self._is_valid = False

            if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE):
                if not self.conf_json_validator.is_test_in_conf_json(collect_ids(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) or \
                    re.match(IMAGE_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)
                if not integration_validator.is_valid_integration():
                    self._is_valid = False

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=False)
                    if not docker_image_validator.is_docker_image_valid():
                        self._is_valid = False

            elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE) or \
                    re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \
                    re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE):

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=False)
                    if not docker_image_validator.is_docker_image_valid():
                        self._is_valid = False

            elif re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                    re.match(BETA_INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
                description_validator = DescriptionValidator(file_path)
                if not description_validator.is_valid_beta_description():
                    self._is_valid = False

                integration_validator = IntegrationValidator(file_path)
                if not integration_validator.is_valid_beta_integration(is_new=True):
                    self._is_valid = False

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=False)
                    if not docker_image_validator.is_docker_image_valid():
                        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

            elif re.match(INCIDENT_FIELD_REGEX, file_path, re.IGNORECASE):
                incident_field_validator = IncidentFieldValidator(file_path)
                if not incident_field_validator.is_valid():
                    self._is_valid = False
예제 #19
0
def test_version_validation():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-test.yml")

    assert validator.is_valid_version(), \
        "Found an incorrect version although the version is -1"
예제 #20
0
def test_playbook_file_with_invalid_id():
    validator = StructureValidator(
        file_path="./Tests/setup/playbook-invalid-id-test.yml")
    assert not validator.is_file_id_without_slashes(), \
        "Didn't find a slash in the ID even though it contains a slash."
예제 #21
0
    def validate_modified_files(self, modified_files, is_backward_check=True, old_branch='master'):
        """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.
            is_backward_check (bool): When set to True will run backward compatibility checks
            old_branch (str): Old git branch to compare backward compatibility check to
        """
        for file_path in modified_files:
            old_file_path = None

            if isinstance(file_path, tuple):
                old_file_path, file_path = file_path

            is_python_file = FilesValidator.is_py_script_or_integration(file_path)

            print('Validating {}'.format(file_path))
            if not checked_type(file_path):
                print_warning('- Skipping validation of non-content entity file.')
                continue

            structure_validator = StructureValidator(file_path, is_added_file=not (False or is_backward_check),
                                                     is_renamed=old_file_path is not None)
            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,
                                                             old_git_branch=old_branch)
                if is_backward_check and not integration_validator.is_backward_compatible():
                    self._is_valid = False
                if not integration_validator.is_valid_integration():
                    self._is_valid = False

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=True)
                    if not docker_image_validator.is_docker_image_valid():
                        self._is_valid = False

            elif re.match(BETA_INTEGRATION_REGEX, file_path, re.IGNORECASE) or \
                    re.match(BETA_INTEGRATION_YML_REGEX, file_path, re.IGNORECASE):
                description_validator = DescriptionValidator(file_path)
                if not description_validator.is_valid_beta_description():
                    self._is_valid = False
                integration_validator = IntegrationValidator(file_path, old_file_path=old_file_path)
                if not integration_validator.is_valid_beta_integration():
                    self._is_valid = False
                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=True)
                    if not docker_image_validator.is_docker_image_valid():
                        self._is_valid = False

            elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE):
                script_validator = ScriptValidator(file_path, old_file_path=old_file_path, old_git_branch=old_branch)
                if is_backward_check and not script_validator.is_backward_compatible():
                    self._is_valid = False
                if not script_validator.is_valid_script():
                    self._is_valid = False

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=True)
                    if not docker_image_validator.is_docker_image_valid():
                        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, old_file_path=old_file_path, old_git_branch=old_branch)
                if is_backward_check and not script_validator.is_backward_compatible():
                    self._is_valid = False

                if is_python_file:
                    docker_image_validator = DockerImageValidator(file_path, is_modified_file=True)
                    if not docker_image_validator.is_docker_image_valid():
                        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

            elif re.match(INCIDENT_FIELD_REGEX, file_path, re.IGNORECASE):
                incident_field_validator = IncidentFieldValidator(file_path, old_file_path=old_file_path,
                                                                  old_git_branch=old_branch)
                if not incident_field_validator.is_valid():
                    self._is_valid = False
                if is_backward_check and not incident_field_validator.is_backward_compatible():
                    self._is_valid = False
예제 #22
0
def test_incorrect_version_validation():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    assert validator.is_valid_version() is False, \
        "Found an a correct version although the version is 123"
예제 #23
0
def test_version_validation():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-test.yml")

    assert validator.is_valid_version(), \
        "Found an incorrect version although the version is -1"
예제 #24
0
def test_integration_file_with_valid_id():
    validator = StructureValidator(
        file_path="./Tests/setup/integration-valid-id-test.yml")
    assert validator.is_file_id_without_slashes(), \
        "Found a slash in the file's ID even though it contains no slashes.."
예제 #25
0
def test_scheme_validation_playbook():
    validator = StructureValidator(
        file_path="./Tests/setup/Playbooks.playbook-test.yml")

    assert validator.is_valid_scheme(matching_regex=PLAYBOOK_REGEX), \
        "Found a problem in the scheme although there is no problem"
예제 #26
0
def test_not_touched_id_validation():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "some other text"
    assert validator.is_id_not_modified(change_string=change_string), \
        "Found the ID as changed although it is not"
예제 #27
0
def test_scheme_validation_playbook():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-test.yml")

    assert validator.is_valid_scheme(matching_regex=PLAYBOOK_REGEX), \
        "Found a problem in the scheme although there is no problem"
예제 #28
0
def test_removed_id_validation():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "-  id: text"
    assert validator.is_id_not_modified(change_string=change_string) is False, \
        "Didn't find the id as updated in file"
예제 #29
0
def test_fromversion_no_update_validation():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "some other text"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string), \
        "Didn't find the fromversion as updated in yml file"
예제 #30
0
def test_fromversion_update_validation_json_structure():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    change_string = "+ \"fromVersion\": \"123"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string) is False, \
        "Didn't find the fromVersion as updated in json file"
예제 #31
0
def test_fromversion_update_validation_yml_structure():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-test.yml")

    change_string = "+ fromversion: sometext"
    assert validator.is_valid_fromversion_on_modified(change_string=change_string) is False, \
        "Didn't find the fromversion as updated in yml file"
예제 #32
0
def test_incorrect_version_validation():
    validator = StructureValidator(file_path="./Tests/setup/Playbooks.playbook-invalid.yml")

    assert validator.is_valid_version() is False, \
        "Found an a correct version although the version is 123"