fix: UTF-8 BOM in RDP bundle zip for Russian Windows PowerShell (0.20.16)

This commit is contained in:
2026-06-20 19:54:12 +10:00
parent 6acbfe22de
commit 9484160045
5 changed files with 40 additions and 9 deletions
+22 -4
View File
@@ -3,7 +3,12 @@
from pathlib import Path
from unittest.mock import patch
from app.services.rdp_bundle_delivery import build_rdp_bundle_zip, get_rdp_bundle_zip, register_rdp_bundle_zip
from app.services.rdp_bundle_delivery import (
_UTF8_BOM,
build_rdp_bundle_zip,
get_rdp_bundle_zip,
register_rdp_bundle_zip,
)
from app.services.winrm_connect import (
RDP_BUNDLE_REQUIRED,
RDP_REMOTE_STAGING,
@@ -30,8 +35,8 @@ def test_download_bundle_uses_invoke_webrequest():
"https://sac.example/api/v1/agent/rdp-bundle/token",
)
assert "Invoke-WebRequest" in script
assert "Expand-Archive" in script
assert "WriteAllBytes" not in script
assert "ZipFile]::ExtractToDirectory" in script
assert "Expand-Archive" not in script
def test_deploy_from_staging_runs_local_bundle():
@@ -45,6 +50,19 @@ def test_custom_deploy_script_escapes_single_quotes():
assert "O''Brien" in script
def test_rdp_bundle_zip_adds_utf8_bom_for_ps1(tmp_path: Path):
repo = tmp_path / "repo"
repo.mkdir()
(repo / "Deploy-LoginMonitor.ps1").write_text("# test", encoding="utf-8")
zip_bytes = build_rdp_bundle_zip(repo, ("Deploy-LoginMonitor.ps1",))
import zipfile
import io
with zipfile.ZipFile(io.BytesIO(zip_bytes)) as archive:
data = archive.read("Deploy-LoginMonitor.ps1")
assert data.startswith(_UTF8_BOM)
def test_rdp_bundle_zip_roundtrip(tmp_path: Path):
repo = tmp_path / "repo"
repo.mkdir()
@@ -69,7 +87,7 @@ def test_run_winrm_rdp_monitor_update_downloads_bundle_from_sac(tmp_path: Path):
return WinRmCmdResult(ok=True, message="staging ok", target="pc", stdout="Staging ready")
if "Invoke-WebRequest" in script:
return WinRmCmdResult(ok=True, message="download ok", target="pc", stdout="Bundle extracted")
if "& $deploy" in script:
if "powershell.exe -NoProfile" in script or "& $deploy" in script:
return WinRmCmdResult(
ok=True,
message="WinRM OK (pc), exit 0",