22 lines
2.0 KiB
PowerShell

# Portable tests for package integrity and fail-closed platform guards. No registry/build tools touched.
$ErrorActionPreference='Stop'
. (Join-Path $PSScriptRoot 'DeveloperPackage.ps1')
$fixture=Join-Path ([IO.Path]::GetTempPath()) ('pd-package-test-'+[guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path (Join-Path $fixture 'Agent') -Force|Out-Null
try{
foreach($name in @('PlotDirector.WordAddIn.dll','PlotDirector.Companion.Client.dll','PlotDirector.Companion.Protocol.dll','Agent/PlotDirector.Companion.Agent.exe')){Set-Content -LiteralPath (Join-Path $fixture $name) -Value 'synthetic fixture, not an executable'}
foreach($name in @('PlotDirector.WordAddIn.vsto','PlotDirector.WordAddIn.dll.manifest')){Set-Content -LiteralPath (Join-Path $fixture $name) -Value '<assembly><assemblyIdentity version="1.0.0.5"/><Signature/></assembly>'}
$files=@(Get-ChildItem $fixture -Recurse -File|ForEach-Object{@{path=$_.FullName.Substring($fixture.Length+1);sha256=(Get-FileHash $_.FullName -Algorithm SHA256).Hash}})
@{version='1.0.0.5';publisher='Nick Beckley';commit=('a'*40);files=$files}|ConvertTo-Json -Depth 5|Set-Content (Join-Path $fixture 'package.json')
$null=Test-DeveloperPackage $fixture
Set-Content (Join-Path $fixture 'PlotDirector.WordAddIn.dll') 'tampered'
$rejected=$false;try{$null=Test-DeveloperPackage $fixture}catch{$rejected=$true};if(!$rejected){throw 'Tampered package was accepted.'}
if($env:OS -ne 'Windows_NT'){
foreach($script in @('Update-WordCompanion.ps1','Install-WordCompanion.ps1')){
$rejected=$false;try{& (Join-Path $PSScriptRoot $script)}catch{$rejected=$_.Exception.Message -match 'Windows'}
if(!$rejected){throw "Platform guard failed: $script"}
}
}
Write-Output 'PASS portable package validation, tamper refusal and non-Windows fail-closed guards. Fixture signatures are placeholders; no Office trust/Windows installation validation claimed.'
}finally{Remove-Item -LiteralPath $fixture -Recurse -Force}