fix netrc security checks on WASI · python/cpython@c472cc9 · GitHub
Skip to content

Commit c472cc9

Browse files
committed
fix netrc security checks on WASI
1 parent ac9d37c commit c472cc9

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

Lib/netrc.py

Lines changed: 16 additions & 10 deletions

Lib/test/test_netrc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import netrc, os, unittest, sys, textwrap
2+
from test import support
23
from test.support import os_helper
34

4-
try:
5-
import pwd
6-
except ImportError:
7-
pwd = None
8-
95
temp_filename = os_helper.TESTFN
106

117
class NetrcTestCase(unittest.TestCase):
@@ -269,9 +265,14 @@ def test_comment_at_end_of_machine_line_pass_has_hash(self):
269265
machine bar.domain.com login foo password pass
270266
""", '#pass')
271267

268+
@unittest.skipUnless(support.is_wasi, 'WASI only test')
269+
def test_security_on_WASI(self):
270+
self.assertFalse(netrc._can_security_check())
271+
self.assertEqual(netrc._getpwuid(0), 'uid 0')
272+
self.assertEqual(netrc._getpwuid(123456), 'uid 123456')
272273

273274
@unittest.skipUnless(os.name == 'posix', 'POSIX only test')
274-
@unittest.skipIf(pwd is None, 'security check requires pwd module')
275+
@unittest.skipUnless(hasattr(os, 'getuid'), "os.getuid is required")
275276
@os_helper.skip_unless_working_chmod
276277
def test_security(self):
277278
# This test is incomplete since we are normally not run as root and
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)