From f285d9e64ee1e3e3111eab7ccba0099097fac43e Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:39:55 +0200 Subject: [PATCH] emulator: fail if object_id of requirement starts with slash Signed-off-by: Steven Armstrong --- lib/cdist/emulator.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 4445f0f7..ca65e731 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -106,8 +106,19 @@ def run(argv): # Record requirements if "require" in os.environ: requirements = os.environ['require'] - log.debug("%s:Writing requirements: %s" % (cdist_object.path, requirements)) - cdist_object.requirements.extend(requirements.split(" ")) + for requirement in requirements.split(" "): + requirement_parts = requirement.split(os.sep, 1) + requirement_parts.reverse() + requirement_type_name = requirement_parts.pop() + try: + requirement_object_id = requirement_parts.pop() + except IndexError: + # no object id, must be singleton + requirement_object_id = 'singleton' + if requirement_object_id.startswith('/'): + raise core.IllegalObjectIdError(requirement_object_id, 'object_id may not start with /') + log.debug("Recording requirement: %s -> %s" % (cdist_object.path, requirement)) + cdist_object.requirements.append(rement_object_id) # Record / Append source cdist_object.source.append(object_source)