diff --git a/api/base_controller.go b/api/base_controller.go index 50e2f6c8f..8dfe9c4a3 100644 --- a/api/base_controller.go +++ b/api/base_controller.go @@ -20,14 +20,13 @@ import ( "context" "encoding/base64" "fmt" + "github.com/tidwall/sjson" "net/http" "strconv" "time" "github.com/Peripli/service-manager/operations" - "github.com/tidwall/sjson" - "github.com/gofrs/uuid" "github.com/Peripli/service-manager/storage" @@ -498,6 +497,9 @@ func (c *BaseController) PatchObject(r *web.Request) (*web.Response, error) { createdAt := objFromDB.GetCreatedAt() updatedAt := objFromDB.GetUpdatedAt() + labels, _, _ := query.ApplyLabelChangesToLabels(labelChanges, objFromDB.GetLabels()) + objFromDB.SetLabels(labels) + if err := util.BytesToObject(r.Body, objFromDB); err != nil { return nil, err } @@ -507,9 +509,6 @@ func (c *BaseController) PatchObject(r *web.Request) (*web.Response, error) { objFromDB.SetUpdatedAt(updatedAt) objFromDB.SetReady(true) - labels, _, _ := query.ApplyLabelChangesToLabels(labelChanges, objFromDB.GetLabels()) - objFromDB.SetLabels(labels) - action := func(ctx context.Context, repository storage.Repository) (types.Object, error) { object, err := repository.Update(ctx, objFromDB, labelChanges, criteria...) return object, util.HandleStorageError(err, c.objectType.String()) diff --git a/test/service_instance_and_binding_test/service_instance_test/service_instance_test.go b/test/service_instance_and_binding_test/service_instance_test/service_instance_test.go index 7c38ab5b8..3e6eeb097 100644 --- a/test/service_instance_and_binding_test/service_instance_test/service_instance_test.go +++ b/test/service_instance_and_binding_test/service_instance_test/service_instance_test.go @@ -2092,6 +2092,27 @@ var _ = DescribeTestsFor(TestCase{ Expect(method).To(Not(Equal("PATCH"))) }) }) + When("invalid label key", func() { + It("returns error", func() { + labels := []*types.LabelChange{ + { + Operation: types.AddLabelOperation, + Key: "label Key1", + Values: []string{"labelValue1"}, + }, + } + patchLabelsBody = make(map[string]interface{}) + patchLabelsBody["labels"] = labels + testCtx.SMWithOAuthForTenant.PATCH(web.ServiceInstancesURL+"/"+SID). + WithQuery("async", "false"). + WithJSON(patchLabelsBody).Expect().Status(http.StatusBadRequest) + + testCtx.SMWithOAuthForTenant.PATCH(web.ServiceInstancesURL+"/"+SID). + WithQuery("async", "false"). + WithJSON(patchLabelsBody).Expect().Status(http.StatusBadRequest) + + }) + }) When("name and label is provided in request body", func() { It("returns 404", func() { patchLabelsBody["name"] = "name"