diff --git a/management/server/posture/os_version.go b/management/server/posture/os_version.go index 9aebeccfdaf..338723aec76 100644 --- a/management/server/posture/os_version.go +++ b/management/server/posture/os_version.go @@ -48,7 +48,7 @@ func (c *OSVersionCheck) Name() string { func checkMinVersion(peerGoOS, peerVersion string, check *MinVersionCheck) error { if check == nil { - return nil + return fmt.Errorf("peer %s OS is not allowed", peerGoOS) } peerNBVersion, err := version.NewVersion(peerVersion) @@ -70,7 +70,7 @@ func checkMinVersion(peerGoOS, peerVersion string, check *MinVersionCheck) error func checkMinKernelVersion(peerGoOS, peerVersion string, check *MinKernelVersionCheck) error { if check == nil { - return nil + return fmt.Errorf("peer %s OS is not allowed", peerGoOS) } peerNBVersion, err := version.NewVersion(peerVersion) diff --git a/management/server/posture/os_version_test.go b/management/server/posture/os_version_test.go index 045ab21fbd8..73f642c3ea3 100644 --- a/management/server/posture/os_version_test.go +++ b/management/server/posture/os_version_test.go @@ -31,7 +31,7 @@ func TestOSVersionCheck_Check(t *testing.T) { wantErr: false, }, { - name: "Valid Peer macOS version", + name: "Not valid Peer macOS version", input: peer.Peer{ Meta: peer.PeerSystemMeta{ GoOS: "darwin", @@ -40,24 +40,46 @@ func TestOSVersionCheck_Check(t *testing.T) { }, check: OSVersionCheck{ Darwin: &MinVersionCheck{ - MinVersion: "13", + MinVersion: "15", }, }, - wantErr: false, + wantErr: true, }, { - name: "No valid Peer macOS version", + name: "Valid Peer ios version allowed by any rule", input: peer.Peer{ Meta: peer.PeerSystemMeta{ - GoOS: "darwin", - Core: "14.2.1", + GoOS: "ios", + Core: "17.0.1", }, }, check: OSVersionCheck{ - Darwin: &MinVersionCheck{ - MinVersion: "15", + Ios: &MinVersionCheck{ + MinVersion: "0", + }, + }, + wantErr: false, + }, + { + name: "Valid Peer android version not allowed by rule", + input: peer.Peer{ + Meta: peer.PeerSystemMeta{ + GoOS: "android", + Core: "14", + }, + }, + check: OSVersionCheck{}, + wantErr: true, + }, + { + name: "Valid Peer Linux Kernel version not allowed by rule", + input: peer.Peer{ + Meta: peer.PeerSystemMeta{ + GoOS: "linux", + KernelVersion: "6.1.1", }, }, + check: OSVersionCheck{}, wantErr: true, }, }