Skip to content

Commit cb9c17d

Browse files
tiranvstinner
authored andcommitted
pythongh-84461: Fix Emscripten umask and permission issues (pythonGH-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)
1 parent 9007571 commit cb9c17d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Lib/test/libregrtest/main.py

+12
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ def save_xml_result(self):
600600
for s in ET.tostringlist(root):
601601
f.write(s)
602602

603+
def fix_umask(self):
604+
if support.is_emscripten:
605+
# Emscripten has default umask 0o777, which breaks some tests.
606+
# see https://github.com/emscripten-core/emscripten/issues/17269
607+
old_mask = os.umask(0)
608+
if old_mask == 0o777:
609+
os.umask(0o027)
610+
else:
611+
os.umask(old_mask)
612+
603613
def set_temp_dir(self):
604614
if self.ns.tempdir:
605615
self.tmp_dir = self.ns.tempdir
@@ -660,6 +670,8 @@ def main(self, tests=None, **kwargs):
660670

661671
self.set_temp_dir()
662672

673+
self.fix_umask()
674+
663675
if self.ns.cleanup:
664676
self.cleanup()
665677
sys.exit(0)

Lib/test/test_posix.py

+3
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def check_stat(uid, gid):
787787
check_stat(uid, gid)
788788

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

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

@@ -1356,6 +1358,7 @@ def test_chmod_dir_fd(self):
13561358

13571359
@unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd),
13581360
"test needs dir_fd support in os.chown()")
1361+
@unittest.skipIf(support.is_emscripten, "getgid() is a stub")
13591362
def test_chown_dir_fd(self):
13601363
with self.prepare_file() as (dir_fd, name, fullname):
13611364
posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)

Lib/test/test_pydoc.py

+1
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ def test_apropos_with_unreadable_dir(self):
950950
self.assertEqual(err.getvalue(), '')
951951

952952
@os_helper.skip_unless_working_chmod
953+
@unittest.skipIf(is_emscripten, "cannot remove x bit")
953954
def test_apropos_empty_doc(self):
954955
pkgdir = os.path.join(TESTFN, 'walkpkg')
955956
os.mkdir(pkgdir)

0 commit comments

Comments
 (0)