Bug 667: NBI not validating that hyphens are not allowed in Jinja2 44/7444/4
authordelacruzramo <pedro.delacruzramos@altran.com>
Fri, 3 May 2019 12:52:37 +0000 (14:52 +0200)
committerdelacruzramo <pedro.delacruzramos@altran.com>
Mon, 13 May 2019 08:51:53 +0000 (09:51 +0100)
Change-Id: Ie70da179757808b7e7cfecb7f66c257fb347dcd0
Signed-off-by: delacruzramo <pedro.delacruzramos@altran.com>
osm_nbi/instance_topics.py

index e14590b..55845d6 100644 (file)
@@ -23,6 +23,7 @@ from base_topic import BaseTopic, EngineException, get_iterable
 from descriptor_topics import DescriptorTopic
 from yaml import safe_dump
 from osm_common.dbbase import DbException
+from re import match  # For checking that additional parameter names are valid Jinja2 identifiers
 
 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 
@@ -115,6 +116,12 @@ class NsrTopic(BaseTopic):
                     break
         if additional_params:
             for k, v in additional_params.items():
+                # BEGIN Check that additional parameter names are valid Jinja2 identifiers
+                if not match('^[a-zA-Z_][a-zA-Z0-9_]*$', k):
+                    raise EngineException("Invalid param name at {}:{}. Must contain only alphanumeric characters "
+                                          "and underscores, and cannot start with a digit"
+                                          .format(where_, k))
+                # END Check that additional parameter names are valid Jinja2 identifiers
                 if not isinstance(k, str):
                     raise EngineException("Invalid param at {}:{}. Only string keys are allowed".format(where_, k))
                 if "." in k or "$" in k: