22# SPDX-License-Identifier: Apache-2.0
33
44import asyncio
5+ from collections import namedtuple
56import logging
67import multiprocessing as MP
78import os
@@ -141,6 +142,17 @@ def test_setuid(self, nobody_uid, mocker):
141142 main (args = ())
142143 mock .assert_called_with (nobody_uid )
143144
145+ def test_setuid_other (self , nobody_uid , mocker ):
146+ other_user = namedtuple (
147+ "pwnam" ,
148+ ["pw_uid" , "pw_dir" , "pw_shell" ],
149+ )(42 , "/" , "/bin/sh" )
150+ mock_getpwnam = mocker .patch ("pwd.getpwnam" , return_value = other_user )
151+ mock_suid = mocker .patch ("os.setuid" )
152+ main (args = ("-S" , "other" ))
153+ mock_getpwnam .assert_called_with ("other" )
154+ mock_suid .assert_called_with (42 )
155+
144156 def test_setuid_permission_error (self , nobody_uid , mocker , capsys ):
145157 mock = mocker .patch ("os.setuid" , side_effect = PermissionError )
146158 with pytest .raises (SystemExit ) as excinfo :
@@ -149,7 +161,7 @@ def test_setuid_permission_error(self, nobody_uid, mocker, capsys):
149161 mock .assert_called_with (nobody_uid )
150162 assert (
151163 capsys .readouterr ().err
152- == 'Cannot setuid "nobody"; try running with -n option.\n '
164+ == 'Cannot setuid to "nobody"; try running with -n option.\n '
153165 )
154166
155167 def test_setuid_no_pwd_module (self , nobody_uid , mocker , capsys ):
0 commit comments