Check macos version with semver for nudge disabling (#18485)

Fixes a bug where macos versions are incorrectly parsed for nudge
requirements
This commit is contained in:
Dante Catalfamo 2024-04-23 10:09:47 -04:00 committed by GitHub
parent 05357c1691
commit 086e2464c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -2,8 +2,9 @@ package fleet
import (
"fmt"
"strconv"
"strings"
"github.com/Masterminds/semver"
)
// OperatingSystem is an operating system uniquely identified according to its name and version.
@ -32,6 +33,8 @@ func (os OperatingSystem) IsWindows() bool {
return strings.ToLower(os.Platform) == "windows"
}
var macOSNudgeLastVersion = semver.MustParse("14")
// RequiresNudge returns whether the target platform is darwin and
// below version 14. Starting at macOS 14 nudge is no longer required,
// as the mechanism to notify users about updates is built in.
@ -40,12 +43,12 @@ func (os *OperatingSystem) RequiresNudge() (bool, error) {
return false, nil
}
versionFloat, err := strconv.ParseFloat(os.Version, 32)
version, err := semver.NewVersion(os.Version)
if err != nil {
return false, fmt.Errorf("parsing macos version \"%s\": %w", os.Version, err)
}
if float32(versionFloat) < 14 {
if version.LessThan(macOSNudgeLastVersion) {
return true, nil
}

View file

@ -33,10 +33,10 @@ func TestOperatingSystemRequiresNudge(t *testing.T) {
{platform: "chrome", version: "12.1"},
{platform: "chrome", version: "15"},
{platform: "darwin", parseError: true},
{platform: "darwin", version: "12.0", requiresNudge: true},
{platform: "darwin", version: "12.0.9", requiresNudge: true},
{platform: "darwin", version: "11", requiresNudge: true},
{platform: "darwin", version: "14.0"},
{platform: "darwin", version: "14.3"},
{platform: "darwin", version: "14.3.2"},
{platform: "windows"},
{platform: "windows", version: "12.2"},
{platform: "windows", version: "15.4"},