Skip to content

Commit

Permalink
pythongh-84461: Fix Emscripten umask and permission issues (pythonGH-…
Browse files Browse the repository at this point in the history
…94002)

- Emscripten's default umask is too strict, see
  emscripten-core/emscripten#17269
- getuid/getgid and geteuid/getegid are stubs that always return 0
  (root). Disable effective uid/gid syscalls and fix tests that use
  chmod() current user.
- Cannot drop X bit from directory.

(cherry picked from commit 2702e40)
  • Loading branch information
tiran authored and vstinner committed Sep 2, 2023
1 parent 9007571 commit cb9c17d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ def save_xml_result(self):
for s in ET.tostringlist(root):
f.write(s)

def fix_umask(self):
if support.is_emscripten:
# Emscripten has default umask 0o777, which breaks some tests.
# see https://github.com/emscripten-core/emscripten/issues/17269
old_mask = os.umask(0)
if old_mask == 0o777:
os.umask(0o027)
else:
os.umask(old_mask)

def set_temp_dir(self):
if self.ns.tempdir:
self.tmp_dir = self.ns.tempdir
Expand Down Expand Up @@ -660,6 +670,8 @@ def main(self, tests=None, **kwargs):

self.set_temp_dir()

self.fix_umask()

if self.ns.cleanup:
self.cleanup()
sys.exit(0)
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ def check_stat(uid, gid):
check_stat(uid, gid)

@os_helper.skip_unless_working_chmod
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
def test_chown(self):
# raise an OSError if the file does not exist
os.unlink(os_helper.TESTFN)
Expand All @@ -798,6 +799,7 @@ def test_chown(self):

@os_helper.skip_unless_working_chmod
@unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
def test_fchown(self):
os.unlink(os_helper.TESTFN)

Expand Down Expand Up @@ -1356,6 +1358,7 @@ def test_chmod_dir_fd(self):

@unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd),
"test needs dir_fd support in os.chown()")
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
def test_chown_dir_fd(self):
with self.prepare_file() as (dir_fd, name, fullname):
posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ def test_apropos_with_unreadable_dir(self):
self.assertEqual(err.getvalue(), '')

@os_helper.skip_unless_working_chmod
@unittest.skipIf(is_emscripten, "cannot remove x bit")
def test_apropos_empty_doc(self):
pkgdir = os.path.join(TESTFN, 'walkpkg')
os.mkdir(pkgdir)
Expand Down

0 comments on commit cb9c17d

Please sign in to comment.