[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / 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.
 #
 # 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
+    )