$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' } }