86 lines
4.0 KiB
PowerShell
86 lines
4.0 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$PythonPath
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$repository = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
|
$installerPath = Join-Path $PSScriptRoot 'install_windows_release_client.ps1'
|
|
$fixtureScript = Join-Path $PSScriptRoot 'test_windows_release_launcher.py'
|
|
$temporaryRoot = Join-Path ([IO.Path]::GetTempPath()) ('akyldash-bundle-mode-' + [guid]::NewGuid().ToString('N'))
|
|
[void][IO.Directory]::CreateDirectory($temporaryRoot)
|
|
$bundlePath = Join-Path $temporaryRoot 'fixture.zip'
|
|
|
|
try {
|
|
$fixtureOutput = & $PythonPath -E -s -S $fixtureScript --write-bundle-fixture $bundlePath
|
|
if ($LASTEXITCODE -ne 0) { throw 'The temporary packager fixture failed.' }
|
|
$fixture = ($fixtureOutput -join "`n") | ConvertFrom-Json
|
|
|
|
$tokens = $null
|
|
$parseErrors = $null
|
|
$installerAst = [System.Management.Automation.Language.Parser]::ParseFile(
|
|
$installerPath, [ref]$tokens, [ref]$parseErrors)
|
|
if ($parseErrors.Count -gt 0) { throw 'Installer PowerShell syntax is invalid.' }
|
|
$validatorAst = $installerAst.Find({
|
|
param($node)
|
|
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
|
|
$node.Name -ceq 'Assert-ReceiverBundleEntryMode'
|
|
}, $true)
|
|
if ($null -eq $validatorAst) { throw 'Installer bundle-mode validator was not found.' }
|
|
. ([scriptblock]::Create($validatorAst.Extent.Text))
|
|
|
|
Add-Type -AssemblyName System.IO.Compression
|
|
$stream = [IO.File]::OpenRead($bundlePath)
|
|
try {
|
|
$archive = [System.IO.Compression.ZipArchive]::new(
|
|
$stream, [System.IO.Compression.ZipArchiveMode]::Read, $true)
|
|
try {
|
|
foreach ($entry in $archive.Entries) {
|
|
Assert-ReceiverBundleEntryMode -Entry $entry
|
|
}
|
|
} finally { $archive.Dispose() }
|
|
} finally { $stream.Dispose() }
|
|
|
|
$alteredPath = Join-Path $temporaryRoot 'altered-mode.zip'
|
|
$sourceStream = [IO.File]::OpenRead($bundlePath)
|
|
$targetStream = [IO.File]::Create($alteredPath)
|
|
try {
|
|
$sourceArchive = [System.IO.Compression.ZipArchive]::new(
|
|
$sourceStream, [System.IO.Compression.ZipArchiveMode]::Read, $true)
|
|
$targetArchive = [System.IO.Compression.ZipArchive]::new(
|
|
$targetStream, [System.IO.Compression.ZipArchiveMode]::Create, $true)
|
|
try {
|
|
$changed = $false
|
|
foreach ($entry in $sourceArchive.Entries) {
|
|
$copy = $targetArchive.CreateEntry($entry.FullName, [System.IO.Compression.CompressionLevel]::NoCompression)
|
|
$copy.ExternalAttributes = $entry.ExternalAttributes
|
|
if (-not $changed) {
|
|
$copy.ExternalAttributes = [int]([long]0x81A0 -shl 16)
|
|
$changed = $true
|
|
}
|
|
$input = $entry.Open()
|
|
$output = $copy.Open()
|
|
try { $input.CopyTo($output) }
|
|
finally { $output.Dispose(); $input.Dispose() }
|
|
}
|
|
if (-not $changed) { throw 'Packager fixture had no entries to mutate.' }
|
|
} finally { $targetArchive.Dispose(); $sourceArchive.Dispose() }
|
|
} finally { $targetStream.Dispose(); $sourceStream.Dispose() }
|
|
|
|
$alteredStream = [IO.File]::OpenRead($alteredPath)
|
|
try {
|
|
$alteredArchive = [System.IO.Compression.ZipArchive]::new(
|
|
$alteredStream, [System.IO.Compression.ZipArchiveMode]::Read, $true)
|
|
try {
|
|
$rejected = $false
|
|
try { Assert-ReceiverBundleEntryMode -Entry $alteredArchive.Entries[0] }
|
|
catch { $rejected = $true }
|
|
if (-not $rejected) { throw 'Installer validator accepted an altered ZIP entry mode.' }
|
|
} finally { $alteredArchive.Dispose() }
|
|
} finally { $alteredStream.Dispose() }
|
|
|
|
Write-Output ("PASS: installer validator accepted the actual packager bundle for commit {0} (SHA-256 {1}) and rejected altered mode." -f $fixture.commit, $fixture.sha256)
|
|
} finally {
|
|
Remove-Item -LiteralPath $temporaryRoot -Recurse -Force
|
|
}
|