X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vvp%2Fvalidation-scripts.git;a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_no_http_resources.py;fp=ice_validator%2Ftests%2Ftest_required_parameters_specified_in_heat_templates.py;h=6c01971fa133db3f48f077872b0936e8b6af4027;hp=9b387221945e8ba003c429207178acf67cc87491;hb=1f4df7c7ad27b23773ad9cdbe4db1632ce388cf1;hpb=ca9085f0f77d442d3741a8c754e65cc45b6a318d diff --git a/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py b/ice_validator/tests/test_no_http_resources.py similarity index 68% rename from ice_validator/tests/test_required_parameters_specified_in_heat_templates.py rename to ice_validator/tests/test_no_http_resources.py index 9b38722..6c01971 100644 --- a/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py +++ b/ice_validator/tests/test_no_http_resources.py @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,41 +37,38 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # +import re import pytest from tests import cached_yaml as yaml +from .helpers import validates -def test_required_parameters_provided_in_heat_template(heat_template): - ''' - Make sure all required parameters are specified properly - in the heat template if a server resource is defined - ''' - required_parameters = ["vnf_id", "vf_module_id", "vnf_name"] - provided_parameters = [] +VERSION = "1.0.0" - with open(heat_template) as fh: +# pylint: disable=invalid-name + + +@validates("R-71699", "R-53952") +def test_no_http_resources(yaml_file): + """Resources are prohibited from retrieving external + yaml files""" + is_url = re.compile(r"(?:http|https|file|ftp|ftps)://.+") + + with open(yaml_file) as fh: yml = yaml.load(fh) + # skip if parameters are not defined if "resources" not in yml: pytest.skip("No resources specified in the heat template") - server_count = 0 - for v in yml["resources"].values(): - if "type" not in v: + invalid_resources = [] + for rid, rprop in yml["resources"].items(): + rtype = rprop.get("type", "") + if is_url.match(rtype): + invalid_resources.append({"resource": rid, "url": rtype}) continue - if v["type"] == "OS::Nova::Server": - server_count += 1 - - if server_count == 0: - pytest.skip("No Nova Server resources specified in " + - "the heat template") - - if "parameters" not in yml: - pytest.fail("No parameters specified in the heat template") - - for k in yml["parameters"]: - if k in required_parameters: - provided_parameters.append(k) - assert set(required_parameters) == set(provided_parameters) + assert not invalid_resources, "External resource types detected {}".format( + invalid_resources + )