fix: 本地账号稳定注册上游中继任务 (#111)

This commit is contained in:
WuYongJie 2026-09-07 15:08:58 +08:00
parent 6796d68012
commit c96b314a9d
2 changed files with 18 additions and 1 deletions

View File

@ -85,7 +85,14 @@ $argumentList = @(
'-ConfigPath', (ConvertTo-TaskArgument $privateConfigPath)
)
$taskArguments = $argumentList -join ' '
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$currentUser = if ([string]::IsNullOrWhiteSpace($env:USERNAME)) {
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
}
else {
# Task Scheduler can return ERROR_FILE_NOT_FOUND when a local SAM account
# is registered with a stale or unresolvable machine-qualified prefix.
$env:USERNAME
}
if ($PSCmdlet.ShouldProcess($TaskName, 'register and start the read-only upstream tunnel task')) {
$privateConfigDirectory = Split-Path -Parent $privateConfigPath

View File

@ -79,4 +79,14 @@ class BusinessMirrorScheduleTest extends TestCase
$this->assertStringContainsString('ClickHouse did not become healthy', $contents, $script);
}
}
public function test_tunnel_task_uses_the_local_sam_account_and_hidden_powershell(): void
{
$contents = file_get_contents(dirname(__DIR__, 3) . '/scripts/install-upstream-tunnel-task.ps1');
$this->assertIsString($contents);
$this->assertStringContainsString('$env:USERNAME', $contents);
$this->assertStringContainsString("'-WindowStyle', 'Hidden'", $contents);
$this->assertStringContainsString('TASK_LOGON_INTERACTIVE_TOKEN', $contents);
}
}