diff options
author | Petr Viktorin <encukou@gmail.com> | 2023-04-25 12:56:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 12:56:01 (GMT) |
commit | c8c3956d905e019101038b018129a4c90c9c9b8f (patch) | |
tree | b1d551e33222a766f5c7d2111b9e95faa8d5676a | |
parent | 83305808000e03cbad31ac3e9ef65454fb409282 (diff) | |
download | cpython-c8c3956d905e019101038b018129a4c90c9c9b8f.zip cpython-c8c3956d905e019101038b018129a4c90c9c9b8f.tar.gz cpython-c8c3956d905e019101038b018129a4c90c9c9b8f.tar.bz2 |
gh-102950: Adjust tarfile filter tests for systems that don't set the sticky bit (GH-103831)
Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.
-rw-r--r-- | Lib/test/test_tarfile.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ba25590..e8d322d 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -3635,15 +3635,35 @@ class TestExtractionFilters(unittest.TestCase): arc.add('exec_group_other', mode='?rw-rwxrwx') arc.add('read_group_only', mode='?---r-----') arc.add('no_bits', mode='?---------') - arc.add('dir/', mode='?---rwsrwt', type=tarfile.DIRTYPE) + arc.add('dir/', mode='?---rwsrwt') + + # On some systems, setting the sticky bit is a no-op. + # Check if that's the case. + tmp_filename = os.path.join(TEMPDIR, "tmp.file") + with open(tmp_filename, 'w'): + pass + os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX) + have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX) + os.unlink(tmp_filename) + + os.mkdir(tmp_filename) + os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX) + have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX) + os.rmdir(tmp_filename) with self.check_context(arc.open(), 'fully_trusted'): - self.expect_file('all_bits', mode='?rwsrwsrwt') + if have_sticky_files: + self.expect_file('all_bits', mode='?rwsrwsrwt') + else: + self.expect_file('all_bits', mode='?rwsrwsrwx') self.expect_file('perm_bits', mode='?rwxrwxrwx') self.expect_file('exec_group_other', mode='?rw-rwxrwx') self.expect_file('read_group_only', mode='?---r-----') self.expect_file('no_bits', mode='?---------') - self.expect_file('dir', type=tarfile.DIRTYPE, mode='?---rwsrwt') + if have_sticky_dirs: + self.expect_file('dir/', mode='?---rwsrwt') + else: + self.expect_file('dir/', mode='?---rwsrwx') with self.check_context(arc.open(), 'tar'): self.expect_file('all_bits', mode='?rwxr-xr-x') @@ -3651,7 +3671,7 @@ class TestExtractionFilters(unittest.TestCase): self.expect_file('exec_group_other', mode='?rw-r-xr-x') self.expect_file('read_group_only', mode='?---r-----') self.expect_file('no_bits', mode='?---------') - self.expect_file('dir/', type=tarfile.DIRTYPE, mode='?---r-xr-x') + self.expect_file('dir/', mode='?---r-xr-x') with self.check_context(arc.open(), 'data'): normal_dir_mode = stat.filemode(stat.S_IMODE( @@ -3661,7 +3681,7 @@ class TestExtractionFilters(unittest.TestCase): self.expect_file('exec_group_other', mode='?rw-r--r--') self.expect_file('read_group_only', mode='?rw-r-----') self.expect_file('no_bits', mode='?rw-------') - self.expect_file('dir/', type=tarfile.DIRTYPE, mode=normal_dir_mode) + self.expect_file('dir/', mode=normal_dir_mode) def test_pipe(self): # Test handling of a special file |