@@ -27,7 +27,7 @@ def test_cmd_exitcode(modules, state_tree, exit_code, return_code, result):
2727 ret = modules .state .single (
2828 "cmd.run" ,
2929 name = f"exit { exit_code } " ,
30- shell = ' cmd' ,
30+ shell = " cmd" ,
3131 success_retcodes = [2 , 44 , 300 ],
3232 )
3333 assert ret .result is result
@@ -47,7 +47,7 @@ def test_cmd_exitcode_runas(
4747 ret = modules .state .single (
4848 "cmd.run" ,
4949 name = f"exit { exit_code } " ,
50- shel = ' cmd' ,
50+ shell = " cmd" ,
5151 success_retcodes = [2 , 44 , 300 ],
5252 runas = account .username ,
5353 password = account .password ,
@@ -60,8 +60,9 @@ def test_cmd_exitcode_runas(
6060 "command, expected" ,
6161 [
6262 ("echo foo" , "foo" ),
63+ ("cmd /c echo foo" , "foo" ),
6364 ("whoami && echo foo" , "foo" ),
64- (' echo "foo \ ' bar\' "' , '" foo \ ' bar\' "' ),
65+ (" echo \ " foo 'bar' \" " , " \" foo 'bar' \" " ),
6566 ('echo|set /p="foo" & echo|set /p="bar"' , "foobar" ),
6667 ('''echo "&<>[]|{}^=;!'+,`~ "''' , '''"&<>[]|{}^=;!'+,`~ "''' ),
6768 ],
@@ -70,16 +71,17 @@ def test_cmd_builtins(modules, command, expected):
7071 """
7172 Test builtin cmd.exe commands
7273 """
73- result = modules .cmd .run (command , shell = ' cmd' )
74+ result = modules .cmd .run (command , shell = " cmd" )
7475 assert expected in result
7576
7677
7778@pytest .mark .parametrize (
7879 "command, expected" ,
7980 [
8081 ("echo foo" , "foo" ),
82+ ("cmd /c echo foo" , "foo" ),
8183 ("whoami && echo foo" , "foo" ),
82- (' echo "foo \ ' bar\' "' , '" foo \ ' bar\' "' ),
84+ (" echo \ " foo 'bar' \" " , " \" foo 'bar' \" " ),
8385 ('echo|set /p="foo" & echo|set /p="bar"' , "foobar" ),
8486 ('''echo "&<>[]|{}^=;!'+,`~ "''' , '''"&<>[]|{}^=;!'+,`~ "''' ),
8587 ],
@@ -89,7 +91,7 @@ def test_cmd_builtins_runas(modules, account, command, expected):
8991 Test builtin cmd.exe commands with runas
9092 """
9193 result = modules .cmd .run (
92- cmd = command , shell = ' cmd' , runas = account .username , password = account .password
94+ cmd = command , shell = " cmd" , runas = account .username , password = account .password
9395 )
9496 assert expected in result
9597
@@ -142,25 +144,7 @@ def test_cmd_env(modules, command, env, expected):
142144 """
143145 Test cmd.run with environment variables
144146 """
145- result = modules .cmd .run_all (command , shell = 'cmd' , env = env )
146- assert isinstance (result ["pid" ], int )
147- assert result ["retcode" ] == 0
148- assert result ["stdout" ] == expected
149- assert result ["stderr" ] == ""
150-
151- @pytest .mark .parametrize (
152- "command, env, expected" ,
153- [
154- ("echo %a%%b%" , {"a" : "foo" , "b" : "bar" }, "foobar" ),
155- ],
156- )
157- def test_cmd_env_runas (modules , account , command , env , expected ):
158- """
159- Test cmd.run with environment variables and runas
160- """
161- result = modules .cmd .run_all (
162- command , shell = 'cmd' , env = env , runas = account .username , password = account .password
163- )
147+ result = modules .cmd .run_all (command , shell = "cmd" , env = env )
164148 assert isinstance (result ["pid" ], int )
165149 assert result ["retcode" ] == 0
166150 assert result ["stdout" ] == expected
@@ -187,30 +171,3 @@ def test_redirect_stderr(modules, command, expected, redirect_stderr):
187171 else :
188172 assert result ["stdout" ] == ""
189173 assert expected in result ["stderr" ]
190-
191-
192- @pytest .mark .parametrize (
193- "command, expected, redirect_stderr" ,
194- [
195- (["whoami.exe" , "/foo" ], "/foo" , True ),
196- (["whoami.exe" , "/foo" ], "/foo" , False ),
197- ],
198- )
199- def test_redirect_stderr_runas (modules , account , command , expected , redirect_stderr ):
200- """
201- Test redirection of stderr to stdout by running cmd.run_all with runas and invalid commands
202- """
203- result = modules .cmd .run_all (
204- command ,
205- runas = account .username ,
206- password = account .password ,
207- redirect_stderr = redirect_stderr ,
208- )
209- assert isinstance (result ["pid" ], int )
210- assert result ["retcode" ] == 1
211- if redirect_stderr :
212- assert expected in result ["stdout" ]
213- assert result ["stderr" ] == ""
214- else :
215- assert result ["stdout" ] == ""
216- assert expected in result ["stderr" ]
0 commit comments