Ensure empty paths raise a value error

Empty paths should not be allowed to be set or
fetched or normalized so check for those and raise
an error when one is encountered.

Also add some basic test conditions that ensure
the normpath method raises when it should.

Change-Id: I7f7e6600f03c67376ba310ab231b2e33cd7528db
This commit is contained in:
Joshua Harlow
2015-05-11 22:31:38 -07:00
parent 4e550ba48c
commit 5d4dfe055e
2 changed files with 9 additions and 0 deletions

View File

@@ -74,6 +74,9 @@ class FakeFilesystem(object):
@classmethod
def normpath(cls, path):
"""Return a normalized absolutized version of the pathname path."""
if not path:
raise ValueError("This filesystem can only normalize paths"
" that are not empty")
if not path.startswith(cls.root_path):
raise ValueError("This filesystem can only normalize"
" paths that start with %s: '%s' is not"

View File

@@ -128,6 +128,12 @@ class MemoryFilesystemTest(test.TestCase):
fs = impl_memory.FakeFilesystem()
self.assertRaises(exc.NotFound, self._get_item_path, fs, '/c')
def test_bad_norms(self):
fs = impl_memory.FakeFilesystem()
self.assertRaises(ValueError, fs.normpath, '')
self.assertRaises(ValueError, fs.normpath, 'abc/c')
self.assertRaises(ValueError, fs.normpath, '../c')
def test_del_root_not_allowed(self):
fs = impl_memory.FakeFilesystem()
self.assertRaises(ValueError, self._del_item_path, fs, '/')