added a few fixes
This commit is contained in:
@@ -34,6 +34,95 @@ try {
|
||||
. ([scriptblock]::Create($definition.Extent.Text))
|
||||
}
|
||||
}
|
||||
# Exercise the real bounded retry loops without delaying offline tests.
|
||||
function Start-Sleep { param([int]$Seconds) $script:testSleeps += $Seconds }
|
||||
$script:testSleeps = @()
|
||||
& {
|
||||
$script:probeCalls=0; $script:testSleeps=@()
|
||||
$result = Wait-OfficeResult { $script:probeCalls++; if ($script:probeCalls -eq 3) { [pscustomobject]@{Version='ready'} } } 'delayed fixture registration'
|
||||
Assert-OfficeTest ($result.Version -eq 'ready' -and $script:probeCalls -eq 3 -and $script:testSleeps.Count -eq 2) 'Delayed registration must return the verified value without leaking log text.'
|
||||
$script:probeCalls=0; $script:testSleeps=@()
|
||||
$result = Wait-OfficeResult { $script:probeCalls++; $false } 'missing fixture registration'
|
||||
Assert-OfficeTest ($null -eq $result -and $script:probeCalls -eq (Get-OfficeDeploymentDefinitions).RegistrationCheckAttempts -and $script:testSleeps.Count -eq ($script:probeCalls - 1)) 'Registration waits must stop at the configured bound.'
|
||||
$script:probeCalls=0
|
||||
Assert-OfficeThrows { Wait-OfficeResult { $script:probeCalls++; throw 'Registry access denied' } 'unreadable fixture' } 'Registry access denied'
|
||||
Assert-OfficeTest ($script:probeCalls -eq 1) 'Failed inventory reads must not be treated as absent installations.'
|
||||
}
|
||||
& {
|
||||
function Start-Process {
|
||||
param($FilePath,$ArgumentList,$WorkingDirectory,[switch]$Wait,[switch]$PassThru,$WindowStyle,$RedirectStandardOutput,$RedirectStandardError)
|
||||
$script:processCalls++; $script:processLogs += $RedirectStandardOutput
|
||||
if ($script:processExit -eq 1618 -and $script:processRecovers -and $script:processCalls -eq 3) { return [pscustomobject]@{ExitCode=0} }
|
||||
[pscustomobject]@{ExitCode=$script:processExit}
|
||||
}
|
||||
foreach ($mode in @('recovers','busy','fatal','reboot','not-msi','null-code')) {
|
||||
$script:processCalls=0; $script:processLogs=@(); $script:testSleeps=@(); $script:processRecovers=$mode -eq 'recovers'
|
||||
$script:processExit = switch ($mode) { 'fatal' {1603}; 'reboot' {3010}; 'null-code' {$null}; default {1618} }
|
||||
$executable = if ($mode -eq 'not-msi') { 'bootstrapper.exe' } else { 'msiexec.exe' }
|
||||
$file = Join-Path $testRoot $executable
|
||||
if ($mode -eq 'null-code') { Assert-OfficeThrows { Invoke-OfficeProcess $file '/x fixture' (Join-Path $testRoot 'msi') } 'No exit code'; continue }
|
||||
$code = Invoke-OfficeProcess $file '/x fixture' (Join-Path $testRoot 'msi')
|
||||
$expectedCalls = if ($mode -eq 'recovers') {3} elseif ($mode -eq 'busy') {(Get-OfficeDeploymentDefinitions).MsiBusyAttempts} else {1}
|
||||
$expectedCode = if ($mode -eq 'recovers') {0} else {$script:processExit}
|
||||
Assert-OfficeTest ($code -eq $expectedCode -and $script:processCalls -eq $expectedCalls -and $script:testSleeps.Count -eq ($expectedCalls - 1)) "Incorrect retry behavior for $mode."
|
||||
Assert-OfficeTest (@($script:processLogs | Select-Object -Unique).Count -eq $expectedCalls) 'MSI retry output logs must not overwrite earlier attempts.'
|
||||
}
|
||||
}
|
||||
& {
|
||||
function Invoke-WebRequest {
|
||||
[CmdletBinding()]
|
||||
param([switch]$UseBasicParsing,$Uri,$OutFile,$TimeoutSec)
|
||||
$script:downloadCalls++
|
||||
if (!$script:downloadRecovers -or $script:downloadCalls -eq 1) { throw 'Temporary network failure' }
|
||||
[IO.File]::WriteAllText($OutFile, 'downloaded fixture')
|
||||
}
|
||||
$script:downloadCalls=0; $script:downloadRecovers=$true
|
||||
Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null
|
||||
Assert-OfficeTest ($script:downloadCalls -eq 2 -and (Get-Content -LiteralPath (Join-Path $testRoot 'download') -Raw) -eq 'downloaded fixture') 'A transient download error should recover.'
|
||||
$script:downloadCalls=0; $script:downloadRecovers=$false
|
||||
Assert-OfficeThrows { Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null } 'Temporary network failure'
|
||||
Assert-OfficeTest ($script:downloadCalls -eq (Get-OfficeDeploymentDefinitions).DownloadAttempts) 'Persistent download failure must remain bounded.'
|
||||
}
|
||||
& {
|
||||
function Remove-AppxPackage {
|
||||
param($Package,[switch]$AllUsers)
|
||||
$script:appxCalls++
|
||||
if ($script:appxMode -eq 'already-gone') { $script:appxPresent=$false; throw 'Package already removed by another operation' }
|
||||
if ($script:appxMode -eq 'failure' -or ($script:appxMode -eq 'recovers' -and $script:appxCalls -eq 1)) { throw 'Transient package in use' }
|
||||
$script:appxPresent=$false
|
||||
}
|
||||
function Remove-AppxProvisionedPackage { param($PackageName,[switch]$Online,[switch]$AllUsers) Remove-AppxPackage -Package $PackageName -AllUsers }
|
||||
function Get-AppxPackage {
|
||||
param([switch]$AllUsers)
|
||||
if ($script:appxMode -eq 'query-failure') { throw 'Appx inventory access denied' }
|
||||
if ($script:appxPresent) { [pscustomobject]@{PackageFullName='fixture'; PackageName='fixture'} }
|
||||
}
|
||||
function Get-AppxProvisionedPackage { param([switch]$Online) Get-AppxPackage -AllUsers }
|
||||
foreach ($provisioned in @($false,$true)) {
|
||||
foreach ($script:appxMode in @('success','already-gone','recovers','failure','query-failure')) {
|
||||
$script:appxPresent=$true; $script:appxCalls=0
|
||||
if ($script:appxMode -eq 'failure') {
|
||||
Assert-OfficeThrows { Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned } 'Appx package remains'
|
||||
Assert-OfficeTest ($script:appxCalls -eq (Get-OfficeDeploymentDefinitions).AppxRemovalAttempts) 'Persistent Appx removal failure must be bounded.'
|
||||
} elseif ($script:appxMode -eq 'query-failure') {
|
||||
Assert-OfficeThrows { Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned } 'Appx inventory access denied'
|
||||
Assert-OfficeTest ($script:appxCalls -eq 1) 'Appx read errors must propagate instead of passing verification.'
|
||||
} else {
|
||||
$output = @(Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned)
|
||||
$expectedCalls = if ($script:appxMode -eq 'recovers') {2} else {1}
|
||||
Assert-OfficeTest (!$script:appxPresent -and $script:appxCalls -eq $expectedCalls -and $output.Count -eq 0) "Appx removal did not recover cleanly: $script:appxMode, provisioned=$provisioned."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
& {
|
||||
function Get-OfficeRunningApps { [pscustomobject]@{Id=123; HasExited=$script:appHasExited} }
|
||||
function Stop-Process { throw 'Process is gone or access was denied.' }
|
||||
$script:appHasExited=$true
|
||||
Stop-OfficeDeploymentApps ([pscustomobject]@{OfficeAppShutdown='Force'})
|
||||
$script:appHasExited=$false
|
||||
Assert-OfficeThrows { Stop-OfficeDeploymentApps ([pscustomobject]@{OfficeAppShutdown='Force'}) } 'Process is gone or access was denied'
|
||||
}
|
||||
foreach ($value in @($null, '', ' ', 'true', ' TRUE ', '$true', '1', 'yes')) {
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; ValidateBeforeChanges=$value}
|
||||
Assert-OfficeTest ($options.ValidateBeforeChanges -is [bool] -and $options.ValidateBeforeChanges) "Validation must be on for '$value'."
|
||||
@@ -90,12 +179,25 @@ try {
|
||||
$values = @{ OfficeSubscription='Microsoft 365 E3' }; $values[$name]='invalid'
|
||||
Assert-OfficeThrows { Get-OfficeDeploymentOptions $values } "Invalid $name"
|
||||
}
|
||||
foreach ($value in @($null, '', ' ', 'true', '$true', $true)) {
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; DeferReboot=$value}
|
||||
Assert-OfficeTest ($options.DeferReboot -is [bool] -and $options.DeferReboot) 'Missing/blank or true restart input must produce Boolean true.'
|
||||
}
|
||||
foreach ($value in @('false', '$false', $false, '0', ' No ')) {
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; DeferReboot=$value}
|
||||
Assert-OfficeTest ($options.DeferReboot -is [bool] -and !$options.DeferReboot) 'False restart text must be parsed, not cast to a truthy string.'
|
||||
}
|
||||
Assert-OfficeTest ((Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'}).DeferReboot) 'Omitted restart input must default to true.'
|
||||
foreach ($value in @('maybe', 'Defer', 'StopBeforeInstall')) {
|
||||
Assert-OfficeThrows { Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; DeferReboot=$value} } 'Invalid \$DeferReboot'
|
||||
}
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeArchitecture='32'; COMPANY='A & B <Company> "quoted"'; OfficeActivation='SharedComputer'; OfficeAppShutdown='Force'}
|
||||
$xml = New-OfficeConfiguration $options 'C:\Office & Tools' '16.0.12345.67890'
|
||||
$roundTrip = [xml]$xml.OuterXml
|
||||
Assert-OfficeTest ($roundTrip.Configuration.AppSettings.Setup.Value -eq $options.Company) 'Company XML escaping failed.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.SourcePath -eq 'C:\Office & Tools') 'Source XML escaping failed.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Display.Level -eq 'None') 'Install must be silent.'
|
||||
Assert-OfficeTest ($null -ne $roundTrip.SelectSingleNode('/Configuration/RemoveMSI') -and $null -ne $roundTrip.SelectSingleNode('/Configuration/Add')) 'Legacy MSI removal must run with the replacement installation.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.OfficeClientEdition -eq '32') '32-bit selection ignored.'
|
||||
Assert-OfficeTest ($roundTrip.SelectSingleNode('//Property[@Name="SharedComputerLicensing"]').Value -eq '1') 'Shared activation lost.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.Version -eq '16.0.12345.67890') 'Downloaded version must be pinned.'
|
||||
@@ -106,29 +208,30 @@ try {
|
||||
Assert-OfficeThrows { Assert-OfficeCompanionPlatform -Build 20348 -ProductType 3 -Revision 2401 } 'Server 2022'
|
||||
Assert-OfficeThrows { Assert-OfficeCompanionPlatform -Build 19044 -ProductType 1 -EditionId EnterpriseS -InstallTeams $true } 'LTSC'
|
||||
Assert-OfficeCompanionPlatform -Build 19044 -ProductType 1 -EditionId EnterpriseS -InstallTeams $false
|
||||
# Exercise actual ZIP extraction in media staging under the Tools.ps1 command scope.
|
||||
foreach ($shutdown in @('Abort','Force')) {
|
||||
$removal = New-OfficeRemovalConfiguration ([pscustomobject]@{OfficeAppShutdown=$shutdown})
|
||||
Assert-OfficeTest ($removal.Configuration.Remove.All -eq 'TRUE' -and $removal.Configuration.Display.Level -eq 'None' -and $removal.Configuration.Display.AcceptEULA -eq 'TRUE') 'ODT removal must remove all Click-to-Run products without UI.'
|
||||
Assert-OfficeTest ($removal.SelectSingleNode('//Property[@Name="FORCEAPPSHUTDOWN"]').Value -eq $(if ($shutdown -eq 'Force') {'TRUE'} else {'FALSE'})) 'Silent removal must honor the app shutdown selection.'
|
||||
Assert-OfficeTest ($null -eq $removal.SelectSingleNode('/Configuration/Add') -and $null -eq $removal.SelectSingleNode('/Configuration/RemoveMSI')) 'The separate removal pass must not install Office or depend on standalone RemoveMSI.'
|
||||
}
|
||||
# Exercise media staging under the Tools.ps1 command scope, including literal paths.
|
||||
# Network requests, Microsoft signatures, and executable launches are mocked; files are inert.
|
||||
& {
|
||||
$archiveCommand = Get-Command Expand-Archive
|
||||
Assert-OfficeTest ($archiveCommand.CommandType -eq 'Function' -and !$archiveCommand.Parameters.ContainsKey('LiteralPath')) 'The real Tools archive override must be present for this regression.'
|
||||
$mediaWorkspace = Join-Path $testRoot 'media [literal]'
|
||||
$null = [IO.Directory]::CreateDirectory($mediaWorkspace)
|
||||
$zipSource = Join-Path $testRoot 'zip-source'
|
||||
$null = [IO.Directory]::CreateDirectory($zipSource)
|
||||
[IO.File]::WriteAllText((Join-Path $zipSource 'GetHelpCmd.exe'), 'Inert scrubber fixture; never executed.')
|
||||
$mediaFixtureZip = Join-Path $testRoot 'gethelp-fixture.zip'
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
[IO.Compression.ZipFile]::CreateFromDirectory($zipSource, $mediaFixtureZip)
|
||||
$script:mediaSignatures = @(); $script:mediaProcesses = @()
|
||||
$script:mediaSignatures = @(); $script:mediaProcesses = @(); $script:mediaDownloadCalls = 0
|
||||
function Invoke-WebRequest {
|
||||
[CmdletBinding()]
|
||||
param([switch]$UseBasicParsing, [string]$Uri, [int]$TimeoutSec)
|
||||
[pscustomobject]@{Content='https://download.microsoft.com/test/officedeploymenttool_test.exe'}
|
||||
}
|
||||
function Save-OfficeDownload {
|
||||
param([string]$Uri, [string]$Path)
|
||||
if ([IO.Path]::GetFileName($Path) -eq 'GetHelp.zip') {
|
||||
[IO.File]::Copy($mediaFixtureZip, $Path)
|
||||
param([string]$Uri, [string]$Path, [int]$TimeoutSeconds)
|
||||
if ([IO.Path]::GetFileName($Path) -eq 'odt-download-page.html') {
|
||||
Assert-OfficeTest ($TimeoutSeconds -eq (Get-OfficeDeploymentDefinitions).OdtPageTimeoutSeconds) 'ODT page must use the retried downloader with its configured timeout.'
|
||||
[IO.File]::WriteAllText($Path, 'https://download.microsoft.com/test/officedeploymenttool_test.exe')
|
||||
} elseif ([IO.Path]::GetFileName($Path) -eq 'Office-UserCleanup.ps1') {
|
||||
[IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion)
|
||||
} else {
|
||||
@@ -146,6 +249,8 @@ try {
|
||||
if ([IO.Path]::GetFileName($FilePath) -eq 'odt.exe' -and $Arguments -like '/quiet /extract:*') {
|
||||
[IO.File]::WriteAllText((Join-Path $mediaWorkspace 'ODT\setup.exe'), 'Inert ODT fixture; never executed.')
|
||||
} elseif ([IO.Path]::GetFileName($FilePath) -eq 'setup.exe' -and $Arguments -like '/download *') {
|
||||
$script:mediaDownloadCalls++
|
||||
if ($script:mediaDownloadCalls -eq 1) { return 12029 }
|
||||
$payload = Join-Path $mediaWorkspace 'ODT\Office\Data\16.0.12345.67890'
|
||||
$null = [IO.Directory]::CreateDirectory($payload)
|
||||
foreach ($name in @('stream.x64.x-none.dat', 'stream.x64.en-us.dat')) { [IO.File]::WriteAllText((Join-Path $payload $name), 'Inert Office payload.') }
|
||||
@@ -154,11 +259,13 @@ try {
|
||||
}
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'}
|
||||
$media = Initialize-OfficeMedia $options $mediaWorkspace
|
||||
Assert-OfficeTest ((Get-Content -LiteralPath $media.Scrubber -Raw) -eq 'Inert scrubber fixture; never executed.') 'Get Help ZIP did not extract correctly with Tools loaded and a literal path.'
|
||||
Assert-OfficeTest ($media.Scrubber -in $script:mediaSignatures -and $media.Setup -in $script:mediaSignatures) 'Extracted Get Help and ODT must still pass signature checks.'
|
||||
Assert-OfficeTest ($media.Setup -in $script:mediaSignatures) 'Extracted ODT must still pass signature checks.'
|
||||
Assert-OfficeTest ($media.Version -eq '16.0.12345.67890' -and $media.Companions.Count -eq 3 -and !$media.Companions.ContainsKey('Teams')) 'Media staging lost its build or no-Teams selection.'
|
||||
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Staged configuration must pin the downloaded build.'
|
||||
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe') 'Staging attempted to run a scrubber or companion installer.'
|
||||
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe,setup.exe') 'Staging must only extract ODT and download Office, with no removal or installation.'
|
||||
$removal = [xml](Get-Content -LiteralPath $media.RemovalConfig -Raw)
|
||||
Assert-OfficeTest ($removal.Configuration.Remove.All -eq 'TRUE' -and $removal.Configuration.Display.Level -eq 'None') 'Staging must save the silent removal configuration.'
|
||||
Assert-OfficeTest (!$media.Scrubber -and !($script:mediaSignatures -match 'GetHelp|SaRA')) 'Unattended deployments must not stage an interactive scrubber.'
|
||||
}
|
||||
& {
|
||||
$script:staged = @(); $script:verified = @()
|
||||
@@ -178,10 +285,16 @@ try {
|
||||
Assert-OfficeThrows { Initialize-OfficeCompanionMedia $testRoot } 'Untrusted companion'
|
||||
}
|
||||
& {
|
||||
function Get-OfficeMachineWebViewVersion { if ($script:webViewPresent) { '140.0.0.1' } }
|
||||
function Get-OfficeMachineWebViewVersion {
|
||||
if ($script:webViewPresent) {
|
||||
if ($script:appMode -eq 'delayed-success') { $script:webViewChecks++; if ($script:webViewChecks -lt 3) { return } }
|
||||
'140.0.0.1'
|
||||
}
|
||||
}
|
||||
function Invoke-OfficeProcess {
|
||||
param($FilePath,$Arguments,$LogPrefix)
|
||||
$script:appCalls += "$FilePath $Arguments"
|
||||
$script:lastInstalledApp=$FilePath
|
||||
if ($script:appMode -eq "fail-$FilePath") { return 42 }
|
||||
if ($FilePath -eq 'WebView2') { $script:webViewPresent = $true }
|
||||
if ($script:appMode -eq 'reboot' -and $FilePath -eq 'OneDrive') { return 3010 }
|
||||
@@ -189,16 +302,21 @@ try {
|
||||
}
|
||||
function Get-AppxProvisionedPackage {
|
||||
param([switch]$Online,$ErrorAction)
|
||||
if ($script:appMode -eq 'delayed-success') { $script:packageChecks[$script:lastInstalledApp]++; if ($script:packageChecks[$script:lastInstalledApp] -lt 3) { return } }
|
||||
if ($script:appMode -ne 'missing-Teams') { [pscustomobject]@{DisplayName='MSTeams'; PackageName='MSTeams_1.0.0.0_neutral_~_8wekyb3d8bbwe'; Version='1.0.0.0'} }
|
||||
if ($script:appMode -ne 'missing-NewOutlook') { [pscustomobject]@{DisplayName='Microsoft.OutlookForWindows'; PackageName='Microsoft.OutlookForWindows_1.0.0.0_neutral_~_8wekyb3d8bbwe'; Version='1.0.0.0'} }
|
||||
}
|
||||
function Get-OfficeMachineOneDrive { if ($script:appMode -ne 'missing-OneDrive') { [pscustomobject]@{Path='inert.exe'; Version='26.1.2.3'} } }
|
||||
function Get-OfficeMachineOneDrive {
|
||||
if ($script:appMode -eq 'delayed-success') { $script:oneDriveChecks++; if ($script:oneDriveChecks -lt 3) { return } }
|
||||
if ($script:appMode -ne 'missing-OneDrive') { [pscustomobject]@{Path='inert.exe'; Version='26.1.2.3'} }
|
||||
}
|
||||
function Assert-OfficeMicrosoftSignature { }
|
||||
$media = @{WebView2='WebView2'; OneDrive='OneDrive'; Teams='Teams'; NewOutlook='NewOutlook'}
|
||||
foreach ($script:appMode in @('success','reboot','fail-WebView2','fail-OneDrive','fail-Teams','fail-NewOutlook','missing-OneDrive','missing-Teams','missing-NewOutlook')) {
|
||||
foreach ($script:appMode in @('success','delayed-success','reboot','fail-WebView2','fail-OneDrive','fail-Teams','fail-NewOutlook','missing-OneDrive','missing-Teams','missing-NewOutlook')) {
|
||||
$script:webViewPresent = $false; $script:appCalls = @(); $failure = $null; $result = $null
|
||||
$script:webViewChecks=0; $script:oneDriveChecks=0; $script:packageChecks=@{}
|
||||
try { $result = Install-OfficeCompanionApps $media $testRoot -InstallTeams $true } catch { $failure = $_ }
|
||||
if ($script:appMode -in @('success','reboot')) {
|
||||
if ($script:appMode -in @('success','delayed-success','reboot')) {
|
||||
$expectedCode = if ($script:appMode -eq 'reboot') { 3010 } else { 0 }
|
||||
Assert-OfficeTest ($null -eq $failure -and $result.ExitCode -eq $expectedCode) "Unexpected companion result for $script:appMode : $failure"
|
||||
Assert-OfficeTest ($result.Versions.OneDrive -eq '26.1.2.3' -and $result.Versions.Teams -eq '1.0.0.0' -and $result.Versions.NewOutlook -eq '1.0.0.0') 'Companion verification receipt is incomplete.'
|
||||
@@ -258,12 +376,97 @@ try {
|
||||
Assert-OfficeThrows { Get-OfficeOdtDownloadUrl '<html>blocked</html>' } 'unique current ODT'
|
||||
Assert-OfficeThrows { Get-OfficeOdtDownloadUrl ($url + ' ' + $url.Replace('20326','20327')) } 'unique current ODT'
|
||||
Assert-OfficeThrows { Get-OfficeOdtDownloadUrl 'https://download.microsoft.com.evil.test/officedeploymenttool_1.exe' } 'unique current ODT'
|
||||
Assert-OfficeScrubResult 0 '00: Successfully completed this scenario.' @()
|
||||
Assert-OfficeScrubResult 0 '66: No matching version.' @()
|
||||
Assert-OfficeThrows { Assert-OfficeScrubResult 0 '09: Failure to remove Office.' @() } 'removal failed'
|
||||
Assert-OfficeThrows { Assert-OfficeScrubResult 0 'Starting scenario...' @() } 'no recognizable'
|
||||
Assert-OfficeThrows { Assert-OfficeScrubResult 1 '00: Success.' @() } 'removal failed'
|
||||
Assert-OfficeThrows { Assert-OfficeScrubResult 0 '68: No product.' @([pscustomobject]@{DisplayName='Office 2016'}) } 'Office remains'
|
||||
& {
|
||||
function Get-OfficeUninstallEntries {
|
||||
[pscustomobject]@{DisplayName='Microsoft Office Professional Plus 2016'; WindowsInstaller=1}
|
||||
[pscustomobject]@{DisplayName='Microsoft Office Home and Business 2021 - en-us'}
|
||||
[pscustomobject]@{DisplayName='Microsoft Teams Meeting Add-in for Microsoft Office'; WindowsInstaller=1}
|
||||
}
|
||||
function Test-Path { param($LiteralPath,$ErrorAction) $script:c2rPresent }
|
||||
function Get-ItemProperty { throw 'Click-to-Run inventory access denied' }
|
||||
$script:c2rPresent=$false
|
||||
$inventory = @(Get-OfficeSuiteInventory)
|
||||
Assert-OfficeTest ($inventory.Count -eq 2 -and $inventory[0].WindowsInstaller -eq 1) 'Office inventory must preserve the MSI marker and exclude the Teams add-in.'
|
||||
$script:c2rPresent=$true
|
||||
Assert-OfficeThrows { Get-OfficeSuiteInventory } 'Click-to-Run inventory access denied'
|
||||
}
|
||||
& {
|
||||
function Get-OfficeSuiteInventory {
|
||||
$script:removalChecks++
|
||||
if ($script:removalMode -eq 'empty') { return }
|
||||
[pscustomobject]@{DisplayName='Microsoft Office Professional Plus 2016'; WindowsInstaller=1}
|
||||
if ($script:removalMode -eq 'msi-only') { return }
|
||||
if ($script:removalStarted -and $script:removalMode -eq 'read-error') { throw 'Office inventory is unreadable' }
|
||||
if (!$script:removalStarted -or $script:removalMode -eq 'remaining' -or ($script:removalMode -eq 'delayed' -and $script:removalChecks -le 3)) {
|
||||
[pscustomobject]@{DisplayName='Microsoft Office Home and Business 2021 - en-us'}
|
||||
}
|
||||
}
|
||||
function Invoke-OfficeProcess {
|
||||
param($FilePath,$Arguments,$LogPrefix)
|
||||
$script:removalCalls++; $script:removalStarted=$true
|
||||
Assert-OfficeTest ($FilePath -eq $media.Setup -and $Arguments -eq ('/configure "' + $media.RemovalConfig + '"')) 'Removal must run only ODT with the staged removal configuration.'
|
||||
Assert-OfficeTest ((Split-Path -Leaf $LogPrefix) -eq 'office-remove') 'Removal must retain diagnostic process logs.'
|
||||
$script:removalCode
|
||||
}
|
||||
$removalPath = Join-Path $testRoot 'remove [literal].xml'
|
||||
(New-OfficeRemovalConfiguration ([pscustomobject]@{OfficeAppShutdown='Force'})).Save($removalPath)
|
||||
$media = [pscustomobject]@{Setup='inert-setup.exe'; RemovalConfig=$removalPath}
|
||||
foreach ($script:removalMode in @('empty','msi-only','mixed','delayed','remaining','read-error','fatal','reboot')) {
|
||||
$script:removalChecks=0; $script:removalCalls=0; $script:removalStarted=$false
|
||||
$script:removalCode = switch ($script:removalMode) { 'fatal' {1603}; 'reboot' {3010}; default {0} }
|
||||
if ($script:removalMode -eq 'remaining') {
|
||||
Assert-OfficeThrows { Remove-OfficeSuite $media $testRoot } 'Office remains.*Office Home and Business 2021.*manual scrub'
|
||||
Assert-OfficeTest ($script:removalChecks -eq ((Get-OfficeDeploymentDefinitions).RegistrationCheckAttempts + 2)) 'Remaining Click-to-Run products must be checked for the bounded registration interval.'
|
||||
} elseif ($script:removalMode -eq 'read-error') {
|
||||
Assert-OfficeThrows { Remove-OfficeSuite $media $testRoot } 'Office inventory is unreadable'
|
||||
} elseif ($script:removalMode -eq 'fatal') {
|
||||
Assert-OfficeThrows { Remove-OfficeSuite $media $testRoot } 'ODT Office removal failed \(exit 1603\).*No interactive scrubber was launched.*manual scrub'
|
||||
} else {
|
||||
$result = @(Remove-OfficeSuite $media $testRoot)
|
||||
$expected = if ($script:removalMode -eq 'reboot') {3010} else {0}
|
||||
Assert-OfficeTest ($result.Count -eq 1 -and $result[0] -eq $expected) 'Removal must return just its exit code; MSI products are deferred to installation.'
|
||||
if ($script:removalMode -eq 'delayed') { Assert-OfficeTest ($script:removalChecks -eq 4) 'Removal must tolerate registry propagation delays.' }
|
||||
if ($script:removalMode -eq 'reboot') { Assert-OfficeTest ($script:removalChecks -eq 1) 'A required restart must be surfaced before demanding registration cleanup.' }
|
||||
}
|
||||
$expectedCalls = if ($script:removalMode -in @('empty','msi-only')) {0} else {1}
|
||||
Assert-OfficeTest ($script:removalCalls -eq $expectedCalls) 'Do not remove absent Click-to-Run Office, rerun failed removal, or launch a fallback scrubber.'
|
||||
}
|
||||
}
|
||||
& {
|
||||
function Get-OfficeSuiteInventory {
|
||||
$script:restartChecks++
|
||||
if ($script:restartMode -eq 'read-error') { throw 'Removal inventory access denied' }
|
||||
if ($script:restartMode -eq 'remaining' -or ($script:restartMode -eq 'delayed' -and $script:restartChecks -lt 3)) {
|
||||
[pscustomobject]@{DisplayName='Old Office fixture'}
|
||||
}
|
||||
# MSI Office is intentionally left for RemoveMSI during replacement installation.
|
||||
if ($script:restartMode -eq 'msi-only') { [pscustomobject]@{DisplayName='MSI Office fixture'; WindowsInstaller=1} }
|
||||
}
|
||||
function Get-OfficeMachineCompanionEntries { Get-OfficeSuiteInventory }
|
||||
foreach ($stage in @('Office','Companions')) {
|
||||
foreach ($behavior in @($true,$false)) {
|
||||
foreach ($script:restartMode in @('gone','remaining','delayed','read-error')) {
|
||||
$script:restartChecks=0
|
||||
$options = [pscustomobject]@{DeferReboot=$behavior}
|
||||
if ($behavior -and $script:restartMode -eq 'read-error') {
|
||||
Assert-OfficeThrows { Test-OfficeCanDeferRestart $options $stage } 'Removal inventory access denied'
|
||||
} else {
|
||||
$result = @(Test-OfficeCanDeferRestart $options $stage)
|
||||
$expected = $behavior -and $script:restartMode -in @('gone','delayed')
|
||||
Assert-OfficeTest ($result.Count -eq 1 -and $result[0] -eq $expected) "Incorrect restart decision: $stage / $behavior / $script:restartMode."
|
||||
if (!$behavior) { Assert-OfficeTest ($script:restartChecks -eq 0) 'DeferReboot=false must return immediately after a restart request.' }
|
||||
elseif ($script:restartMode -eq 'remaining') { Assert-OfficeTest ($script:restartChecks -eq ((Get-OfficeDeploymentDefinitions).RegistrationCheckAttempts + 1)) 'Deferral must wait for removal registration, with a bounded deadline.' }
|
||||
elseif ($script:restartMode -eq 'delayed') { Assert-OfficeTest ($script:restartChecks -eq 3) 'Deferral must tolerate delayed removal registration.' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$script:restartMode='msi-only'; $script:restartChecks=0
|
||||
Assert-OfficeTest (Test-OfficeCanDeferRestart ([pscustomobject]@{DeferReboot=$true}) 'Office') 'Deferred MSI removal must not block Click-to-Run restart deferral.'
|
||||
foreach ($value in @($null, 'false', 'true', 'invalid')) {
|
||||
Assert-OfficeThrows { Test-OfficeCanDeferRestart ([pscustomobject]@{DeferReboot=$value}) 'Office' } 'must be a validated Boolean'
|
||||
}
|
||||
}
|
||||
Assert-OfficeTest (Test-OfficeCredentialTarget 'MicrosoftOffice16_Data:ADAL:example') 'Office ADAL credential should be cleared.'
|
||||
foreach ($target in @('WindowsLive:target', 'MicrosoftAccount:user', 'OneDrive:user', 'AzureAD:user', 'TERMSRV/server', 'MicrosoftOffice16_DataEvil')) { Assert-OfficeTest (!(Test-OfficeCredentialTarget $target)) "Unrelated credential matched: $target" }
|
||||
Assert-OfficeTest ('Microsoft.AAD.BrokerPlugin' -notin (Get-OfficeAppxNames)) 'Must preserve Windows work-account broker.'
|
||||
@@ -275,6 +478,96 @@ try {
|
||||
Assert-OfficeThrows { Get-OfficeOneDriveCommand '"C:\Users\someone\OneDriveSetup.exe" /uninstall' @('C:\Program Files\Microsoft OneDrive') } 'allowlist'
|
||||
Assert-OfficeThrows { Get-OfficeOneDriveCommand '"C:\Program Files\Microsoft OneDrive\OneDriveSetup.exe" /uninstall & calc.exe' @('C:\Program Files\Microsoft OneDrive') } 'allowlist'
|
||||
|
||||
# Compile and exercise the real read-only MSI queries for a nonexistent product.
|
||||
$absentProduct = '{' + [guid]::NewGuid().ToString() + '}'
|
||||
Assert-OfficeTest (!(Test-OfficeMachineMsiProduct $absentProduct)) 'An unknown product must not be classified as a machine MSI.'
|
||||
Assert-OfficeTest (!(Test-OfficeUserMsiProduct $absentProduct)) 'An unknown product must not be classified as a current-user MSI.'
|
||||
Assert-OfficeThrows { Test-OfficeMachineMsiProduct 'not-a-guid' } 'ProductCode'
|
||||
Assert-OfficeThrows { Test-OfficeUserMsiProduct 'not-a-guid' } 'ProductCode'
|
||||
Assert-OfficeTest ($helperAst.Extent.Text.Contains((Get-OfficeDeploymentDefinitions).HelperVersion)) 'The staged helper version contract must match the checked-in helper.'
|
||||
|
||||
# HKLM can contain a per-user Teams add-in registration. Never run its MSI as SYSTEM.
|
||||
& {
|
||||
$addin = [pscustomobject]@{DisplayName='Microsoft Teams Meeting Add-in for Microsoft Office'; DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'; PSPath='Registry::HKEY_LOCAL_MACHINE\Software\Fixture\Addin'}
|
||||
$script:companionEntries=@($addin); $script:machineRegistered=$false; $script:removalCalls=@()
|
||||
function Get-OfficeUninstallEntries { $script:companionEntries }
|
||||
function Test-OfficeMachineMsiProduct { $script:machineRegistered }
|
||||
function Get-AppxProvisionedPackage { param([switch]$Online) }
|
||||
function Get-AppxPackage { param([switch]$AllUsers) }
|
||||
function Assert-OfficeMicrosoftSignature { }
|
||||
function Invoke-OfficeProcess {
|
||||
param($FilePath,$Arguments,$LogPrefix)
|
||||
$script:removalCalls += $Arguments
|
||||
if ($script:removalMode -eq 'success') { $script:machineRegistered=$false }
|
||||
if ($script:removalMode -eq 'unknown') { return 1605 }
|
||||
if ($script:removalMode -eq 'reboot') { return 3010 }
|
||||
if ($script:removalMode -eq 'failure') { return 1603 }
|
||||
return 0
|
||||
}
|
||||
$reboot = Remove-OfficeCompanionApps $testRoot
|
||||
Assert-OfficeTest (!$reboot -and $script:removalCalls.Count -eq 0) 'An HKLM entry without machine MSI registration must be left to user cleanup.'
|
||||
foreach ($mode in @('success','remaining','unknown','failure','reboot')) {
|
||||
$script:machineRegistered=$true; $script:removalMode=$mode; $script:removalCalls=@()
|
||||
if ($mode -in @('remaining','unknown')) {
|
||||
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'registrations remain.*Microsoft Teams Meeting Add-in.*1\.26\.25904.*Fixture'
|
||||
} elseif ($mode -eq 'failure') {
|
||||
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'Could not remove.*1603'
|
||||
} else {
|
||||
$reboot=Remove-OfficeCompanionApps $testRoot
|
||||
Assert-OfficeTest ($reboot -eq ($mode -eq 'reboot')) "Incorrect reboot result for machine MSI mode $mode."
|
||||
}
|
||||
Assert-OfficeTest ($script:removalCalls.Count -eq 1 -and $script:removalCalls[0] -like ('/x ' + $addin.PSChildName + ' /qn /norestart*')) 'A real machine add-in must still be uninstalled silently.'
|
||||
}
|
||||
$script:companionEntries=@([pscustomobject]@{DisplayName='Microsoft OneDrive'; DisplayVersion='26.1'; PSPath='Registry::HKEY_LOCAL_MACHINE\Software\Fixture\OneDrive'; UninstallString=('"' + $env:ProgramFiles + '\Microsoft OneDrive\OneDriveSetup.exe" /uninstall /allusers')})
|
||||
$script:removalMode='remaining'
|
||||
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'registrations remain.*Microsoft OneDrive.*26\.1'
|
||||
$script:companionEntries=@($addin)
|
||||
function Test-OfficeMachineMsiProduct { throw 'MSI registration query failed' }
|
||||
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'MSI registration query failed'
|
||||
}
|
||||
& {
|
||||
$mine = [pscustomobject]@{DisplayName='Microsoft Teams Meeting Add-in for Microsoft Office'; Publisher='Microsoft'; DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'}
|
||||
$other = [pscustomobject]@{DisplayName=$mine.DisplayName; Publisher='Microsoft'; PSChildName='{22222222-2222-3333-4444-555555555555}'}
|
||||
function Test-Path { param($LiteralPath) $true }
|
||||
function Get-ItemProperty { param($Path) if ($Path -like 'HKLM:*') { $mine; $other } }
|
||||
function Test-OfficeUserMsiProduct { param($ProductCode) $ProductCode -eq $mine.PSChildName }
|
||||
$found=@(Get-OfficeUserTeamsAddinEntries)
|
||||
Assert-OfficeTest ($found.Count -eq 1 -and $found[0].PSChildName -eq $mine.PSChildName) 'User cleanup must discover its HKLM-advertised add-in, deduplicate registry views, and exclude other contexts.'
|
||||
function Test-OfficeUserMsiProduct { $false }
|
||||
Assert-OfficeTest (@(Get-OfficeUserTeamsAddinEntries).Count -eq 0) 'User cleanup must not claim products registered only for another user or machine.'
|
||||
}
|
||||
& {
|
||||
function Remove-OfficeUserLegacyTeams { }
|
||||
function Get-OfficeUserTeamsAddinEntries { [pscustomobject]@{DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'} }
|
||||
function Test-Path { $false }
|
||||
function Test-OfficeUserMsiProduct { $script:userMsiRemains }
|
||||
function Start-Process {
|
||||
param($FilePath,$ArgumentList,$WindowStyle,[switch]$Wait,[switch]$PassThru)
|
||||
Assert-OfficeTest ($FilePath -like '*\msiexec.exe' -and $ArgumentList -like '/x * /qn /norestart' -and $Wait -and $WindowStyle -eq 'Hidden') 'User MSI uninstall must remain silent and synchronous.'
|
||||
[pscustomobject]@{ExitCode=$script:userMsiExit}
|
||||
}
|
||||
$script:userMsiRemains=$false; $script:userMsiExit=0
|
||||
Remove-OfficeUserCompanions
|
||||
$script:userMsiRemains=$true
|
||||
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'remains registered for this user'
|
||||
$script:userMsiExit=1605
|
||||
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'remains registered for this user'
|
||||
$script:userMsiExit=1603
|
||||
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'removal needs attention.*1603'
|
||||
function Start-Process {
|
||||
$script:userMsiStarts++
|
||||
$code = if ($script:userMsiRecovers -and $script:userMsiStarts -eq 3) {0} else {1618}
|
||||
[pscustomobject]@{ExitCode=$code}
|
||||
}
|
||||
function Test-OfficeUserMsiProduct { $script:userMsiChecks++; $script:userMsiChecks -lt 3 }
|
||||
$script:userMsiStarts=0; $script:userMsiChecks=0; $script:userMsiRecovers=$true
|
||||
Remove-OfficeUserCompanions
|
||||
Assert-OfficeTest ($script:userMsiStarts -eq 3 -and $script:userMsiChecks -eq 3) 'User MSI cleanup must recover from busy MSI and delayed registration removal.'
|
||||
$script:userMsiStarts=0; $script:userMsiRecovers=$false
|
||||
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'removal needs attention.*1618'
|
||||
Assert-OfficeTest ($script:userMsiStarts -eq (Get-OfficeUserCleanupDefinitions).MsiBusyAttempts) 'User MSI busy retries must be bounded.'
|
||||
}
|
||||
|
||||
# Exercise real cache deletion against synthetic profiles only. Documents/SSO stay intact.
|
||||
$profile = Join-Path $testRoot 'profile'
|
||||
$cache = Join-Path $profile 'AppData\Local\Microsoft\Office\Licenses'
|
||||
@@ -297,7 +590,9 @@ try {
|
||||
}
|
||||
& {
|
||||
function Invoke-OfficeProcess { return $script:installCode }
|
||||
function Get-OfficeSuiteInventory { }
|
||||
function Get-ItemProperty { return $script:installed }
|
||||
function Test-Path { $true }
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Standard'; OfficeArchitecture='64'}
|
||||
$media = [pscustomobject]@{Setup='inert.exe'; Config='inert.xml'; Version='16.0.1.2'}
|
||||
$script:installed = [pscustomobject]@{ProductReleaseIds='O365BusinessRetail'; Platform='x64'; VersionToReport='16.0.1.2'}
|
||||
@@ -311,6 +606,29 @@ try {
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
|
||||
$script:installCode=42
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'installation failed'
|
||||
$script:installCode=0; $script:installed.VersionToReport='16.0.1.2'; $script:officeChecks=0
|
||||
function Get-ItemProperty { $script:officeChecks++; if ($script:officeChecks -ge 3) { $script:installed } }
|
||||
Assert-OfficeTest ((Install-OfficeMedia $options $media $testRoot) -eq 0 -and $script:officeChecks -eq 3) 'Office verification must tolerate delayed Click-to-Run registration.'
|
||||
function Get-ItemProperty { $script:installed }
|
||||
function Get-OfficeSuiteInventory {
|
||||
$script:msiChecks++
|
||||
if ($script:msiMode -eq 'read-error') { throw 'MSI inventory access denied' }
|
||||
if ($script:msiChecks -eq 1 -or $script:msiMode -eq 'remaining' -or ($script:msiMode -eq 'delayed' -and $script:msiChecks -lt 4)) {
|
||||
[pscustomobject]@{DisplayName='Microsoft Office Professional Plus 2016'; WindowsInstaller=1}
|
||||
}
|
||||
}
|
||||
foreach ($script:msiMode in @('removed','delayed','remaining','read-error')) {
|
||||
$script:msiChecks=0
|
||||
if ($script:msiMode -eq 'remaining') {
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'MSI Office remains.*Office Professional Plus 2016.*new suite may already be installed.*manual scrub'
|
||||
Assert-OfficeTest ($script:msiChecks -eq ((Get-OfficeDeploymentDefinitions).RegistrationCheckAttempts + 2)) 'MSI removal must be verified with a bounded wait.'
|
||||
} elseif ($script:msiMode -eq 'read-error') {
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'MSI inventory access denied'
|
||||
} else {
|
||||
Assert-OfficeTest ((Install-OfficeMedia $options $media $testRoot) -eq 3010) 'Verified MSI removal requires a restart even if ODT returns zero.'
|
||||
if ($script:msiMode -eq 'delayed') { Assert-OfficeTest ($script:msiChecks -eq 4) 'MSI removal must allow registry propagation time.' }
|
||||
}
|
||||
}
|
||||
}
|
||||
& {
|
||||
$script:registered = @(); $script:started = @(); $script:removed = @()
|
||||
@@ -327,11 +645,122 @@ try {
|
||||
$pending = Start-OfficeUserCleanup $profiles ([pscustomobject]@{Helper='C:\secure\helper.ps1'}) (Join-Path $testRoot ('a'*32))
|
||||
Assert-OfficeTest ($script:registered.Count -eq 2 -and $script:started.Count -eq 1 -and $script:removed.Count -eq 1) 'User scheduling or completed task cleanup is incorrect.'
|
||||
Assert-OfficeTest ($pending.Count -eq 1 -and $pending[0] -eq 'logged-off') 'Logged-off user cleanup was reported complete.'
|
||||
function Unregister-ScheduledTask { throw 'Task Scheduler is temporarily unavailable.' }
|
||||
$pending = Start-OfficeUserCleanup $profiles ([pscustomobject]@{Helper='C:\secure\helper.ps1'}) (Join-Path $testRoot ('a'*32))
|
||||
Assert-OfficeTest ($pending.Count -eq 1 -and $pending[0] -eq 'logged-off') 'Completed task housekeeping must not fail deployment or mark completed cleanup pending.'
|
||||
}
|
||||
|
||||
# Real temporary files for cache reuse/tampering; no installer or network may run.
|
||||
& {
|
||||
$cacheRoot = Join-Path $testRoot 'cache-tests'; $null = [IO.Directory]::CreateDirectory($cacheRoot)
|
||||
$source = Join-Path $cacheRoot ('a' * 32); $null = [IO.Directory]::CreateDirectory($source)
|
||||
# LiteralPath matters: the staged fixture intentionally contains brackets.
|
||||
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $testRoot 'media [literal]')) { Copy-Item -LiteralPath $file.FullName -Destination $source -Recurse }
|
||||
$target = Join-Path $cacheRoot ('b' * 32); $null = [IO.Directory]::CreateDirectory($target)
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'; COMPANY='New Company'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'}
|
||||
$script:rejectCacheSignature = $false; $script:helperDownloads = 0
|
||||
function Get-CimInstance { }
|
||||
function Assert-OfficeMicrosoftSignature { param($Path) if ($script:rejectCacheSignature) { throw 'Untrusted cache signature' }; Assert-OfficeTest (Test-Path -LiteralPath $Path) 'Cache signature target was missing.' }
|
||||
function Save-OfficeDownload { param($Uri,$Path) if ([IO.Path]::GetFileName($Path) -ne 'Office-UserCleanup.ps1') { throw 'Unexpected network download on cache hit' }; $script:helperDownloads++; Set-Content -LiteralPath $Path -Value ('# ' + (Get-OfficeDeploymentDefinitions).HelperVersion) }
|
||||
function Invoke-OfficeProcess { throw 'A cached deployment must not redownload Office.' }
|
||||
$manifestPath = Join-Path $source 'media-cache.json'
|
||||
$originalManifest = Get-Content -LiteralPath $manifestPath -Raw
|
||||
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5'; OfficeArchitecture='64'}
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Teams selection mismatch reused the wrong cache.'
|
||||
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'; UpdateChannel='MonthlyEnterprise'}
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Channel mismatch reused the wrong cache.'
|
||||
$manifest = $originalManifest | ConvertFrom-Json; $manifest.CreatedUtc = [DateTime]::UtcNow.AddDays(-8).ToString('o')
|
||||
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Expired cache was reused.'
|
||||
Set-Content -LiteralPath $manifestPath -Value $originalManifest
|
||||
$stream = Join-Path $source 'ODT\Office\Data\16.0.12345.67890\stream.x64.x-none.dat'
|
||||
$originalBytes = [IO.File]::ReadAllBytes($stream); $changedBytes = $originalBytes.Clone(); $changedBytes[0] = $changedBytes[0] -bxor 1; [IO.File]::WriteAllBytes($stream, $changedBytes)
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Same-size payload corruption passed hash verification.'
|
||||
[IO.File]::WriteAllBytes($stream, $originalBytes)
|
||||
$extra = Join-Path $source 'ODT\unexpected.dll'; Set-Content -LiteralPath $extra -Value 'unexpected dependency'
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Unrecorded executable dependencies passed cache verification.'
|
||||
Remove-OfficeManagedItem $cacheRoot $extra
|
||||
function Get-CimInstance { [pscustomobject]@{CommandLine="setup.exe $source\install.xml"} }
|
||||
Assert-OfficeThrows { Restore-OfficeMediaCache $options $target } 'previous Office deployment still has active processes'
|
||||
Assert-OfficeTest (Test-Path -LiteralPath $stream) 'A live installer lost its cached media.'
|
||||
function Get-CimInstance { }
|
||||
$script:rejectCacheSignature = $true
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Invalid Microsoft signature was reused.'
|
||||
$script:rejectCacheSignature = $false
|
||||
$media = Initialize-OfficeMedia $options $target
|
||||
Assert-OfficeTest ($media.CachedMediaReused -and $media.Version -eq '16.0.12345.67890' -and $script:helperDownloads -eq 1) 'Deployment did not reuse the validated media and refresh the helper.'
|
||||
Assert-OfficeTest (!(Test-Path -LiteralPath (Join-Path $source 'ODT')) -and (Test-Path -LiteralPath $media.Setup)) 'Cache transfer duplicated large files or lost setup.'
|
||||
$config = [xml](Get-Content -LiteralPath $media.Config -Raw)
|
||||
Assert-OfficeTest ($config.Configuration.AppSettings.Setup.Value -eq 'New Company' -and $config.Configuration.Add.SourcePath -eq (Join-Path $target 'ODT')) 'Reused media retained stale company/configuration paths.'
|
||||
Assert-OfficeTest ((Get-Content -LiteralPath (Join-Path $target 'media-cache.json') -Raw | ConvertFrom-Json).CreatedUtc -eq ($originalManifest | ConvertFrom-Json).CreatedUtc) 'Reuse extended cache expiry.'
|
||||
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $testRoot } 'outside the Office deployment root'
|
||||
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $cacheRoot } 'outside the Office deployment root'
|
||||
}
|
||||
# Cleanup runs synchronously on success. Downloads are temporary; pending-user
|
||||
# helpers have a separate durable folder and are never part of the media cache.
|
||||
& {
|
||||
$root = Join-Path $testRoot 'temporary-downloads'; $null = [IO.Directory]::CreateDirectory($root)
|
||||
$workspace = Join-Path $root ('c' * 32); $null = [IO.Directory]::CreateDirectory($workspace)
|
||||
foreach ($name in @('options.json', 'Office-UserCleanup.ps1', 'user-cleanup.lock', 'office-install.stdout.log', 'odt.exe')) { Set-Content -LiteralPath (Join-Path $workspace $name) -Value 'fixture' }
|
||||
$null = [IO.Directory]::CreateDirectory((Join-Path $workspace 'ODT'))
|
||||
Set-Content -LiteralPath (Join-Path $workspace 'ODT\payload') -Value 'fixture'
|
||||
$userRoot = Join-Path $testRoot 'durable-user-helpers'; $null = [IO.Directory]::CreateDirectory($userRoot)
|
||||
function New-OfficeWorkspace {
|
||||
param($Root,$DeploymentId)
|
||||
Assert-OfficeTest ($Root -eq (Join-Path $env:ProgramData 'EmberkomOfficeDeployment') -and $DeploymentId -eq ('c' * 32)) 'Pending-user helper must use a separate protected ProgramData workspace.'
|
||||
$path = Join-Path $userRoot $DeploymentId; $null = [IO.Directory]::CreateDirectory($path)
|
||||
Set-Content -LiteralPath (Join-Path $path 'user-cleanup.lock') -Value ''
|
||||
$path
|
||||
}
|
||||
$media = [pscustomobject]@{Helper=(Join-Path $workspace 'Office-UserCleanup.ps1')}
|
||||
$userWorkspace = New-OfficeUserWorkspace $media $workspace
|
||||
Assert-OfficeTest ($media.Helper -eq (Join-Path $userWorkspace 'Office-UserCleanup.ps1') -and (Test-Path -LiteralPath $media.Helper)) 'User helper was not separated from cached installers.'
|
||||
$script:cleanupTasks = $true; $script:cleanupProcess = $true
|
||||
function Get-CimInstance { if ($script:cleanupProcess) { [pscustomobject]@{CommandLine="setup.exe $workspace\install.xml"} } }
|
||||
function Get-ScheduledTask { if ($script:cleanupTasks) { [pscustomobject]@{TaskName="Emberkom-OfficeCleanup-$('c' * 32)-SID"; State='Ready'} } }
|
||||
function Register-ScheduledTask { throw 'File cleanup must not register any task.' }
|
||||
$warnings = Complete-OfficeDeploymentFiles $workspace $userWorkspace
|
||||
Assert-OfficeTest ($warnings.Count -and (Test-Path -LiteralPath (Join-Path $workspace 'ODT'))) 'Cleanup deleted files referenced by a surviving installer.'
|
||||
$script:cleanupProcess = $false
|
||||
$warnings = Complete-OfficeDeploymentFiles $workspace $userWorkspace
|
||||
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath $workspace)) 'Successful deployment left its temporary workspace behind.'
|
||||
Assert-OfficeTest (Test-Path -LiteralPath $media.Helper) 'Temporary cache cleanup deleted the pending-user helper.'
|
||||
$script:cleanupTasks = $false
|
||||
$warnings = Complete-OfficeDeploymentFiles $workspace $userWorkspace
|
||||
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath $userWorkspace)) 'Completed user cleanup left its helper folder behind.'
|
||||
# Older ProgramData stages lose only known downloads, never deferred-user files.
|
||||
$legacy = Join-Path $userRoot ('d' * 32); $null = [IO.Directory]::CreateDirectory($legacy)
|
||||
foreach ($name in @('options.json','odt.exe','Office-UserCleanup.ps1','user-cleanup.lock')) { Set-Content -LiteralPath (Join-Path $legacy $name) -Value 'fixture' }
|
||||
$warnings = Complete-OfficeDeploymentFiles $workspace -PreviousRoot $userRoot
|
||||
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath (Join-Path $legacy 'odt.exe')) -and (Test-Path -LiteralPath (Join-Path $legacy 'Office-UserCleanup.ps1'))) 'Legacy download cleanup lost pending-user state or left old downloads.'
|
||||
}
|
||||
# The legacy uninstaller must delete both successful and partial downloads.
|
||||
& {
|
||||
$legacy = Read-OfficeAst 'Uninstall-MicrosoftOffice.ps1'
|
||||
function End-Process { }
|
||||
function Get-TempPath { $testRoot }
|
||||
function Download-File { param($URL,$File) $script:legacyDownload=$File; Set-Content -LiteralPath $File -Value 'inert VBS'; if ($script:legacyMode -eq 'download') { throw 'synthetic download failure' }; $File }
|
||||
function Start-Process { if ($script:legacyMode -eq 'launch') { throw 'synthetic launch failure' } }
|
||||
foreach ($script:legacyMode in @('success', 'download', 'launch')) {
|
||||
$failed=$false
|
||||
try { $null = & ([scriptblock]::Create($legacy.Extent.Text)) 2>$null } catch { $failed=$true }
|
||||
Assert-OfficeTest (!(Test-Path -LiteralPath $script:legacyDownload)) "Legacy uninstaller left its $script:legacyMode download behind."
|
||||
Assert-OfficeTest ($failed -eq ($script:legacyMode -ne 'success')) 'Legacy cleanup swallowed the original failure.'
|
||||
}
|
||||
}
|
||||
|
||||
# Test orchestration with every machine mutation mocked.
|
||||
& {
|
||||
function New-Object {
|
||||
param($TypeName,$ArgumentList)
|
||||
# Do not open the production mutex: a real SYSTEM deployment may be running.
|
||||
if ($TypeName -eq 'Threading.Mutex') { return [Threading.Mutex]::new($false) }
|
||||
throw "Unexpected object requested by orchestration fixture: $TypeName"
|
||||
}
|
||||
function Assert-OfficeDeploymentHost { }
|
||||
function Complete-OfficeDeploymentFiles { param($Workspace,$UserWorkspace,$PreviousRoot) $script:artifactCleanupRuns++; if ($script:mode -eq 'cleanup-warning') { return ,@('Synthetic file in use') }; return ,@() }
|
||||
function New-OfficeUserWorkspace { param($Media,$Workspace) $Workspace }
|
||||
function Register-ScheduledTask { throw 'Unexpected task registration in orchestration fixture.' }
|
||||
function New-OfficeWorkspace { $path = Join-Path $testRoot ([guid]::NewGuid().ToString('N')); $null = New-Item -ItemType Directory -Path $path; $path }
|
||||
function Start-Transcript { }
|
||||
function Stop-Transcript { }
|
||||
@@ -339,39 +768,63 @@ try {
|
||||
Set-Content -LiteralPath (Join-Path $profile 'NTUSER.DAT') -Value 'test hive, never loaded'
|
||||
function Stop-OfficeDeploymentApps { $script:events += 'apps' }
|
||||
function Get-OfficeRunningApps { }
|
||||
function Get-OfficeSuiteInventory { [pscustomobject]@{DisplayName='Synthetic Office'} }
|
||||
function Initialize-OfficeMedia { $script:events += 'download'; if ($script:mode -eq 'download') { throw 'download failure' }; [pscustomobject]@{Version='16.0.1.2'} }
|
||||
function Get-OfficeSuiteInventory { if ($script:mode -ne 'office-reboot' -or $script:removalStillRegistered) { [pscustomobject]@{DisplayName='Synthetic Office'} } }
|
||||
function Get-OfficeMachineCompanionEntries { if ($script:removalStillRegistered) { [pscustomobject]@{DisplayName='Synthetic OneDrive'} } }
|
||||
function Initialize-OfficeMedia { param($Options,$Workspace) $script:events += 'download'; if ($script:mode -eq 'download') { throw 'download failure' }; [pscustomobject]@{Version='16.0.1.2'; Helper=(Join-Path $Workspace 'Office-UserCleanup.ps1')} }
|
||||
function Remove-OfficeCompanionApps { $script:events += 'companions'; if ($script:mode -eq 'companions') { throw 'companion failure' }; return ($script:mode -eq 'reboot') }
|
||||
function Remove-OfficeSuite { $script:events += 'scrub'; if ($script:mode -eq 'scrub') { throw 'scrub failure' } }
|
||||
function Remove-OfficeSuite { $script:events += 'remove-office'; if ($script:mode -eq 'remove-office') { throw 'Office removal failure' }; if ($script:mode -eq 'office-reboot') { return 3010 }; return 0 }
|
||||
function Clear-OfficeProfileIdentity { $script:events += 'identity'; if ($script:mode -eq 'identity') { throw 'identity failure' } }
|
||||
function Start-OfficeUserCleanup { $script:events += 'user'; if ($script:mode -eq 'user') { throw 'user still running' }; if ($script:mode -eq 'pending') { return ,@('S-1-5-21-test') }; return ,@() }
|
||||
function Set-OfficeReinstallPhase { $script:events += 'phase'; if ($script:mode -eq 'phase') { throw 'user still holds cleanup lock' } }
|
||||
function Install-OfficeMedia { $script:events += 'install'; if ($script:mode -eq 'install') { throw 'install failure' }; return 0 }
|
||||
function Install-OfficeCompanionApps { param($Media,$Workspace,[bool]$InstallTeams) $script:teamsRequested=$InstallTeams; $script:events += 'install-companions'; if ($script:mode -eq 'install-companions') { throw 'companion install failure' }; [pscustomobject]@{ExitCode=$(if ($script:mode -eq 'companion-reboot') {3010} else {0}); Versions=@{NewOutlook='1'; OneDrive='1'}} }
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'}
|
||||
foreach ($script:mode in @('success','download','companions','scrub','identity','user','phase','install','install-companions','pending','reboot','companion-reboot')) {
|
||||
$script:removalStillRegistered=$false
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'; DeferReboot='false'}
|
||||
foreach ($script:mode in @('success','download','companions','remove-office','identity','user','phase','install','install-companions','pending','reboot','office-reboot','companion-reboot')) {
|
||||
$script:artifactCleanupRuns = 0
|
||||
$script:events = @(); $errorResult = $null; $result = $null
|
||||
try { $result = Invoke-OfficeDeployment $options } catch { $errorResult = $_ }
|
||||
if ($script:mode -in @('success','pending','reboot','companion-reboot')) {
|
||||
if ($script:mode -in @('success','pending','reboot','office-reboot','companion-reboot')) {
|
||||
Assert-OfficeTest ($null -eq $errorResult) "Unexpected failure in $script:mode : $errorResult"
|
||||
$code = switch ($script:mode) { 'success' {0}; 'pending' {2}; 'reboot' {3010}; 'companion-reboot' {3010} }
|
||||
$code = switch ($script:mode) { 'success' {0}; 'pending' {2}; 'reboot' {3010}; 'office-reboot' {3010}; 'companion-reboot' {3010} }
|
||||
Assert-OfficeTest ($result.ExitCode -eq $code) "Wrong result code for $script:mode"
|
||||
} else { Assert-OfficeTest ($null -ne $errorResult) "Failure swallowed in $script:mode" }
|
||||
if ($script:mode -notin @('success','pending','install','install-companions','companion-reboot')) { Assert-OfficeTest ('install' -notin $script:events) "Install ran after $script:mode failure/reboot." }
|
||||
if ($script:mode -notin @('success','pending','install-companions','companion-reboot')) { Assert-OfficeTest ('install-companions' -notin $script:events) "Companion install ran after $script:mode failure/reboot." }
|
||||
if ($script:mode -eq 'download') { Assert-OfficeTest ('companions' -notin $script:events -and 'scrub' -notin $script:events) 'Removal ran after download failed.' }
|
||||
if ($script:mode -eq 'success') { Assert-OfficeTest (($script:events -join ',') -eq 'download,apps,companions,scrub,identity,user,phase,install,install-companions') 'Deployment order changed.' }
|
||||
if ($script:mode -eq 'download') { Assert-OfficeTest ('companions' -notin $script:events -and 'remove-office' -notin $script:events) 'Removal ran after download failed.' }
|
||||
Assert-OfficeTest ($script:artifactCleanupRuns -eq $(if ($script:mode -in @('success','pending','companion-reboot')) {1} else {0})) "Media cleanup ran before successful installation, or was skipped after success: $script:mode"
|
||||
if ($script:mode -eq 'office-reboot') { Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'RestartRequiredBeforeInstall' -and 'identity' -notin $script:events -and 'user' -notin $script:events) 'Office removal restart must stop before user cleanup and replacement installation.' }
|
||||
if ($script:mode -eq 'success') { Assert-OfficeTest (($script:events -join ',') -eq 'download,apps,companions,remove-office,identity,user,phase,install,install-companions') 'Deployment order changed.' }
|
||||
}
|
||||
$script:mode='cleanup-warning'; $script:events=@()
|
||||
$result = @(Invoke-OfficeDeployment $options)
|
||||
Assert-OfficeTest ($result.Count -eq 1 -and $result[0].ArtifactCleanupPending -and $result[0].ExitCode -eq 0 -and $result[0].OfficeDeploymentStatus -eq 'Installed') 'Artifact cleanup problems corrupted the receipt or failed a verified installation.'
|
||||
foreach ($script:mode in @('reboot','office-reboot')) {
|
||||
foreach ($script:removalStillRegistered in @($false,$true)) {
|
||||
$script:events=@()
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'}
|
||||
$result = Invoke-OfficeDeployment $options
|
||||
Assert-OfficeTest ($result.ExitCode -eq 3010 -and $result.RestartRequired -and $result.DeferReboot -is [bool] -and $result.DeferReboot) 'A deferred removal restart must survive later zero-exit installers in the final result.'
|
||||
if ($script:removalStillRegistered) {
|
||||
Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'RestartRequiredBeforeInstall' -and 'install' -notin $script:events -and 'install-companions' -notin $script:events) 'Incomplete removal must still stop before installation with DeferReboot=true.'
|
||||
} else {
|
||||
Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'Installed' -and 'install' -in $script:events -and 'install-companions' -in $script:events) 'Verified removal should complete installation without an intervening restart.'
|
||||
}
|
||||
}
|
||||
}
|
||||
$script:removalStillRegistered=$false
|
||||
$script:mode='success'; $script:events=@()
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'}
|
||||
$result = Invoke-OfficeDeployment $options
|
||||
Assert-OfficeTest (!$script:teamsRequested -and !$result.TeamsSelected) 'Deployment did not pass the no-Teams choice to companion installation/reporting.'
|
||||
Assert-OfficeTest (!$result.RestartRequired -and $result.ExitCode -eq 0) 'A clean deployment without restart requests must not demand a restart.'
|
||||
foreach ($shutdown in @('Abort','Force')) {
|
||||
foreach ($validate in @($null, '', 'true')) {
|
||||
$script:events=@()
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeAppShutdown=$shutdown; ValidateBeforeChanges=$validate}
|
||||
$result = Invoke-OfficeDeployment $options
|
||||
Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'ValidationPassed' -and $result.ExitCode -eq 0 -and $result.ValidateBeforeChanges) 'Validation did not produce a distinct result.'
|
||||
Assert-OfficeTest ($result.OfficeRemovalMethod -eq 'SilentODT' -and $result.DeferReboot -is [bool] -and $result.DeferReboot) 'Validation must identify the silent removal method and Boolean restart selection.'
|
||||
Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Validation reached app shutdown, removal, identities, user tasks, phase changes, or installation.'
|
||||
Assert-OfficeTest (!$result.TeamsSelected -and $result.ProfileCount -eq 1 -and $result.ExistingOffice[0] -eq 'Synthetic Office') 'Validation report lost the deployment plan.'
|
||||
}
|
||||
@@ -389,6 +842,9 @@ try {
|
||||
Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Failed validation reached mutations.'
|
||||
$options.ValidateBeforeChanges='false'
|
||||
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'validated Boolean'
|
||||
$options.ValidateBeforeChanges=$false; $options.DeferReboot='false'; $script:events=@()
|
||||
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'DeferReboot must be a validated Boolean'
|
||||
Assert-OfficeTest ($script:events.Count -eq 0) 'Unparsed restart input must fail before any deployment action.'
|
||||
}
|
||||
|
||||
# Exercise unchanged Run-Script with injected strings; all downloads return inert source.
|
||||
@@ -425,7 +881,7 @@ function Invoke-OfficeDeployment {
|
||||
if ($script:ProbeMode -eq 'failure') { throw 'Simulated deployment failure.' }
|
||||
if ($script:ProbeMode -eq 'missing') { return }
|
||||
$null = Write-Output 'Mock action diagnostic'
|
||||
[pscustomobject]@{OfficeDeploymentStatus='Mocked'; ExitCode=$script:ProbeExitCode; ProductId=$Options.ProductId; Company=$Options.Company; Activation=$Options.OfficeActivation; ValidateBeforeChanges=$Options.ValidateBeforeChanges}
|
||||
[pscustomobject]@{OfficeDeploymentStatus='Mocked'; ExitCode=$script:ProbeExitCode; ProductId=$Options.ProductId; Company=$Options.Company; Activation=$Options.OfficeActivation; ValidateBeforeChanges=$Options.ValidateBeforeChanges; DeferReboot=$Options.DeferReboot}
|
||||
}
|
||||
'@
|
||||
$mockCore = $coreAst.Extent.Text.Remove($workload.Extent.StartOffset, $workload.Extent.EndOffset - $workload.Extent.StartOffset).Insert($workload.Extent.StartOffset, $mockWorkload)
|
||||
@@ -461,7 +917,7 @@ function New-Object {
|
||||
__LAUNCH__
|
||||
'@
|
||||
function ConvertTo-OfficeTestBase64 { param([string]$Text) [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($Text)) }
|
||||
$probeValues = @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeActivation='SharedComputer'; ValidateBeforeChanges='false'; COMPANY='A & B '' " $() `company`'}
|
||||
$probeValues = @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeActivation='SharedComputer'; ValidateBeforeChanges='false'; DeferReboot='false'; COMPANY='A & B '' " $() `company`'}
|
||||
$shimSource = Get-Content -LiteralPath (Join-Path $repo 'rmm\Install-MicrosoftOffice365.ps1') -Raw
|
||||
foreach ($case in @(@{Mode='success';Code=0;Validate='true'},@{Mode='success';Code=0;Validate=''},@{Mode='success';Code=0;Validate='false'},@{Mode='success';Code=2;Validate='false'},@{Mode='success';Code=3010;Validate='false'},@{Mode='failure';Code=1;Validate='false'},@{Mode='missing';Code=1;Validate='true'})) {
|
||||
$probeValues.ValidateBeforeChanges=$case.Validate
|
||||
@@ -478,6 +934,7 @@ __LAUNCH__
|
||||
$receipt = $probeText.Substring($probeText.IndexOf('{')) | ConvertFrom-Json
|
||||
Assert-OfficeTest ($receipt.ProductId -eq 'O365ProPlusEEANoTeamsRetail' -and $receipt.Company -ceq $probeValues.COMPANY -and $receipt.Activation -eq 'SharedComputer') 'Shim lost injected strings before main workload.'
|
||||
Assert-OfficeTest ($receipt.ValidateBeforeChanges -eq ($case.Validate -ne 'false')) 'Shim lost the validation gate.'
|
||||
Assert-OfficeTest ($receipt.DeferReboot -is [bool] -and !$receipt.DeferReboot) 'Shim/main entry lost or misparsed the injected false restart string.'
|
||||
$probeLog = Get-Content -LiteralPath (Join-Path $testRoot 'probe-management.log') -Raw
|
||||
Assert-OfficeTest ($probeLog -match 'Mock action diagnostic' -and $probeLog -match '"OfficeDeploymentStatus"' -and $probeText -notmatch 'Mock action diagnostic') 'Diagnostics or receipt did not reach the correct log/console destination.'
|
||||
Assert-OfficeTest ($probeLog -notmatch 'Validation only:|Diagnostic log:') 'Console-only output was unexpectedly logged.'
|
||||
@@ -488,13 +945,14 @@ __LAUNCH__
|
||||
}
|
||||
}
|
||||
# Exercise the native-host command with the same network mock and an inert child workload.
|
||||
$nativePayload = '$null = Write-Output "Native logging diagnostic"; [pscustomobject]@{Subscription=$OfficeSubscription; Company=$COMPANY; Activation=$OfficeActivation; ValidateBeforeChanges=(ConvertTo-RmmBoolean $ValidateBeforeChanges); LogFile=$Global:LogFile} | ConvertTo-Json -Compress; exit 2'
|
||||
$nativePayload = '$null = Write-Output "Native logging diagnostic"; [pscustomobject]@{Subscription=$OfficeSubscription; Company=$COMPANY; Activation=$OfficeActivation; ValidateBeforeChanges=(ConvertTo-RmmBoolean $ValidateBeforeChanges); DeferReboot=(ConvertTo-RmmBoolean $DeferReboot); LogFile=$Global:LogFile} | ConvertTo-Json -Compress; exit 2'
|
||||
$probe = $probeTemplate.Replace('__TOOLS__', (ConvertTo-OfficeTestBase64 $mockToolsText)).Replace('__CORE__', (ConvertTo-OfficeTestBase64 $nativePayload)).Replace('__VALUES__', (ConvertTo-OfficeTestBase64 '{}')).Replace('__MODE__', 'success').Replace('__CODE__', '2').Replace('__LAUNCH__', (New-OfficeNativeCommand $probeValues))
|
||||
$probePath = Join-Path $testRoot 'native-probe.ps1'; Set-Content -LiteralPath $probePath -Value $probe
|
||||
$probeOutput = & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $probePath
|
||||
Assert-OfficeTest ($LASTEXITCODE -eq 2) 'Native-host command lost the workload exit code.'
|
||||
$receipt = $probeOutput | ConvertFrom-Json
|
||||
Assert-OfficeTest ($receipt.Subscription -ceq $probeValues.OfficeSubscription -and $receipt.Company -ceq $probeValues.COMPANY -and $receipt.Activation -eq 'SharedComputer') 'Native-host command changed injected strings.'
|
||||
Assert-OfficeTest ($receipt.DeferReboot -is [bool] -and !$receipt.DeferReboot) 'Native-host command lost the false restart selection.'
|
||||
Assert-OfficeTest ($receipt.ValidateBeforeChanges -and $receipt.LogFile -eq $Global:LogFile -and (Get-Content -LiteralPath $Global:LogFile -Raw) -match 'Native logging diagnostic') 'Native-host command must reload Tools and preserve validation and the parent log.'
|
||||
# Simulate Syncro's 32-bit Windows PowerShell launching the native 64-bit 5.1 host.
|
||||
# Only the relaunch payload is replaced; host selection and process exit handling are real.
|
||||
|
||||
Reference in New Issue
Block a user