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 {
if ($AllowUnsigned)
{
# unfortunately -AllowUnsigned isn't supported on vb so we need to manually import the certificate and trust it.
(Get-AuthenticodeSignature $Package).SignerCertificate | Export-Certificate -FilePath private-wsl.cert | Out-Null
try
{
Import-Certificate -FilePath .\private-wsl.cert -CertStoreLocation Cert:\LocalMachine\Root | Out-Null
# Try to add with -AllowUnsigned first (supported in newer PowerShell)
try {
Add-AppxPackage $Package -AllowUnsigned -ErrorAction Stop
$installed = $true
}
finally
{
Remove-Item -Path .\private-wsl.cert
catch {
# Fallback: manually import the certificate and trust it
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 {
Write-Host $_
Get-AppPackageLog -All
Write-Host "Error installing package: $_"
# 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
}
}