fix: WinRM RDP update PowerShell quoting via EncodedCommand (0.20.10)
Broken -Command quotes caused ParserError on remote hosts; run deploy script through base64-encoded PowerShell.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""WinRM command builder tests."""
|
||||
|
||||
import base64
|
||||
|
||||
from app.services.winrm_connect import _winrm_rdp_update_remote_cmd
|
||||
|
||||
|
||||
def test_rdp_update_default_uses_encoded_command_without_broken_quotes():
|
||||
cmd = _winrm_rdp_update_remote_cmd("")
|
||||
assert "-EncodedCommand" in cmd
|
||||
assert "-Command" not in cmd
|
||||
assert '"& {' not in cmd
|
||||
|
||||
encoded = cmd.rsplit(" ", 1)[-1]
|
||||
script = base64.b64decode(encoded).decode("utf-16-le")
|
||||
assert "Deploy-LoginMonitor.ps1" in script
|
||||
assert "Join-Path $env:ProgramData" in script
|
||||
|
||||
|
||||
def test_rdp_update_custom_script_uses_encoded_command():
|
||||
cmd = _winrm_rdp_update_remote_cmd(r"C:\ProgramData\LoginMonitor\Deploy-LoginMonitor.ps1")
|
||||
assert "-EncodedCommand" in cmd
|
||||
encoded = cmd.rsplit(" ", 1)[-1]
|
||||
script = base64.b64decode(encoded).decode("utf-16-le")
|
||||
assert r"C:\ProgramData\LoginMonitor\Deploy-LoginMonitor.ps1" in script
|
||||
assert "Test-Path -LiteralPath" in script
|
||||
|
||||
|
||||
def test_rdp_update_custom_script_escapes_single_quotes():
|
||||
cmd = _winrm_rdp_update_remote_cmd(r"C:\Users\O'Brien\Deploy-LoginMonitor.ps1")
|
||||
encoded = cmd.rsplit(" ", 1)[-1]
|
||||
script = base64.b64decode(encoded).decode("utf-16-le")
|
||||
assert "O''Brien" in script
|
||||
Reference in New Issue
Block a user