From 5d4dfe055efe5deab537ab77f78a689186508545 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 11 May 2015 22:31:38 -0700 Subject: [PATCH] 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 --- taskflow/persistence/backends/impl_memory.py | 3 +++ taskflow/tests/unit/persistence/test_memory_persistence.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/taskflow/persistence/backends/impl_memory.py b/taskflow/persistence/backends/impl_memory.py index 31913a6b..e341f18f 100644 --- a/taskflow/persistence/backends/impl_memory.py +++ b/taskflow/persistence/backends/impl_memory.py @@ -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" diff --git a/taskflow/tests/unit/persistence/test_memory_persistence.py b/taskflow/tests/unit/persistence/test_memory_persistence.py index 2b3599e4..24f76aa3 100644 --- a/taskflow/tests/unit/persistence/test_memory_persistence.py +++ b/taskflow/tests/unit/persistence/test_memory_persistence.py @@ -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, '/')