mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-76912: Raise OSError from any failure in getpass.getuser() (#29739)
* bpo-32731: Raise OSError from any failure in getpass.getuser() Previously, if the username was not set in certain environment variables, ImportError escaped on Windows systems, and it was possible for KeyError to escape on other systems if getpwuid() failed.
This commit is contained in:
parent
936c503a44
commit
99a73c3465
5 changed files with 24 additions and 7 deletions
|
@ -26,7 +26,7 @@ class GetpassGetuserTest(unittest.TestCase):
|
|||
environ.get.return_value = None
|
||||
try:
|
||||
getpass.getuser()
|
||||
except ImportError: # in case there's no pwd module
|
||||
except OSError: # in case there's no pwd module
|
||||
pass
|
||||
except KeyError:
|
||||
# current user has no pwd entry
|
||||
|
@ -47,7 +47,7 @@ class GetpassGetuserTest(unittest.TestCase):
|
|||
getpass.getuser())
|
||||
getpw.assert_called_once_with(42)
|
||||
else:
|
||||
self.assertRaises(ImportError, getpass.getuser)
|
||||
self.assertRaises(OSError, getpass.getuser)
|
||||
|
||||
|
||||
class GetpassRawinputTest(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue