Beispiel #1
0
def test_is_docker_image_latest_tag_with_default_image():
    """
    Given
    - The default docker image - 'demisto/python:1.3-alpine'

    When
    - The most updated docker image in docker-hub is '1.0.3'

    Then
    -  If the docker image is numeric and the most update one, it is Valid
    -  If the docker image is not numeric and labeled "latest", it is Invalid
   """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.code_type = 'python'
        docker_image_validator.checked_files = set()
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.suppress_print = False

        docker_image_validator.is_latest_tag = True
        docker_image_validator.is_modified_file = False
        docker_image_validator.docker_image_tag = '1.3-alpine'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
Beispiel #2
0
def test_is_docker_image_latest_tag_without_tag():
    """
   Given
   - A latest docker image has an empty tag

   When
   - The most updated docker image in docker-hub is '1.0.3'

   Then
   -  If the docker image is numeric and the most update one, it is Valid
   -  If the docker image is not numeric and labeled "latest", it is Invalid
  """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.ignored_errors = {}
        docker_image_validator.file_path = "path"
        docker_image_validator.docker_image_latest_tag = ''
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.code_type = 'python'
        docker_image_validator.suppress_print = False

        docker_image_validator.is_latest_tag = True
        docker_image_validator.docker_image_tag = '1.0.2'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
Beispiel #3
0
def test_is_docker_image_latest_tag_with_numeric_but_not_most_updated():
    """
   Given
   - A docker image with '1.0.2' as tag

   When
   - The most updated docker image in docker-hub is '1.0.3'

   Then
   -  If the docker image is numeric and the most update one, it is Valid
   -  If the docker image is not numeric and labeled "latest", it is Invalid
   - If the docker image is not the most updated one it is still valid
        (however, a warning will be printed)
  """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.ignored_errors = {}
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'

        docker_image_validator.is_latest_tag = True
        docker_image_validator.docker_image_tag = '1.0.2'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is True
        assert docker_image_validator.is_latest_tag is True
        assert docker_image_validator.is_docker_image_valid() is True
Beispiel #4
0
def test_is_docker_image_latest_tag_with_tag_labeled_latest():
    """
    Given
    - A docker image with "latest" as tag

    When
    - The most updated docker image in docker-hub is '1.0.3'

    Then
    -  If the docker image is numeric and the most update one, it is Valid
    -  If the docker image is not numeric and labeled "latest", it is Invalid
   """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.ignored_errors = {}
        docker_image_validator.docker_image_latest_tag = 'latest'
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.file_path = "PATH"

        docker_image_validator.is_latest_tag = True
        docker_image_validator.is_valid = True
        docker_image_validator.docker_image_tag = 'latest'

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
def mock_docker_image_validator():
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.checked_files = set()
        docker_image_validator.suppress_print = False
        docker_image_validator.json_file_path = ''
        return docker_image_validator
Beispiel #6
0
def test_get_docker_image_latest_tag(image, mocker):
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = []
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        tag = docker_image_validator.get_docker_image_latest_tag(
            docker_image_name='demisto/' + image, yml_docker_image='')
    # current latest tag is 2.7.16.2728 or 3.7.2.2728 disable-secrets-detection
    assert int(tag.split('.')[3]) >= 2728
Beispiel #7
0
def test_none_demisto_docker(docker, docker_tag, expected_output):
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        assert docker_image_validator.get_docker_image_latest_tag(
            docker_image_name=docker,
            yml_docker_image='{}:{}'.format(docker,
                                            docker_tag)) == expected_output
Beispiel #8
0
def mock_docker_image_validator():
    with mock.patch.object(DockerImageValidator, '__init__', lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.checked_files = set()
        docker_image_validator.suppress_print = False
        docker_image_validator.json_file_path = ''
        docker_image_validator.specific_validations = None
        docker_image_validator.predefined_deprecated_ignored_errors = {}
        docker_image_validator.predefined_by_support_ignored_errors = {}
        return docker_image_validator
Beispiel #9
0
 def test_none_demisto_docker(self, docker, docker_tag, expected_output):
     with mock.patch.object(DockerImageValidator, '__init__',
                            lambda x, y, z, w: None):
         docker_image_validator = DockerImageValidator(None, None, None)
         docker_image_validator.yml_file = {}
         docker_image_validator.file_path = "PATH"
         docker_image_validator.ignored_errors = {}
         docker_image_validator.checked_files = set()
         docker_image_validator.suppress_print = False
         assert docker_image_validator.get_docker_image_latest_tag(
             docker_image_name=docker,
             yml_docker_image='{}:{}'.format(docker,
                                             docker_tag)) == expected_output
Beispiel #10
0
def test_parse_docker_image():
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        assert 'demisto/python', '1.3-alpine' == docker_image_validator.parse_docker_image(
            docker_image='demisto/python:1.3-alpine')
        assert 'demisto/slack', '1.2.3.4' == docker_image_validator.parse_docker_image(
            docker_image='demisto/slack:1.2.3.4')
        assert 'demisto/python', '' == docker_image_validator.parse_docker_image(
            docker_image='demisto/python/1.2.3.4')
        assert ('', '') == docker_image_validator.parse_docker_image(
            docker_image='blah/blah:1.2.3.4')