Skip to content

Commit 698a6d4

Browse files
committed
Fix test failure in test_tarfile, remove tests that aren't suitable for
security backports.
1 parent 371b4ea commit 698a6d4

File tree

2 files changed

+1
-102
lines changed

2 files changed

+1
-102
lines changed

Lib/test/test_posixpath.py

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -812,107 +812,6 @@ def test_realpath_unreadable_directory(self):
812812
safe_rmdir(ABSTFN + '/k')
813813
safe_rmdir(ABSTFN)
814814

815-
@skip_if_ABSTFN_contains_backslash
816-
def test_realpath_nonterminal_file(self):
817-
try:
818-
with open(ABSTFN, 'w') as f:
819-
f.write('test_posixpath wuz ere')
820-
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN)
821-
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN)
822-
self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN)
823-
824-
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN)
825-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True)
826-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/",
827-
strict=ALLOW_MISSING)
828-
829-
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN)
830-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True)
831-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.",
832-
strict=ALLOW_MISSING)
833-
834-
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN))
835-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True)
836-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..",
837-
strict=ALLOW_MISSING)
838-
839-
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "/subdir")
840-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True)
841-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir",
842-
strict=ALLOW_MISSING)
843-
finally:
844-
os_helper.unlink(ABSTFN)
845-
846-
@os_helper.skip_unless_symlink
847-
@skip_if_ABSTFN_contains_backslash
848-
def test_realpath_nonterminal_symlink_to_file(self):
849-
try:
850-
with open(ABSTFN + "1", 'w') as f:
851-
f.write('test_posixpath wuz ere')
852-
os.symlink(ABSTFN + "1", ABSTFN)
853-
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN + "1")
854-
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "1")
855-
self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN + "1")
856-
857-
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN + "1")
858-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True)
859-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/",
860-
strict=ALLOW_MISSING)
861-
862-
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN + "1")
863-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True)
864-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.",
865-
strict=ALLOW_MISSING)
866-
867-
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN))
868-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True)
869-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..",
870-
strict=ALLOW_MISSING)
871-
872-
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "1/subdir")
873-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True)
874-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir",
875-
strict=ALLOW_MISSING)
876-
finally:
877-
os_helper.unlink(ABSTFN)
878-
os_helper.unlink(ABSTFN + "1")
879-
880-
@os_helper.skip_unless_symlink
881-
@skip_if_ABSTFN_contains_backslash
882-
def test_realpath_nonterminal_symlink_to_symlinks_to_file(self):
883-
try:
884-
with open(ABSTFN + "2", 'w') as f:
885-
f.write('test_posixpath wuz ere')
886-
os.symlink(ABSTFN + "2", ABSTFN + "1")
887-
os.symlink(ABSTFN + "1", ABSTFN)
888-
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN + "2")
889-
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "2")
890-
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "2")
891-
892-
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN + "2")
893-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True)
894-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/",
895-
strict=ALLOW_MISSING)
896-
897-
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN + "2")
898-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True)
899-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.",
900-
strict=ALLOW_MISSING)
901-
902-
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN))
903-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True)
904-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..",
905-
strict=ALLOW_MISSING)
906-
907-
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "2/subdir")
908-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True)
909-
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir",
910-
strict=ALLOW_MISSING)
911-
finally:
912-
os_helper.unlink(ABSTFN)
913-
os_helper.unlink(ABSTFN + "1")
914-
os_helper.unlink(ABSTFN + "2")
915-
916815
def test_relpath(self):
917816
(real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
918817
try:

Lib/test/test_tarfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,7 @@ def check_files_present(self, directory):
31303130
got_paths = set(
31313131
p.relative_to(directory)
31323132
for p in pathlib.Path(directory).glob('**/*'))
3133-
if self.extraction_filter in (None, 'data'):
3133+
if self.extraction_filter == 'data':
31343134
# The 'data' filter is expected to reject special files
31353135
for path in 'ustar/fifotype', 'ustar/blktype', 'ustar/chrtype':
31363136
got_paths.discard(pathlib.Path(path))

0 commit comments

Comments
 (0)