Skip to content

Commit

Permalink
Add validation for non-existing posture checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga committed Jan 9, 2024
1 parent 16c4bf5 commit e138aa2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ components:
min_version:
description: Minimum acceptable NetBird version
type: string
example: "1.2.3"
example: "0.25.0"
required:
- enabled
- min_version
Expand Down
2 changes: 1 addition & 1 deletion management/server/http/posture_checks_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func validatePostureChecksUpdate(req api.PostureCheckUpdate) error {
return status.Errorf(status.InvalidArgument, "posture checks name shouldn't be empty")
}

if req.Checks == nil {
if req.Checks == nil || req.Checks.NbVersionCheck == nil {
return status.Errorf(status.InvalidArgument, "posture checks shouldn't be empty")
}

Expand Down
34 changes: 34 additions & 0 deletions management/server/http/posture_checks_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ func TestPostureCheckUpdate(t *testing.T) {
},
},
},
{
name: "Create Posture Checks Invalid Check",
requestType: http.MethodPost,
requestPath: "/api/posture-checks",
requestBody: bytes.NewBuffer(
[]byte(`{
"name": "default",
"checks": {
"non_existing_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
}`)),
expectedStatus: http.StatusBadRequest,
expectedBody: false,
},
{
name: "Create Posture Checks Invalid Name",
requestType: http.MethodPost,
Expand Down Expand Up @@ -255,6 +272,23 @@ func TestPostureCheckUpdate(t *testing.T) {
},
},
},
{
name: "Update Posture Checks Invalid Check",
requestType: http.MethodPut,
requestPath: "/api/posture-checks/postureCheck",
requestBody: bytes.NewBuffer(
[]byte(`{
"name": "default",
"checks": {
"non_existing_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
}`)),
expectedStatus: http.StatusBadRequest,
expectedBody: false,
},
{
name: "Update Posture Checks Invalid Name",
requestType: http.MethodPut,
Expand Down

0 comments on commit e138aa2

Please sign in to comment.