mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
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:
parent
05357c1691
commit
086e2464c2
2 changed files with 8 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
|
|
|
|||
Loading…
Reference in a new issue