52 lines
5.0 KiB
PowerShell

[CmdletBinding()]
param([Parameter(Mandatory)][string]$PackagePath,[Parameter(Mandatory)][string]$ReportPath)
$ErrorActionPreference='Stop'
$inventory=Get-Content -Raw (Join-Path $PackagePath 'package.json') | ConvertFrom-Json
$release=Get-Content -Raw (Join-Path $PSScriptRoot 'Release.json') | ConvertFrom-Json
$checks=[Collections.Generic.List[string]]::new()
function Assert-Payload([bool]$condition,[string]$description){if(!$condition){throw "Payload qualification failed: $description"};$checks.Add($description)}
Assert-Payload ($inventory.version -eq $release.version -and $inventory.publisher -eq 'Nick Beckley') 'Payload version and release publisher match'
foreach($name in @('PlotDirector.WordAddIn.vsto','PlotDirector.WordAddIn.dll.manifest')){
[xml]$xml=Get-Content -Raw (Join-Path $PackagePath $name)
$identity=$xml.SelectSingleNode('/*/*[local-name()="assemblyIdentity"]')
Assert-Payload ($identity.version -eq $release.version -and $identity.processorArchitecture -eq 'msil') "$name identity is version12 AnyCPU"
foreach($node in $xml.SelectNodes('//*[local-name()="X509Certificate"]')){
$certificate=[Security.Cryptography.X509Certificates.X509Certificate2]::new([Convert]::FromBase64String($node.InnerText))
try{Assert-Payload ($certificate.Thumbprint -eq $inventory.certificateThumbprint) "$name embeds the existing developer certificate"}finally{$certificate.Dispose()}
}
foreach($dependency in $xml.SelectNodes('//*[local-name()="dependentAssembly" and @dependencyType="install" and @codebase] | //*[local-name()="file" and @name]')){
$relative=if($dependency.HasAttribute('codebase')){$dependency.GetAttribute('codebase')}else{$dependency.GetAttribute('name')}
$path=Join-Path $PackagePath ([uri]::UnescapeDataString($relative))
Assert-Payload ((Test-Path $path -PathType Leaf) -and (Get-Item $path).Length -eq [long]$dependency.GetAttribute('size')) "$name reference resolves with exact size: $relative"
$algorithm=$dependency.SelectSingleNode('.//*[local-name()="DigestMethod"]').GetAttribute('Algorithm')
$expected=$dependency.SelectSingleNode('.//*[local-name()="DigestValue"]').InnerText
Assert-Payload ($algorithm -eq 'http://www.w3.org/2000/09/xmldsig#sha256' -and [Convert]::ToBase64String([Security.Cryptography.SHA256]::HashData([IO.File]::ReadAllBytes($path))) -eq $expected) "$name SHA256 reference matches: $relative"
}
}
[xml]$deployment=Get-Content -Raw (Join-Path $PackagePath 'PlotDirector.WordAddIn.vsto')
Assert-Payload ($deployment.SelectSingleNode('/*/*[local-name()="description"]').GetAttribute('publisher','urn:schemas-microsoft-com:asm.v2') -eq 'Nick Beckley') 'Signed VSTO deployment publisher is Nick Beckley'
foreach($relative in @('PlotDirector.WordAddIn.dll','Agent\PlotDirector.Companion.Agent.exe','Agent\PlotDirector.Companion.Agent.dll')){
Assert-Payload ([Diagnostics.FileVersionInfo]::GetVersionInfo((Join-Path $PackagePath $relative)).FileVersion -eq $release.version) "Application file version is 1.0.0.12: $relative"
}
# These SDK class libraries deliberately retain their default stable assembly
# version. Their exact build bytes are pinned by package.json and the signed
# application manifest, rather than relabelling their ABI to the app version.
foreach($relative in @('PlotDirector.Companion.Client.dll','PlotDirector.Companion.Protocol.dll','Agent\PlotDirector.Companion.Protocol.dll')){
Assert-Payload ([Diagnostics.FileVersionInfo]::GetVersionInfo((Join-Path $PackagePath $relative)).FileVersion -eq '1.0.0.0') "Supporting library retains its declared stable version: $relative"
}
$agent=[IO.File]::ReadAllBytes((Join-Path $PackagePath 'Agent\PlotDirector.Companion.Agent.exe'))
$pe=[BitConverter]::ToInt32($agent,0x3c)
Assert-Payload ([BitConverter]::ToUInt16($agent,$pe+4) -eq 0x8664) 'Published tray apphost is native Windows x64'
Add-Type -Path (Join-Path $PSScriptRoot 'InstallerInventory.cs')
$sid=[Security.Principal.WindowsIdentity]::GetCurrent().User.Value
$fixture=[CompanionInstalledProduct]::new();$fixture.ProductCode=$release.baselineProductCode;$fixture.Context=2;$fixture.UserSid=$sid;$fixture.Version='1.0.10'
[CompanionInstallerInventory]::RequireCurrentUser(@($fixture),'1.0.12');$checks.Add('Native context guard accepts the existing current-user version10 upgrade')
foreach($test in @('machine','foreign-user','newer-version')){
$fixture.Context=2;$fixture.UserSid=$sid;$fixture.Version='1.0.10'
switch($test){'machine'{$fixture.Context=4};'foreign-user'{$fixture.UserSid='S-1-5-18'};'newer-version'{$fixture.Version='1.0.13'}}
$refused=$false;try{[CompanionInstallerInventory]::RequireCurrentUser(@($fixture),'1.0.12')}catch{$refused=$true}
Assert-Payload $refused "Native context guard refuses $test without mutation"
}
@{sourceCommit=$inventory.commit;version=$inventory.version;passed=$checks} | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $ReportPath -Encoding UTF8
Write-Output "PASS developer payload: $($checks.Count) assertions, including exact manifest digests and non-mutating installer context fixtures."