object_id = '/' is invalid

This commit is contained in:
Darko Poljak 2017-08-10 19:08:44 +02:00
parent 260303dd14
commit ca1cc0f64a
2 changed files with 14 additions and 5 deletions

View File

@ -21,9 +21,7 @@
#
#
import fnmatch
import os
import collections
import cdist
import cdist.core
@ -142,9 +140,13 @@ class CdistObject(object):
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 .')
_invalid_object_ids = ('.', '/', )
for ioid in _invalid_object_ids:
if self.object_id == ioid:
raise IllegalObjectIdError(
self.object_id,
'object_id may not be a {}'.format(ioid))
# If no object_id and type is not singleton => error out
if not self.object_id and not self.cdist_type.is_singleton:

View File

@ -147,6 +147,13 @@ class ObjectIdTestCase(test.CdistTestCase):
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
def test_object_id_equals_slash(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = '/'
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, 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'