mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Fix hanging test
This commit is contained in:
parent
4524d8a54a
commit
ab9e02a1a9
3 changed files with 13 additions and 11 deletions
|
@ -296,7 +296,7 @@ def _prep_powershell_cmd(win_shell, cmd, encoded_cmd):
|
|||
keywords = ["$", "&", ".", "Configuration", "try"]
|
||||
|
||||
for keyword in keywords:
|
||||
if cmd.startswith(keyword):
|
||||
if cmd.lower().startswith(keyword.lower()):
|
||||
new_cmd.extend(["-Command", f"{cmd.strip()}"])
|
||||
break
|
||||
else:
|
||||
|
|
|
@ -199,6 +199,9 @@ def runas(cmdLine, username, password=None, cwd=None):
|
|||
# Create the environment for the user
|
||||
env = create_env(user_token, False)
|
||||
|
||||
if "&&" in cmdLine:
|
||||
cmdLine = f'cmd /c "{cmdLine}"'
|
||||
|
||||
hProcess = None
|
||||
try:
|
||||
# Start the process in a suspended state.
|
||||
|
@ -206,7 +209,7 @@ def runas(cmdLine, username, password=None, cwd=None):
|
|||
int(user_token),
|
||||
logonflags=1,
|
||||
applicationname=None,
|
||||
commandline=f'cmd /c "{cmdLine}"',
|
||||
commandline=cmdLine,
|
||||
currentdirectory=cwd,
|
||||
creationflags=creationflags,
|
||||
startupinfo=startup_info,
|
||||
|
@ -297,6 +300,9 @@ def runas_unpriv(cmd, username, password, cwd=None):
|
|||
hStdError=errwrite,
|
||||
)
|
||||
|
||||
if "&&" in cmd:
|
||||
cmd = f'cmd /c "{cmd}"'
|
||||
|
||||
try:
|
||||
# Run command and return process info structure
|
||||
process_info = salt.platform.win.CreateProcessWithLogonW(
|
||||
|
@ -304,7 +310,7 @@ def runas_unpriv(cmd, username, password, cwd=None):
|
|||
domain=domain,
|
||||
password=password,
|
||||
logonflags=salt.platform.win.LOGON_WITH_PROFILE,
|
||||
commandline=f'cmd /c "{cmd}"',
|
||||
commandline=cmd,
|
||||
startupinfo=startup_info,
|
||||
currentdirectory=cwd,
|
||||
)
|
||||
|
|
|
@ -4,8 +4,6 @@ Test the win_runas util
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.modules.win_useradd as win_user
|
||||
import salt.utils.win_functions as win_functions
|
||||
import salt.utils.win_runas as win_runas
|
||||
|
||||
pytestmark = [
|
||||
|
@ -32,8 +30,6 @@ def test_compound_runas(user):
|
|||
|
||||
def test_compound_runas_unpriv(user):
|
||||
cmd = "hostname && whoami"
|
||||
is_admin = win_functions.is_admin(user.username)
|
||||
user_info = win_user.info(user.username)
|
||||
result = win_runas.runas_unpriv(
|
||||
cmd=cmd,
|
||||
username=user.username,
|
||||
|
|
Loading…
Add table
Reference in a new issue