def test_check_safe_path(self): if not tests_utils.coreutils_readlink_available(): self.skipTest("coreutils readlink(1) unavailable") vfs = vfsimpl.VFSLocalFS("dummy.img") vfs.imgdir = "/foo" ret = vfs._canonical_path('etc/something.conf') self.assertEqual(ret, '/foo/etc/something.conf')
def test_check_unsafe_path(self): if not tests_utils.coreutils_readlink_available(): self.skipTest("coreutils readlink(1) unavailable") vfs = vfsimpl.VFSLocalFS("dummy.img") vfs.imgdir = "/foo" self.assertRaises(exception.Invalid, vfs._canonical_path, 'etc/../../../something.conf')