修复Windows部署脚本兼容性
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-01 11:57:43 +08:00
1 parent 0a192851a8
commit 9f23c07b7b
5 files changed
+51 -5

No files matched your search

@@ -18,6 +18,9 @@ func TestWindowsDeploymentScriptsKeepAdminChannelManual(t *testing.T) {
"sc.exe",
"smail-admin.exe",
"Set-RestrictedAcl",
"sidtype",
"$PackageRoot = $null",
"$PackageRoot = Split-Path -Parent $PSScriptRoot",
"NT SERVICE\\Smail:(F)",
".backup-",
"$mainBackup",
@@ -28,6 +31,14 @@ func TestWindowsDeploymentScriptsKeepAdminChannelManual(t *testing.T) {
t.Fatalf("Windows installer is missing %q", required)
}
}
if !hasUTF8BOM(installer) {
t.Fatal("Windows installer must be encoded as UTF-8 with BOM for Windows PowerShell")
}
serviceSetup := strings.Index(content, `"sidtype", "Smail", "unrestricted"`)
aclSetup := strings.Index(content, "Set-RestrictedAcl -Root $resolvedInstallRoot")
if serviceSetup < 0 || aclSetup < 0 || serviceSetup > aclSetup {
t.Fatal("Windows installer must create the service SID before applying service ACLs")
}
for _, forbidden := range []string{
"create SmailAdmin",
"Start-Service -Name \"SmailAdmin\"",
@@ -39,6 +50,10 @@ func TestWindowsDeploymentScriptsKeepAdminChannelManual(t *testing.T) {
}
}
func hasUTF8BOM(data []byte) bool {
return len(data) >= 3 && data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF
}
func TestWindowsUninstallerPreservesData(t *testing.T) {
root := filepath.Clean(filepath.Join("..", "..", ".."))
uninstaller, err := os.ReadFile(filepath.Join(root, "deploy", "uninstall-windows.ps1"))
@@ -46,6 +61,9 @@ func TestWindowsUninstallerPreservesData(t *testing.T) {
t.Fatal(err)
}
content := string(uninstaller)
if !hasUTF8BOM(uninstaller) {
t.Fatal("Windows uninstaller must be encoded as UTF-8 with BOM for Windows PowerShell")
}
if strings.Contains(content, "Remove-Item -LiteralPath $resolvedInstallRoot -Recurse") {
t.Fatal("Windows uninstaller recursively removes the data root")
}