diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-12-02 18:29:18 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-12-02 18:29:18 (GMT) |
commit | 52173d4959a1c1e961efab2522e4ba8a22a3c7c6 (patch) | |
tree | a89463de7c0db84aa60ef25bc05caf8837e2cc33 /Lib/test/test_posixpath.py | |
parent | 02524629f39bb70f4ea00ab8e64d694e08719227 (diff) | |
download | cpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.zip cpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.tar.gz cpython-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.tar.bz2 |
Fix #9333. Expose os.symlink on Windows only when usable.
In order to create symlinks on Windows, SeCreateSymbolicLinkPrivilege
is an account privilege that is required to be held by the user. Not only
must the privilege be enabled for the account, the activated privileges for
the currently running application must be adjusted to enable the requested
privilege.
Rather than exposing an additional function to be called prior to the user's
first os.symlink call, we handle the AdjustTokenPrivileges Windows API call
internally and only expose os.symlink when the privilege escalation was
successful.
Due to the change of only exposing os.symlink when it's available, we can
go back to the original test skipping methods of checking via `hasattr`.
Diffstat (limited to 'Lib/test/test_posixpath.py')
-rw-r--r-- | Lib/test/test_posixpath.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 8cac0df..4042595 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -155,7 +155,7 @@ class PosixPathTest(unittest.TestCase): f.write(b"foo") f.close() self.assertIs(posixpath.islink(support.TESTFN + "1"), False) - if support.can_symlink(): + if hasattr(os, "symlink"): os.symlink(support.TESTFN + "1", support.TESTFN + "2") self.assertIs(posixpath.islink(support.TESTFN + "2"), True) os.remove(support.TESTFN + "1") @@ -180,7 +180,8 @@ class PosixPathTest(unittest.TestCase): @unittest.skipIf( sys.platform.startswith('win'), "posixpath.samefile does not work on links in Windows") - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") def test_samefile_on_links(self): test_fn1 = support.TESTFN + "1" test_fn2 = support.TESTFN + "2" @@ -204,7 +205,8 @@ class PosixPathTest(unittest.TestCase): @unittest.skipIf( sys.platform.startswith('win'), "posixpath.samestat does not work on links in Windows") - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") def test_samestat_on_links(self): test_fn1 = support.TESTFN + "1" test_fn2 = support.TESTFN + "2" @@ -273,7 +275,8 @@ class PosixPathTest(unittest.TestCase): self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"), b"/foo/bar") - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash def test_realpath_basic(self): # Basic operation. @@ -283,7 +286,8 @@ class PosixPathTest(unittest.TestCase): finally: support.unlink(ABSTFN) - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash def test_realpath_symlink_loops(self): # Bug #930024, return the path unchanged if we get into an infinite @@ -307,7 +311,8 @@ class PosixPathTest(unittest.TestCase): support.unlink(ABSTFN+"1") support.unlink(ABSTFN+"2") - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash def test_realpath_resolve_parents(self): # We also need to resolve any symlinks in the parents of a relative @@ -328,7 +333,8 @@ class PosixPathTest(unittest.TestCase): safe_rmdir(ABSTFN + "/y") safe_rmdir(ABSTFN) - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash def test_realpath_resolve_before_normalizing(self): # Bug #990669: Symbolic links should be resolved before we @@ -358,7 +364,8 @@ class PosixPathTest(unittest.TestCase): safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN) - @support.skip_unless_symlink + @unittest.skipUnless(hasattr(os, "symlink"), + "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash def test_realpath_resolve_first(self): # Bug #1213894: The first component of the path, if not absolute, |