test: fix and issue with the test-setup.ps1 script that was preventing it from being run from some version of powershell

This commit is contained in:
Ben Hillis 2025-12-05 08:26:04 -08:00
parent 1390e644fb
commit e5993ff879

View File

@ -71,23 +71,45 @@ if ($Package) {
try { try {
if ($AllowUnsigned) if ($AllowUnsigned)
{ {
# unfortunately -AllowUnsigned isn't supported on vb so we need to manually import the certificate and trust it. # Try to add with -AllowUnsigned first (supported in newer PowerShell)
(Get-AuthenticodeSignature $Package).SignerCertificate | Export-Certificate -FilePath private-wsl.cert | Out-Null try {
try Add-AppxPackage $Package -AllowUnsigned -ErrorAction Stop
{ $installed = $true
Import-Certificate -FilePath .\private-wsl.cert -CertStoreLocation Cert:\LocalMachine\Root | Out-Null
} }
finally catch {
{ # Fallback: manually import the certificate and trust it
Remove-Item -Path .\private-wsl.cert try {
$cert = (Get-AuthenticodeSignature -LiteralPath $Package).SignerCertificate
if ($cert) {
$certPath = Join-Path $env:TEMP "private-wsl-$([guid]::NewGuid()).cert"
$cert | Export-Certificate -FilePath $certPath | Out-Null
try {
Import-Certificate -FilePath $certPath -CertStoreLocation Cert:\LocalMachine\Root | Out-Null
}
finally {
Remove-Item -Path $certPath -ErrorAction SilentlyContinue
}
}
}
catch {
Write-Warning "Could not import certificate: $_"
}
$installed = $false
} }
} }
Add-AppxPackage $Package if (-not $installed) {
Add-AppxPackage $Package -ErrorAction Stop
}
} }
catch { catch {
Write-Host $_ Write-Host "Error installing package: $_"
Get-AppPackageLog -All # Only show recent relevant logs, not all historical logs
try {
Get-AppPackageLog -ActivityID * | Where-Object {$_.TimeCreated -gt (Get-Date).AddMinutes(-5)} | Select-Object -First 10
} catch {
Write-Host "Could not retrieve app package logs"
}
exit 1 exit 1
} }
} }