Skip to content

Commit

Permalink
(tests) Fixup user agent regex for Extension
Browse files Browse the repository at this point in the history
Correct the Licensed version capture so that the regex matches when
Licensed Extension with User Agent update is installed. Also adds a
validation that the LicensedVersion is present when Licensed Extension
is installed.
  • Loading branch information
corbob committed Nov 27, 2024
1 parent 7387944 commit e852aff
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/pester-tests/features/UserAgent.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ Describe "Chocolatey User Agent" -Tag Chocolatey, UserAgent {

$userAgent = $matches['UserAgent']

$userAgent -match 'Chocolatey Command Line/(?<Version>[a-z0-9.-]+) ([a-z ]+/(<?LicensedVersion>[a-z0-9.-]+) )?\((?<RootProcess>[^,)]+)(?:, (?<ParentProcess>[^)]+))?\) via NuGet Client' |
$userAgent -match 'Chocolatey Command Line/(?<Version>[a-z0-9.-]+) ([a-z ]+/(?<LicensedVersion>[a-z0-9.-]+) )?\((?<RootProcess>[^,)]+)(?:, (?<ParentProcess>[^)]+))?\) via NuGet Client' |
Should -BeTrue -Because "the user agent string should contain the choco.exe version, the licensed extension version if any, and any parent processes. $logLine"

$matches['Version'] | Should -Be $ChocolateyVersion -Because "the user agent string should contain the currently running Chocolatey version. $logLine"

if (Test-PackageIsEqualOrHigher -PackageName 'chocolatey.extension' -Version '6.3.0-alpha') {
# We are not asserting the Licensed Extension version here as the Chocolatey package version often
# mismatches the assembly version.
$matches['LicensedVersion'] | Should -Not -BeNullOrEmpty -Because "Chocolatey Licensed Extension is installed and should be in the user agent. $logLine"
}

$filteredProcesses = @($Processes | Where-Object { $_ -notin $ExcludedProcesses })

if ($filteredProcesses.Count -gt 1) {
Expand Down

0 comments on commit e852aff

Please sign in to comment.