gh-107902: Don't test setting suid/sgid on systems that don't support them (GH-108368)
This commit is contained in:
parent
f3b6608ba2
commit
40e52c94a2
@ -3808,34 +3808,43 @@ class TestExtractionFilters(unittest.TestCase):
|
|||||||
arc.add('read_group_only', mode='?---r-----')
|
arc.add('read_group_only', mode='?---r-----')
|
||||||
arc.add('no_bits', mode='?---------')
|
arc.add('no_bits', mode='?---------')
|
||||||
arc.add('dir/', mode='?---rwsrwt')
|
arc.add('dir/', mode='?---rwsrwt')
|
||||||
|
arc.add('dir_all_bits/', mode='?rwsrwsrwt')
|
||||||
|
|
||||||
# On some systems, setting the sticky bit is a no-op.
|
# On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
|
||||||
# Check if that's the case.
|
# Check which bits we can set, so we can compare tarfile machinery to
|
||||||
|
# a simple chmod.
|
||||||
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
|
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
|
||||||
with open(tmp_filename, 'w'):
|
with open(tmp_filename, 'w'):
|
||||||
pass
|
pass
|
||||||
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
|
new_mode = (os.stat(tmp_filename).st_mode
|
||||||
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
|
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
|
||||||
|
os.chmod(tmp_filename, new_mode)
|
||||||
|
got_mode = os.stat(tmp_filename).st_mode
|
||||||
|
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
|
||||||
|
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
|
||||||
|
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
|
||||||
os.unlink(tmp_filename)
|
os.unlink(tmp_filename)
|
||||||
|
|
||||||
os.mkdir(tmp_filename)
|
os.mkdir(tmp_filename)
|
||||||
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
|
new_mode = (os.stat(tmp_filename).st_mode
|
||||||
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
|
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
|
||||||
|
os.chmod(tmp_filename, new_mode)
|
||||||
|
got_mode = os.stat(tmp_filename).st_mode
|
||||||
|
_t_dir = 't' if (got_mode & stat.S_ISVTX) else 'x'
|
||||||
|
_suid_dir = 's' if (got_mode & stat.S_ISUID) else 'x'
|
||||||
|
_sgid_dir = 's' if (got_mode & stat.S_ISGID) else 'x'
|
||||||
os.rmdir(tmp_filename)
|
os.rmdir(tmp_filename)
|
||||||
|
|
||||||
with self.check_context(arc.open(), 'fully_trusted'):
|
with self.check_context(arc.open(), 'fully_trusted'):
|
||||||
if have_sticky_files:
|
self.expect_file('all_bits',
|
||||||
self.expect_file('all_bits', mode='?rwsrwsrwt')
|
mode=f'?rw{_suid_file}rw{_sgid_file}rw{_t_file}')
|
||||||
else:
|
|
||||||
self.expect_file('all_bits', mode='?rwsrwsrwx')
|
|
||||||
self.expect_file('perm_bits', mode='?rwxrwxrwx')
|
self.expect_file('perm_bits', mode='?rwxrwxrwx')
|
||||||
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
|
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
|
||||||
self.expect_file('read_group_only', mode='?---r-----')
|
self.expect_file('read_group_only', mode='?---r-----')
|
||||||
self.expect_file('no_bits', mode='?---------')
|
self.expect_file('no_bits', mode='?---------')
|
||||||
if have_sticky_dirs:
|
self.expect_file('dir/', mode=f'?---rw{_sgid_dir}rw{_t_dir}')
|
||||||
self.expect_file('dir/', mode='?---rwsrwt')
|
self.expect_file('dir_all_bits/',
|
||||||
else:
|
mode=f'?rw{_suid_dir}rw{_sgid_dir}rw{_t_dir}')
|
||||||
self.expect_file('dir/', mode='?---rwsrwx')
|
|
||||||
|
|
||||||
with self.check_context(arc.open(), 'tar'):
|
with self.check_context(arc.open(), 'tar'):
|
||||||
self.expect_file('all_bits', mode='?rwxr-xr-x')
|
self.expect_file('all_bits', mode='?rwxr-xr-x')
|
||||||
@ -3844,6 +3853,7 @@ class TestExtractionFilters(unittest.TestCase):
|
|||||||
self.expect_file('read_group_only', mode='?---r-----')
|
self.expect_file('read_group_only', mode='?---r-----')
|
||||||
self.expect_file('no_bits', mode='?---------')
|
self.expect_file('no_bits', mode='?---------')
|
||||||
self.expect_file('dir/', mode='?---r-xr-x')
|
self.expect_file('dir/', mode='?---r-xr-x')
|
||||||
|
self.expect_file('dir_all_bits/', mode='?rwxr-xr-x')
|
||||||
|
|
||||||
with self.check_context(arc.open(), 'data'):
|
with self.check_context(arc.open(), 'data'):
|
||||||
normal_dir_mode = stat.filemode(stat.S_IMODE(
|
normal_dir_mode = stat.filemode(stat.S_IMODE(
|
||||||
@ -3854,6 +3864,7 @@ class TestExtractionFilters(unittest.TestCase):
|
|||||||
self.expect_file('read_group_only', mode='?rw-r-----')
|
self.expect_file('read_group_only', mode='?rw-r-----')
|
||||||
self.expect_file('no_bits', mode='?rw-------')
|
self.expect_file('no_bits', mode='?rw-------')
|
||||||
self.expect_file('dir/', mode=normal_dir_mode)
|
self.expect_file('dir/', mode=normal_dir_mode)
|
||||||
|
self.expect_file('dir_all_bits/', mode=normal_dir_mode)
|
||||||
|
|
||||||
def test_pipe(self):
|
def test_pipe(self):
|
||||||
# Test handling of a special file
|
# Test handling of a special file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user