From 21890047e28b55ec48f0cd0c61badc1c63060f4b Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Wed, 23 Sep 2026 09:11:29 -0600 Subject: [PATCH] Fix credential provider startup policy command generation --- ...tall-SguCredentialProviderUpdatePolicy.ps1 | 3 +- .../CredentialProviderUpdatePolicy.Tests.ps1 | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/CredentialProviderUpdatePolicy.Tests.ps1 diff --git a/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 b/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 index bab3bdf..97bbf81 100644 --- a/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 +++ b/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 @@ -79,8 +79,7 @@ if (-not `$computerSystem.PartOfDomain -or `$computerSystem.DomainRole -ge 4) { # the institutional tile at startup while leaving the native password tile # registered for manual recovery. `$logonUiPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI' -Set-ItemProperty -Path `$logonUiPath -Name LastLoggedOnProvider ` - -Value '{D789CFD8-5AD4-489F-9B83-7EB5D9D09335}' +Set-ItemProperty -Path `$logonUiPath -Name LastLoggedOnProvider -Value '{D789CFD8-5AD4-489F-9B83-7EB5D9D09335}' `$updateRoot = Join-Path `$env:ProgramData "SGU\CredentialProviderUpdates\`$version" `$markerPath = Join-Path `$updateRoot 'complete.marker' diff --git a/tests/CredentialProviderUpdatePolicy.Tests.ps1 b/tests/CredentialProviderUpdatePolicy.Tests.ps1 new file mode 100644 index 0000000..1b01448 --- /dev/null +++ b/tests/CredentialProviderUpdatePolicy.Tests.ps1 @@ -0,0 +1,32 @@ +$repositoryRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path +$installerPath = Join-Path $repositoryRoot 'scripts\Install-SguCredentialProviderUpdatePolicy.ps1' + +Describe 'Credential Provider startup policy' { + It 'generates a complete LastLoggedOnProvider command' { + $Version = '0.6.16' + $ClientPackageUri = 'https://example.invalid/client.zip' + $ClientPackageSha256 = 'A' * 64 + $source = Get-Content -LiteralPath $installerPath -Raw + $template = [regex]::Match($source, '(?ms)^\$startupScript = @"\r?\n.*?^"@') + $template.Success | Should Be $true + Invoke-Expression $template.Value + + $tokens = $null + $errors = $null + $ast = [Management.Automation.Language.Parser]::ParseInput( + $startupScript, [ref]$tokens, [ref]$errors) + $errors.Count | Should Be 0 + + $commands = @($ast.FindAll({ + param($node) + $node -is [Management.Automation.Language.CommandAst] -and + $node.GetCommandName() -eq 'Set-ItemProperty' + }, $true)) + $commands.Count | Should Be 1 + @($commands[0].CommandElements | Where-Object { + $_ -is [Management.Automation.Language.CommandParameterAst] -and + $_.ParameterName -eq 'Value' + }).Count | Should Be 1 + $startupScript | Should Not Match '(?m)^\s+-Value\s' + } +}