Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows use of inline powershell for cmd.script args #56197

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _run(cmd,
# The last item in the list [-1] is the current method.
# The third item[2] in each tuple is the name of that method.
if stack[-2][2] == 'script':
cmd = 'Powershell -NonInteractive -NoProfile -ExecutionPolicy Bypass -File ' + cmd
cmd = 'Powershell -NonInteractive -NoProfile -ExecutionPolicy Bypass {0}'.format(cmd.replace('"', '\\"'))
elif encoded_cmd:
cmd = 'Powershell -NonInteractive -EncodedCommand {0}'.format(cmd)
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/files/file/base/issue-56195/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[CmdLetBinding()]
Param(
[SecureString] $SecureString
)

$Credential = New-Object System.Net.NetworkCredential("DummyId", $SecureString)
$Credential.Password
11 changes: 11 additions & 0 deletions tests/integration/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,14 @@ def test_windows_env_handling(self):
out = self.run_function('cmd.run', ['set'], env={"abc": "123", "ABC": "456"}).splitlines()
self.assertIn('abc=123', out)
self.assertIn('ABC=456', out)

@skipIf(not salt.utils.platform.is_windows(), 'minion is not windows')
def test_windows_powershell_script_args(self):
'''
Ensure that powershell processes inline script in args
'''
val = 'i like cheese'
args = '-SecureString (ConvertTo-SecureString -String "{0}" -AsPlainText -Force) -ErrorAction Stop'.format(val)
script = 'salt://issue-56195/test.ps1'
ret = self.run_function('cmd.script', [script], args=args, shell='powershell')
self.assertEqual(ret['stdout'], val)