diff --git a/api/handlers/service_instance_test.go b/api/handlers/service_instance_test.go index 840e2e505..e88e9a9bc 100644 --- a/api/handlers/service_instance_test.go +++ b/api/handlers/service_instance_test.go @@ -169,7 +169,7 @@ var _ = Describe("ServiceInstance", func() { _, actualAuthInfo, actualListMessage := serviceInstanceRepo.ListServiceInstancesArgsForCall(0) Expect(actualAuthInfo).To(Equal(authInfo)) Expect(actualListMessage.Names).To(BeEmpty()) - Expect(actualListMessage.SpaceGuids).To(BeEmpty()) + Expect(actualListMessage.SpaceGUIDs).To(BeEmpty()) Expect(rr).Should(HaveHTTPStatus(http.StatusOK)) Expect(rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json")) @@ -186,7 +186,8 @@ var _ = Describe("ServiceInstance", func() { BeforeEach(func() { requestValidator.DecodeAndValidateURLValuesStub = decodeAndValidateURLValuesStub(&payloads.ServiceInstanceList{ Names: "sc1,sc2", - SpaceGuids: "space1,space2", + SpaceGUIDs: "space1,space2", + GUIDs: "g1,g2", }) }) @@ -195,7 +196,8 @@ var _ = Describe("ServiceInstance", func() { _, _, message := serviceInstanceRepo.ListServiceInstancesArgsForCall(0) Expect(message.Names).To(ConsistOf("sc1", "sc2")) - Expect(message.SpaceGuids).To(ConsistOf("space1", "space2")) + Expect(message.SpaceGUIDs).To(ConsistOf("space1", "space2")) + Expect(message.GUIDs).To(ConsistOf("g1", "g2")) }) It("correctly sets query parameters in response pagination links", func() { diff --git a/api/payloads/service_instance.go b/api/payloads/service_instance.go index 7eddeff4a..edb671945 100644 --- a/api/payloads/service_instance.go +++ b/api/payloads/service_instance.go @@ -130,7 +130,8 @@ func (p *ServiceInstancePatch) UnmarshalJSON(data []byte) error { type ServiceInstanceList struct { Names string - SpaceGuids string + GUIDs string + SpaceGUIDs string OrderBy string } @@ -143,12 +144,13 @@ func (l ServiceInstanceList) Validate() error { func (l *ServiceInstanceList) ToMessage() repositories.ListServiceInstanceMessage { return repositories.ListServiceInstanceMessage{ Names: parse.ArrayParam(l.Names), - SpaceGuids: parse.ArrayParam(l.SpaceGuids), + SpaceGUIDs: parse.ArrayParam(l.SpaceGUIDs), + GUIDs: parse.ArrayParam(l.GUIDs), } } func (l *ServiceInstanceList) SupportedKeys() []string { - return []string{"names", "space_guids", "order_by", "per_page", "page"} + return []string{"names", "space_guids", "guids", "order_by", "per_page", "page"} } func (l *ServiceInstanceList) IgnoredKeys() []*regexp.Regexp { @@ -157,7 +159,8 @@ func (l *ServiceInstanceList) IgnoredKeys() []*regexp.Regexp { func (l *ServiceInstanceList) DecodeFromURLValues(values url.Values) error { l.Names = values.Get("names") - l.SpaceGuids = values.Get("space_guids") + l.SpaceGUIDs = values.Get("space_guids") + l.GUIDs = values.Get("guids") l.OrderBy = values.Get("order_by") return nil } diff --git a/api/payloads/service_instance_test.go b/api/payloads/service_instance_test.go index 01a8ed696..7d38f2989 100644 --- a/api/payloads/service_instance_test.go +++ b/api/payloads/service_instance_test.go @@ -20,7 +20,8 @@ var _ = Describe("ServiceInstanceList", func() { Expect(*actualServiceInstanceList).To(Equal(expectedServiceInstanceList)) }, Entry("names", "names=name", payloads.ServiceInstanceList{Names: "name"}), - Entry("space_guids", "space_guids=space_guid", payloads.ServiceInstanceList{SpaceGuids: "space_guid"}), + Entry("space_guids", "space_guids=space_guid", payloads.ServiceInstanceList{SpaceGUIDs: "space_guid"}), + Entry("guids", "guids=guid", payloads.ServiceInstanceList{GUIDs: "guid"}), Entry("created_at", "order_by=created_at", payloads.ServiceInstanceList{OrderBy: "created_at"}), Entry("-created_at", "order_by=-created_at", payloads.ServiceInstanceList{OrderBy: "-created_at"}), Entry("updated_at", "order_by=updated_at", payloads.ServiceInstanceList{OrderBy: "updated_at"}), diff --git a/api/repositories/service_instance_repository.go b/api/repositories/service_instance_repository.go index e3b373321..14c1b62cd 100644 --- a/api/repositories/service_instance_repository.go +++ b/api/repositories/service_instance_repository.go @@ -77,7 +77,8 @@ func (p PatchServiceInstanceMessage) Apply(cfServiceInstance *korifiv1alpha1.CFS type ListServiceInstanceMessage struct { Names []string - SpaceGuids []string + SpaceGUIDs []string + GUIDs []string } type DeleteServiceInstanceMessage struct { @@ -198,9 +199,10 @@ func (r *ServiceInstanceRepo) ListServiceInstances(ctx context.Context, authInfo preds := []func(korifiv1alpha1.CFServiceInstance) bool{ SetPredicate(message.Names, func(s korifiv1alpha1.CFServiceInstance) string { return s.Spec.DisplayName }), + SetPredicate(message.GUIDs, func(s korifiv1alpha1.CFServiceInstance) string { return s.Name }), } - spaceGUIDSet := NewSet(message.SpaceGuids...) + spaceGUIDSet := NewSet(message.SpaceGUIDs...) var filteredServiceInstances []korifiv1alpha1.CFServiceInstance for ns := range nsList { if len(spaceGUIDSet) > 0 && !spaceGUIDSet.Includes(ns) { diff --git a/api/repositories/service_instance_repository_test.go b/api/repositories/service_instance_repository_test.go index 18c15432b..2846d49f8 100644 --- a/api/repositories/service_instance_repository_test.go +++ b/api/repositories/service_instance_repository_test.go @@ -434,7 +434,7 @@ var _ = Describe("ServiceInstanceRepository", func() { When("the spaceGUID filter is set", func() { BeforeEach(func() { filters = repositories.ListServiceInstanceMessage{ - SpaceGuids: []string{ + SpaceGUIDs: []string{ cfServiceInstance2.Namespace, cfServiceInstance3.Namespace, }, @@ -447,6 +447,20 @@ var _ = Describe("ServiceInstanceRepository", func() { )) }) }) + + When("the serviceGUID filter is set", func() { + BeforeEach(func() { + filters = repositories.ListServiceInstanceMessage{ + GUIDs: []string{cfServiceInstance1.Name, cfServiceInstance3.Name}, + } + }) + It("returns only records for the ServiceInstances within the matching spaces", func() { + Expect(serviceInstanceList).To(ConsistOf( + MatchFields(IgnoreExtras, Fields{"GUID": Equal(cfServiceInstance1.Name)}), + MatchFields(IgnoreExtras, Fields{"GUID": Equal(cfServiceInstance3.Name)}), + )) + }) + }) }) }) diff --git a/tests/e2e/service_instances_test.go b/tests/e2e/service_instances_test.go index 555215ed8..7d571fedd 100644 --- a/tests/e2e/service_instances_test.go +++ b/tests/e2e/service_instances_test.go @@ -154,12 +154,9 @@ var _ = Describe("Service Instances", func() { createSpaceRole("space_developer", certUserName, spaceGUID) }) - It("succeeds", func() { + It("deletes the service instance", func() { Expect(httpError).NotTo(HaveOccurred()) Expect(httpResp).To(HaveRestyStatusCode(http.StatusNoContent)) - }) - - It("deletes the service instance", func() { Expect(listServiceInstances().Resources).NotTo(ContainElement( MatchFields(IgnoreExtras, Fields{ "Name": Equal(existingInstanceName), @@ -180,4 +177,55 @@ var _ = Describe("Service Instances", func() { }) }) }) + + Describe("List", func() { + var ( + anotherSpaceGUID string + anotherInstanceGUID string + serviceInstancesList resourceList[resource] + ) + + BeforeEach(func() { + anotherSpaceGUID = createSpace(generateGUID("space1"), commonTestOrgGUID) + anotherInstanceGUID = createServiceInstance(anotherSpaceGUID, generateGUID("service-instance"), nil) + }) + + JustBeforeEach(func() { + serviceInstancesList = resourceList[resource]{} + httpResp, httpError = certClient.R().SetResult(&serviceInstancesList).Get("/v3/service_instances") + }) + + It("does not return service instances in spaces the user is not permitted", func() { + Expect(httpError).NotTo(HaveOccurred()) + Expect(httpResp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(serviceInstancesList.Resources).NotTo(ContainElements( + MatchFields(IgnoreExtras, Fields{ + "GUID": Equal(existingInstanceGUID), + }), + MatchFields(IgnoreExtras, Fields{ + "GUID": Equal(anotherInstanceGUID), + }), + )) + }) + + When("the user has permissions to list service instances", func() { + BeforeEach(func() { + createSpaceRole("space_developer", certUserName, spaceGUID) + createSpaceRole("space_developer", certUserName, anotherSpaceGUID) + }) + + It("lists the service instances", func() { + Expect(httpError).NotTo(HaveOccurred()) + Expect(httpResp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(serviceInstancesList.Resources).To(ContainElements( + MatchFields(IgnoreExtras, Fields{ + "GUID": Equal(existingInstanceGUID), + }), + MatchFields(IgnoreExtras, Fields{ + "GUID": Equal(anotherInstanceGUID), + }), + )) + }) + }) + }) })