fix(windows): defer missing tray task during trust reset
This commit is contained in:
1 parent
97a0139e3d
commit
2d89e80410
3 files changed
+137
No files matched your search
@@ -37,6 +37,10 @@ Assert-SourceContains '\$existingTask\s*=\s*Get-MinerOpsScheduledTask' `
|
||||
"Existing task preservation guard is missing."
|
||||
Assert-SourceContains 'Preserving existing Scheduled Task' `
|
||||
"Existing task preservation is not explicit."
|
||||
Assert-SourceContains 'Test-MinerOpsInstallerShouldCreateMissingTask' `
|
||||
"Missing-task trust-reset policy helper is absent."
|
||||
Assert-SourceContains 'Deferring missing per-user Scheduled Task' `
|
||||
"Missing per-user task deferral is not explicit."
|
||||
Assert-SourceContains 'ExtraArguments\s*=\s*"-Limit 0 -TimeoutMs 8000"' `
|
||||
"Fresh enrichment task arguments are missing."
|
||||
Assert-SourceContains 'Stop-MinerOpsScheduledTaskForUpgrade' `
|
||||
@@ -52,6 +56,98 @@ Assert-SourceContains 'could not restart restored MinerOpsAgent' `
|
||||
Assert-SourceContains 'Assert-MinerOpsInstallerTrustedAncestors' `
|
||||
"Installer does not validate ancestor namespace protection."
|
||||
|
||||
$taskDefinitionsStart = $source.IndexOf('$definitions = @(')
|
||||
$taskLoopStart = $source.IndexOf(
|
||||
'foreach ($definition in $definitions)', $taskDefinitionsStart
|
||||
)
|
||||
if ($taskDefinitionsStart -lt 0 -or $taskLoopStart -le $taskDefinitionsStart) {
|
||||
throw "Scheduled Task definitions or reconciliation loop were not found."
|
||||
}
|
||||
$taskDefinitions = $source.Substring(
|
||||
$taskDefinitionsStart, $taskLoopStart - $taskDefinitionsStart
|
||||
)
|
||||
foreach ($policy in @(
|
||||
@{ Name = "MinerOpsAgent"; Expected = '\$true' },
|
||||
@{ Name = "MinerOpsAgentTray"; Expected = '\$false' },
|
||||
@{ Name = "MinerOpsApi3Enrichment"; Expected = '\$true' },
|
||||
@{ Name = "MinerOpsPoolPoller"; Expected = '\$true' }
|
||||
)) {
|
||||
$definition = [regex]::Match(
|
||||
$taskDefinitions,
|
||||
('(?s)@\{{.*?Name\s*=\s*"{0}".*?\}}' -f
|
||||
[regex]::Escape($policy.Name))
|
||||
).Value
|
||||
if ([string]::IsNullOrWhiteSpace($definition) -or
|
||||
$definition -notmatch (
|
||||
'CreateWhenMissingDuringTrustReset\s*=\s*{0}' -f
|
||||
$policy.Expected
|
||||
)) {
|
||||
throw "Scheduled Task $($policy.Name) has the wrong trust-reset creation policy."
|
||||
}
|
||||
}
|
||||
|
||||
$taskLoopEnd = $source.IndexOf(
|
||||
'if ($mainTaskWasRunning', $taskLoopStart
|
||||
)
|
||||
if ($taskLoopEnd -le $taskLoopStart) {
|
||||
throw "Scheduled Task reconciliation loop end was not found."
|
||||
}
|
||||
$taskLoop = $source.Substring($taskLoopStart, $taskLoopEnd - $taskLoopStart)
|
||||
$preserveIndex = $taskLoop.IndexOf('$null -ne $existingTask')
|
||||
$deferIndex = $taskLoop.IndexOf(
|
||||
'Test-MinerOpsInstallerShouldCreateMissingTask'
|
||||
)
|
||||
$actionIndex = $taskLoop.IndexOf('New-ScheduledTaskAction')
|
||||
if (
|
||||
$preserveIndex -lt 0 -or
|
||||
$deferIndex -le $preserveIndex -or
|
||||
$actionIndex -le $deferIndex
|
||||
) {
|
||||
throw "Existing-task preservation and missing-task deferral are ordered unsafely."
|
||||
}
|
||||
if ($taskLoop -match '80070534|No mapping between account names') {
|
||||
throw "Missing per-user task handling must be policy-based, not HRESULT-based."
|
||||
}
|
||||
|
||||
$taskPolicyFunction = [regex]::Match(
|
||||
$source,
|
||||
'(?s)function Test-MinerOpsInstallerShouldCreateMissingTask \{.*?\n\}'
|
||||
).Value
|
||||
if ([string]::IsNullOrWhiteSpace($taskPolicyFunction)) {
|
||||
throw "Missing-task trust-reset policy function source was not found."
|
||||
}
|
||||
Invoke-Expression $taskPolicyFunction
|
||||
$trayPolicy = [pscustomobject]@{
|
||||
CreateWhenMissingDuringTrustReset = $false
|
||||
}
|
||||
$systemTaskPolicy = [pscustomobject]@{
|
||||
CreateWhenMissingDuringTrustReset = $true
|
||||
}
|
||||
if (Test-MinerOpsInstallerShouldCreateMissingTask `
|
||||
-Definition $trayPolicy -TrustResetMode $true) {
|
||||
throw "Trust reset would create a missing per-user tray task."
|
||||
}
|
||||
if (-not (Test-MinerOpsInstallerShouldCreateMissingTask `
|
||||
-Definition $trayPolicy -TrustResetMode $false)) {
|
||||
throw "Normal interactive installation would not repair a missing tray task."
|
||||
}
|
||||
if (-not (Test-MinerOpsInstallerShouldCreateMissingTask `
|
||||
-Definition $systemTaskPolicy -TrustResetMode $true)) {
|
||||
throw "Trust reset would skip a missing explicit-SYSTEM task."
|
||||
}
|
||||
$missingPolicyRejected = $false
|
||||
try {
|
||||
[void](Test-MinerOpsInstallerShouldCreateMissingTask `
|
||||
-Definition ([pscustomobject]@{}) -TrustResetMode $true)
|
||||
}
|
||||
catch {
|
||||
$missingPolicyRejected = $_.Exception.Message -match
|
||||
'trust-reset creation policy is missing'
|
||||
}
|
||||
if (-not $missingPolicyRejected) {
|
||||
throw "Trust reset accepted a task definition without explicit policy."
|
||||
}
|
||||
|
||||
foreach ($functionName in @(
|
||||
"Assert-MinerOpsInstallerNoReparsePath",
|
||||
"Assert-MinerOpsInstallerTrustedAncestors"
|
||||
|
||||
Reference in new issue
Block a user