Skip to content

Commit

Permalink
Extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surik committed Jan 19, 2024
1 parent 865a028 commit ae6ea73
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions management/server/posture/os_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
38 changes: 30 additions & 8 deletions management/server/posture/os_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
}
Expand Down

0 comments on commit ae6ea73

Please sign in to comment.