def test_validpath(self): # Tests for validpath method. fs = AbstractedFS(u('/'), None) fs._root = HOME self.assertTrue(fs.validpath(HOME)) self.assertTrue(fs.validpath(HOME + '/')) self.assertFalse(fs.validpath(HOME + 'bar'))
def test_validpath_validlink(self): # Test validpath by issuing a symlink pointing to a path # inside the root directory. testfn = self.get_testfn() testfn2 = self.get_testfn() fs = AbstractedFS(u('/'), None) fs._root = HOME touch(testfn) os.symlink(testfn, testfn2) self.assertTrue(fs.validpath(u(testfn)))
def test_validpath_validlink(self): # Test validpath by issuing a symlink pointing to a path # inside the root directory. fs = AbstractedFS(u('/'), None) fs._root = HOME TESTFN2 = TESTFN + '1' try: touch(TESTFN) os.symlink(TESTFN, TESTFN2) self.assertTrue(fs.validpath(u(TESTFN))) finally: safe_remove(TESTFN, TESTFN2)
def test_validpath_external_symlink(self): # Test validpath by issuing a symlink pointing to a path # outside the root directory. fs = AbstractedFS(u('/'), None) fs._root = HOME # tempfile should create our file in /tmp directory # which should be outside the user root. If it is # not we just skip the test. with tempfile.NamedTemporaryFile() as file: try: if HOME == os.path.dirname(file.name): return os.symlink(file.name, TESTFN) self.assertFalse(fs.validpath(u(TESTFN))) finally: safe_remove(TESTFN)