Skip to content

Commit

Permalink
Add test for new configurable patch limit.
Browse files Browse the repository at this point in the history
Also make test for old default match on the actual error message.
  • Loading branch information
ainmosni committed Jan 10, 2023
1 parent 55f6720 commit ef63ad5
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions services/graph/pkg/service/v0/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"

Expand Down Expand Up @@ -284,8 +285,10 @@ var _ = Describe("Groups", func() {
It("fails when the number of users is exceeded - spec says 20 max", func() {
updatedGroup := libregraph.NewGroup()
updatedGroup.SetDisplayName("group1 updated")
updatedGroup.SetMembersodataBind([]string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21"})
updatedGroup.SetMembersodataBind([]string{
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21",
})
updatedGroupJson, err := json.Marshal(updatedGroup)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -295,6 +298,40 @@ var _ = Describe("Groups", func() {
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchGroup(rr, r)

resp, err := ioutil.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())

Expect(string(resp)).To(ContainSubstring("Request is limited to 20"))
Expect(rr.Code).To(Equal(http.StatusBadRequest))
})

It("fails when the number of users is exceeded when configured to 5", func() {
updatedGroup := libregraph.NewGroup()
updatedGroup.SetDisplayName("group1 updated")
updatedGroup.SetMembersodataBind([]string{
"1", "2", "3", "4", "5", "6",
})
updatedGroupJson, err := json.Marshal(updatedGroup)
Expect(err).ToNot(HaveOccurred())

cfg.API.GroupMembersPatchLimit = 5
svc = service.NewService(
service.Config(cfg),
service.WithGatewayClient(gatewayClient),
service.EventsPublisher(&eventsPublisher),
service.WithIdentityBackend(identityBackend),
)

r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/me/groups", bytes.NewBuffer(updatedGroupJson))
rctx := chi.NewRouteContext()
rctx.URLParams.Add("groupID", *newGroup.Id)
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.PatchGroup(rr, r)

resp, err := ioutil.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())

Expect(string(resp)).To(ContainSubstring("Request is limited to 5"))
Expect(rr.Code).To(Equal(http.StatusBadRequest))
})

Expand Down

0 comments on commit ef63ad5

Please sign in to comment.