From 2dd2f5593f5c32f0a0286d1b5ded27a623ee7b22 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Sun, 9 Feb 2014 17:10:43 +0100 Subject: [PATCH] bugfixes for issue 161 and FIXME: also check that there is no object ID when type is singleton? --- cdist/core/cdist_object.py | 5 ++++- cdist/test/cdist_object/__init__.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py index b17bd339..e8c58a67 100644 --- a/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -121,7 +121,8 @@ class CdistObject(object): return os.path.join(type_name, object_id) def validate_object_id(self): - # FIXME: also check that there is no object ID when type is singleton? + if self.cdist_type.is_singleton and self.object_id: + raise IllegalObjectIdError('singleton objects can\'t have a object_id') """Validate the given object_id and raise IllegalObjectIdError if it's not valid. """ @@ -130,6 +131,8 @@ class CdistObject(object): raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER) if '//' in self.object_id: raise IllegalObjectIdError(self.object_id, 'object_id may not contain //') + if self.object_id == '.': + raise IllegalObjectIdError(self.object_id, 'object_id may not be a .') # If no object_id and type is not singleton => error out if not self.object_id and not self.cdist_type.is_singleton: diff --git a/cdist/test/cdist_object/__init__.py b/cdist/test/cdist_object/__init__.py index 0e2da103..7396bc57 100644 --- a/cdist/test/cdist_object/__init__.py +++ b/cdist/test/cdist_object/__init__.py @@ -94,6 +94,17 @@ class ObjectIdTestCase(test.CdistTestCase): core.CdistObject(cdist_type, object_base_path, illegal_object_id) # if we get here, the test passed + def test_object_id_contains_only_dot(self): + cdist_type = core.CdistType(type_base_path, '__third') + illegal_object_id = '.' + with self.assertRaises(core.IllegalObjectIdError): + core.CdistObject(cdist_type, object_base_path, illegal_object_id) + + def test_object_id_on_singleton_type(self): + cdist_type = core.CdistType(type_base_path, '__test_singleton') + illegal_object_id = 'object_id' + with self.assertRaises(core.IllegalObjectIdError): + core.CdistObject(cdist_type, object_base_path, illegal_object_id) class ObjectTestCase(test.CdistTestCase):