Esempio n. 1
0
def test_invalid_node_property_secrets(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    secrets = [
        KubernetesSecret("ENV_VAR1", "test-secret", "test-key1"),  # valid
        KubernetesSecret("ENV_VAR2", "test-secret", "test-key2"),  # valid
        KubernetesSecret("ENV_VAR3", "test-secret",
                         ""),  # invalid: improper format of secret name/key
        KubernetesSecret(
            "ENV_VAR5", "test%secret",
            "test-key"),  # invalid: not a valid Kubernetes resource name
        KubernetesSecret(
            "ENV_VAR6", "test-secret",
            "test$key2"),  # invalid: not a valid Kubernetes secret key
    ]
    validation_manager._validate_kubernetes_secrets(
        node_id=node["id"],
        node_label=node["app_data"]["label"],
        secrets=secrets,
        response=response)
    issues = response.to_json().get("issues")
    assert issues[0]["severity"] == 1
    assert issues[0]["type"] == "invalidKubernetesSecret"
    assert issues[0]["data"]["propertyName"] == KUBERNETES_SECRETS
    assert issues[0]["data"]["nodeID"] == "test-id"
    assert "improperly formatted representation of secret name and key" in issues[
        0]["message"]
    assert "not a valid Kubernetes resource name" in issues[1]["message"]
    assert "not a valid Kubernetes secret key" in issues[2]["message"]
Esempio n. 2
0
def test_valid_node_property_label_min_length(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    valid_label_name = "d"
    validation_manager._validate_label(node_id=node["id"],
                                       node_label=valid_label_name,
                                       response=response)
    issues = response.to_json().get("issues")
    assert len(issues) == 0
Esempio n. 3
0
def test_valid_node_property_label(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id"}
    valid_label_name = "dead-bread-dead-bread-dead-bread-dead-bread-dead-bread-dead-bre"
    validation_manager._validate_label(node_id=node["id"],
                                       node_label=valid_label_name,
                                       response=response)
    issues = response.to_json().get("issues")
    assert len(issues) == 0
Esempio n. 4
0
def test_invalid_node_property_label_bad_characters(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id"}
    invalid_label_name = "bad_label_*&^&$"
    validation_manager._validate_label(node_id=node["id"],
                                       node_label=invalid_label_name,
                                       response=response)
    issues = response.to_json().get("issues")
    assert len(issues) == 1
    assert issues[0]["severity"] == 2
    assert issues[0]["type"] == "invalidNodeLabel"
    assert issues[0]["data"]["propertyName"] == "label"
    assert issues[0]["data"]["nodeID"] == "test-id"
Esempio n. 5
0
def test_invalid_node_property_label_max_length(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    invalid_label_name = "dead-bread-dead-bread-dead-bread-dead-bread-dead-bread-dead-bred"
    validation_manager._validate_label(node_id=node["id"],
                                       node_label=invalid_label_name,
                                       response=response)
    issues = response.to_json().get("issues")
    assert len(issues) == 1
    assert issues[0]["severity"] == 2
    assert issues[0]["type"] == "invalidNodeLabel"
    assert issues[0]["data"]["propertyName"] == "label"
    assert issues[0]["data"]["nodeID"] == "test-id"
Esempio n. 6
0
def test_invalid_node_property_env_var(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    invalid_env_var = 'TEST_ENV_ONE"test_one"'
    validation_manager._validate_environmental_variables(
        node_id=node["id"],
        node_label=node["app_data"]["label"],
        env_var=invalid_env_var,
        response=response)
    issues = response.to_json().get("issues")
    assert issues[0]["severity"] == 1
    assert issues[0]["type"] == "invalidEnvPair"
    assert issues[0]["data"]["propertyName"] == "env_vars"
    assert issues[0]["data"]["nodeID"] == "test-id"
Esempio n. 7
0
def test_invalid_node_property_image_name_list(validation_manager):
    response = ValidationResponse()
    node_label = "test_label"
    node_id = "test-id"
    failing_image_names = [
        "12345566:one-two-three",
        "someregistry.io/some_org/some_tag/something/",
        "docker.io//missing_org_name:test",
    ]

    for image_name in failing_image_names:
        validation_manager._validate_container_image_name(
            node_id, node_label, image_name, response)

    issues = response.to_json().get("issues")
    assert len(issues) == len(failing_image_names)
Esempio n. 8
0
def test_valid_node_property_dependency_filepath(validation_manager):
    response = ValidationResponse()
    valid_filename = os.path.join(
        os.path.dirname(__file__),
        "resources/validation_pipelines/generic_single_cycle.pipeline")
    node = {"id": "test-id", "app_data": {"label": "test"}}
    property_name = "test-property"

    validation_manager._validate_filepath(
        node_id=node["id"],
        file_dir=os.getcwd(),
        property_name=property_name,
        node_label=node["app_data"]["label"],
        filename=valid_filename,
        response=response,
    )

    assert not response.has_fatal
    assert not response.to_json().get("issues")
Esempio n. 9
0
def test_invalid_node_property_dependency_filepath_non_existent(
        validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    property_name = "test-property"

    validation_manager._validate_filepath(
        node_id=node["id"],
        file_dir=os.getcwd(),
        property_name=property_name,
        node_label=node["app_data"]["label"],
        filename="invalid_filepath/to/file.ipynb",
        response=response,
    )
    issues = response.to_json().get("issues")
    assert issues[0]["severity"] == 1
    assert issues[0]["type"] == "invalidFilePath"
    assert issues[0]["data"]["propertyName"] == property_name
    assert issues[0]["data"]["nodeID"] == node["id"]
Esempio n. 10
0
def test_invalid_node_property_volumes(validation_manager):
    response = ValidationResponse()
    node = {"id": "test-id", "app_data": {"label": "test"}}
    volumes = [
        VolumeMount("/mount/test", "rwx-test-claim"),  # valid
        VolumeMount("/mount/test_two", "second-claim"),  # valid
        VolumeMount("/mount/test_four", "second#claim"),  # invalid pvc name
    ]
    validation_manager._validate_mounted_volumes(
        node_id=node["id"],
        node_label=node["app_data"]["label"],
        volumes=volumes,
        response=response)
    issues = response.to_json().get("issues")
    assert issues[0]["severity"] == 1
    assert issues[0]["type"] == "invalidVolumeMount"
    assert issues[0]["data"]["propertyName"] == MOUNTED_VOLUMES
    assert issues[0]["data"]["nodeID"] == "test-id"
    assert "not a valid Kubernetes resource name" in issues[0]["message"]
Esempio n. 11
0
    def _function(pipeline_filepath):
        response = ValidationResponse()

        pipeline = _read_pipeline_resource(
            f"resources/validation_pipelines/{pipeline_filepath}")
        return pipeline, response