diff --git a/controller/northbound/server/auth_test.go b/controller/northbound/server/auth_test.go index e5c9e7389d443c0f653f53a3c5f32966f5c2671d..956ef2be19b5da9be5eebe2636763bb7c91fe7b5 100644 --- a/controller/northbound/server/auth_test.go +++ b/controller/northbound/server/auth_test.go @@ -89,7 +89,13 @@ func TestAuth_Login(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("username"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("username"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }}, @@ -160,7 +166,13 @@ func TestAuth_Logout(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("username"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("username"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }}, diff --git a/controller/northbound/server/role_test.go b/controller/northbound/server/role_test.go index bb787a4160530b0454d4b2c0198f47c0f9a98ffc..2d75e067843f15c594d6d34e2b0a503d058c8582 100644 --- a/controller/northbound/server/role_test.go +++ b/controller/northbound/server/role_test.go @@ -84,10 +84,20 @@ func TestRole_CreateRoles(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("roles[0].name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("roles"), + }, + { + FieldName: stringToPointer("name"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 3 characters"), - }}, + }, + }, }, { name: "role with too short description should fail", @@ -105,7 +115,16 @@ func TestRole_CreateRoles(t *testing.T) { want: &apb.CreateRolesResponse{}, wantErr: true, validationErrors: []*validate.Violation{{ - FieldPath: stringToPointer("roles[0].description"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("roles"), + }, + { + FieldName: stringToPointer("description"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 3 characters"), }}, @@ -181,7 +200,13 @@ func TestRole_GetRole(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("role_name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("role_name"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, @@ -355,7 +380,16 @@ func TestRole_UpdateRoles(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("roles[0].name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("roles"), + }, + { + FieldName: stringToPointer("name"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 3 characters"), }, @@ -379,7 +413,16 @@ func TestRole_UpdateRoles(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("roles[0].description"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("roles"), + }, + { + FieldName: stringToPointer("description"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 3 characters"), }, @@ -456,12 +499,24 @@ func TestRole_DeletePermissionsForRole(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("role_name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("role_name"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, { - FieldPath: stringToPointer("permissions_to_delete"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("permissions_to_delete"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, diff --git a/controller/northbound/server/topology_test.go b/controller/northbound/server/topology_test.go index 44ce77b57b19c31d5cc6292e5af5c2ac265e3a42..dea560a452ff02ff710d6ca71fcc251d8f57472d 100644 --- a/controller/northbound/server/topology_test.go +++ b/controller/northbound/server/topology_test.go @@ -285,27 +285,72 @@ func TestTopology_AddLink(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("link.name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("link"), + }, + { + FieldName: stringToPointer("name"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 1 characters"), }, { - FieldPath: stringToPointer("link.sourceNode"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("link"), + }, + { + FieldName: stringToPointer("sourceNode"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, { - FieldPath: stringToPointer("link.targetNode"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("link"), + }, + { + FieldName: stringToPointer("targetNode"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, { - FieldPath: stringToPointer("link.sourcePort"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("link"), + }, + { + FieldName: stringToPointer("sourcePort"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, { - FieldPath: stringToPointer("link.targetPort"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("link"), + }, + { + FieldName: stringToPointer("targetPort"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }, @@ -461,7 +506,13 @@ func TestTopology_DeleteLink(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("id"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("id"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }}, diff --git a/controller/northbound/server/user_test.go b/controller/northbound/server/user_test.go index 4a1c663279ce5607a40ff3dd1fd8d87f03d7e0bf..9fcdf4d610cb5685e69e231bd2d65cde95a7e9e8 100644 --- a/controller/northbound/server/user_test.go +++ b/controller/northbound/server/user_test.go @@ -90,7 +90,16 @@ func TestUser_CreateUsers(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("user[0].password"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("user"), + }, + { + FieldName: stringToPointer("password"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 5 characters"), }}, @@ -116,7 +125,16 @@ func TestUser_CreateUsers(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("user[0].name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("user"), + }, + { + FieldName: stringToPointer("name"), + }, + }, + }, ConstraintId: stringToPointer("string.min_len"), Message: stringToPointer("value length must be at least 3 characters"), }}, @@ -190,7 +208,13 @@ func TestUser_GetUser(t *testing.T) { wantErr: true, validationErrors: []*validate.Violation{ { - FieldPath: stringToPointer("name"), + Field: &validate.FieldPath{ + Elements: []*validate.FieldPathElement{ + { + FieldName: stringToPointer("name"), + }, + }, + }, ConstraintId: stringToPointer("required"), Message: stringToPointer("value is required"), }}, diff --git a/controller/northbound/server/utils_test.go b/controller/northbound/server/utils_test.go index 7a4636caabf0f8d66d6e36383e59026d2f376315..dd95d8f2e8c56ba51bf01ade6d6cf5efa0831758 100644 --- a/controller/northbound/server/utils_test.go +++ b/controller/northbound/server/utils_test.go @@ -23,7 +23,8 @@ func isEqualFieldPaths(violationFieldPath, errFieldPath *validate.FieldPath) boo } for i, elem := range violationFieldPath.GetElements() { - if elem != errFieldPath.GetElements()[i] { + errElem := errFieldPath.GetElements()[i] + if *elem.FieldName != *errElem.FieldName { return false } } diff --git a/go.mod b/go.mod index 084198b91a4d594ae15e28eebcfeffb9cdf490b4..9cbe7dabc8903475feba078a53d4886b7aaeff4b 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,7 @@ require ( require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.2-20241127180247-a33202765966.1 - github.com/bufbuild/protovalidate-go v0.7.3 + github.com/bufbuild/protovalidate-go v0.8.2 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-plugin v1.4.10 github.com/lesismal/nbio v1.5.12 @@ -103,7 +103,7 @@ require ( github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/containerd/console v1.0.3 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/google/cel-go v0.22.0 // indirect + github.com/google/cel-go v0.22.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect diff --git a/go.sum b/go.sum index e9fb90e3666fef3277a55b89ee26739771095844..7a355f78a53267ab2ce0c2bcd385f0a1c76b71f5 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/bufbuild/protovalidate-go v0.7.2 h1:UuvKyZHl5p7u3ztEjtRtqtDxOjRKX5VUO github.com/bufbuild/protovalidate-go v0.7.2/go.mod h1:PHV5pFuWlRzdDW02/cmVyNzdiQ+RNNwo7idGxdzS7o4= github.com/bufbuild/protovalidate-go v0.7.3 h1:kKnoSueygR3xxppvuBpm9SEwIsP359MMRfMBGmRByPg= github.com/bufbuild/protovalidate-go v0.7.3/go.mod h1:CFv34wMqiBzAHdQ4q/tWYi9ILFYKuaC3/4zh6eqdUck= +github.com/bufbuild/protovalidate-go v0.8.2 h1:sgzXHkHYP6HnAsL2Rd3I1JxkYUyEQUv9awU1PduMxbM= +github.com/bufbuild/protovalidate-go v0.8.2/go.mod h1:K6w8iPNAXBoIivVueSELbUeUl+MmeTQfCDSug85pn3M= github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -156,6 +158,8 @@ github.com/google/cel-go v0.21.0 h1:cl6uW/gxN+Hy50tNYvI691+sXxioCnstFzLp2WO4GCI= github.com/google/cel-go v0.21.0/go.mod h1:rHUlWCcBKgyEk+eV03RPdZUekPp6YcJwV0FxuUksYxc= github.com/google/cel-go v0.22.0 h1:b3FJZxpiv1vTMo2/5RDUqAHPxkT8mmMfJIrq1llbf7g= github.com/google/cel-go v0.22.0/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8= +github.com/google/cel-go v0.22.1 h1:AfVXx3chM2qwoSbM7Da8g8hX8OVSkBFwX+rz2+PcK40= +github.com/google/cel-go v0.22.1/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=