chocolatey / chocolatey-ansible

The Chocolatey module collection for Ansible
GNU General Public License v3.0
47 stars 29 forks source link

(#132) Ensure only Chocolatey CLI version number is processed through Get-ChocolateyVersion function #133

Closed Windos closed 12 months ago

Windos commented 1 year ago

Description Of Changes

This PR ensures that the Get-ChocolateyVersion function only attempts to cast the Chocolatey CLI version number as a version object.

To achieve this the stdout from executing choco --version is matches against the recommended regular expression for checking SemVer strings.

Motivation and Context

When a Chocolatey for Business or Pro license is installed on a system but the licensed extension package is not yet installed, additional information is presented to the user.

This pollutes the stdout stream meaning that it is not possible to directly cast the information on this stream and a version object.

Instead, the stream is matched against a regular expression representing a valid SemVer string, and then the match (if found) is processed.

If for any reason the regular expression does not match, the function will now assert that the task has failed. This should make diagnosing failures easier.

Testing

I have tested this against a Windows Server 2016 VM where I have installed and uninstalled packages with and without a license installed (and the licensed extension missing).

I have repeated these tests on both Chocolatey CLI 1.4.0 and 2.1.0.

Operating Systems Testing

Change Types Made

Change Checklist

Related Issue

Fixes #132