Esempio n. 1
0
 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'))
Esempio n. 2
0
 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'))
Esempio n. 3
0
    def test_fs2ftp(self):
        # Tests for fs2ftp method.
        def join(x, y):
            return os.path.join(x, y.replace('/', os.sep))

        ae = self.assertEqual
        fs = AbstractedFS(u('/'), None)

        def goforit(root):
            fs._root = root
            ae(fs.fs2ftp(root), u('/'))
            ae(fs.fs2ftp(join(root, u('/'))), u('/'))
            ae(fs.fs2ftp(join(root, u('.'))), u('/'))
            # can't escape from root
            ae(fs.fs2ftp(join(root, u('..'))), u('/'))
            ae(fs.fs2ftp(join(root, u('a'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('a/'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('a/..'))), u('/'))
            ae(fs.fs2ftp(join(root, u('a/b'))), u('/a/b'))
            ae(fs.fs2ftp(join(root, u('a/b'))), u('/a/b'))
            ae(fs.fs2ftp(join(root, u('a/b/..'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('/a/b/../..'))), u('/'))
            fs._cwd = u('/sub')
            ae(fs.fs2ftp(join(root, 'a/')), u('/a'))

        if os.sep == '\\':
            goforit(u(r'C:\dir'))
            goforit(u('C:\\'))
            # on DOS-derived filesystems (e.g. Windows) this is the same
            # as specifying the current drive directory (e.g. 'C:\\')
            goforit(u('\\'))
            fs._root = u(r'C:\dir')
            ae(fs.fs2ftp(u('C:\\')), u('/'))
            ae(fs.fs2ftp(u('D:\\')), u('/'))
            ae(fs.fs2ftp(u('D:\\dir')), u('/'))
        elif os.sep == '/':
            goforit(u('/'))
            if os.path.realpath('/__home/user') != '/__home/user':
                self.fail('Test skipped (symlinks not allowed).')
            goforit(u('/__home/user'))
            fs._root = u('/__home/user')
            ae(fs.fs2ftp(u('/__home')), u('/'))
            ae(fs.fs2ftp(u('/')), u('/'))
            ae(fs.fs2ftp(u('/__home/userx')), u('/'))
        else:
            # os.sep == ':'? Don't know... let's try it anyway
            goforit(getcwdu())
Esempio n. 4
0
    def test_fs2ftp(self):
        # Tests for fs2ftp method.
        def join(x, y):
            return os.path.join(x, y.replace('/', os.sep))

        ae = self.assertEqual
        fs = AbstractedFS(u('/'), None)

        def goforit(root):
            fs._root = root
            ae(fs.fs2ftp(root), u('/'))
            ae(fs.fs2ftp(join(root, u('/'))), u('/'))
            ae(fs.fs2ftp(join(root, u('.'))), u('/'))
            # can't escape from root
            ae(fs.fs2ftp(join(root, u('..'))), u('/'))
            ae(fs.fs2ftp(join(root, u('a'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('a/'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('a/..'))), u('/'))
            ae(fs.fs2ftp(join(root, u('a/b'))), u('/a/b'))
            ae(fs.fs2ftp(join(root, u('a/b'))), u('/a/b'))
            ae(fs.fs2ftp(join(root, u('a/b/..'))), u('/a'))
            ae(fs.fs2ftp(join(root, u('/a/b/../..'))), u('/'))
            fs._cwd = u('/sub')
            ae(fs.fs2ftp(join(root, 'a/')), u('/a'))

        if os.sep == '\\':
            goforit(u(r'C:\dir'))
            goforit(u('C:\\'))
            # on DOS-derived filesystems (e.g. Windows) this is the same
            # as specifying the current drive directory (e.g. 'C:\\')
            goforit(u('\\'))
            fs._root = u(r'C:\dir')
            ae(fs.fs2ftp(u('C:\\')), u('/'))
            ae(fs.fs2ftp(u('D:\\')), u('/'))
            ae(fs.fs2ftp(u('D:\\dir')), u('/'))
        elif os.sep == '/':
            goforit(u('/'))
            if os.path.realpath('/__home/user') != '/__home/user':
                self.fail('Test skipped (symlinks not allowed).')
            goforit(u('/__home/user'))
            fs._root = u('/__home/user')
            ae(fs.fs2ftp(u('/__home')), u('/'))
            ae(fs.fs2ftp(u('/')), u('/'))
            ae(fs.fs2ftp(u('/__home/userx')), u('/'))
        else:
            # os.sep == ':'? Don't know... let's try it anyway
            goforit(getcwdu())
Esempio n. 5
0
 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)))
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)