From 1301b23f028d7564c8e0f88885d18a47c12feb05 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 14 Apr 2023 14:36:06 +0100 Subject: [PATCH 1/4] Add group filter fetch --- .../src/api/routes/global/tests/scim.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index 3352951152..77e9cbea26 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -585,6 +585,21 @@ describe("scim", () => { totalResults: groupCount, }) }) + + it("can fetch groups using displayName filters", async () => { + const groupToFetch = _.sample(groups) + const response = await getScimGroups({ + params: { filter: `displayName eq "${groupToFetch!.displayName}"` }, + }) + + expect(response).toEqual({ + Resources: [groupToFetch], + itemsPerPage: 1, + schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], + startIndex: 1, + totalResults: 1, + }) + }) }) }) From ce2a610c00b112886a45e412e6850f21b7ee14d5 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 14 Apr 2023 14:48:48 +0100 Subject: [PATCH 2/4] Test exclude members --- .../src/api/routes/global/tests/scim.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index 77e9cbea26..91675a12b8 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -600,6 +600,25 @@ describe("scim", () => { totalResults: 1, }) }) + + it("can fetch groups excluding members", async () => { + const response = await getScimGroups({ + params: { excludedAttributes: "members" }, + }) + + expect(response).toEqual({ + Resources: expect.arrayContaining( + groups.map(g => { + const { members, ...groupData } = g + return groupData + }) + ), + itemsPerPage: 25, + schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], + startIndex: 1, + totalResults: groupCount, + }) + }) }) }) From f3e62958927791c92cc1d8cf9e584787fc346007 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 14 Apr 2023 14:50:44 +0100 Subject: [PATCH 3/4] Add tests --- .../src/api/routes/global/tests/scim.spec.ts | 19 +++++++++++++++++++ packages/worker/src/tests/api/scim/groups.ts | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index 91675a12b8..4381d86c7f 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -619,6 +619,25 @@ describe("scim", () => { totalResults: groupCount, }) }) + + it("can fetch groups excluding multiple fields", async () => { + const response = await getScimGroups({ + params: { excludedAttributes: "members,displayName" }, + }) + + expect(response).toEqual({ + Resources: expect.arrayContaining( + groups.map(g => { + const { members, displayName, ...groupData } = g + return groupData + }) + ), + itemsPerPage: 25, + schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], + startIndex: 1, + totalResults: groupCount, + }) + }) }) }) diff --git a/packages/worker/src/tests/api/scim/groups.ts b/packages/worker/src/tests/api/scim/groups.ts index 96ff9aeb67..c494036530 100644 --- a/packages/worker/src/tests/api/scim/groups.ts +++ b/packages/worker/src/tests/api/scim/groups.ts @@ -18,6 +18,7 @@ export class ScimGroupsAPI extends ScimTestAPI { startIndex?: number pageSize?: number filter?: string + excludedAttributes?: string } } ) => { @@ -32,6 +33,9 @@ export class ScimGroupsAPI extends ScimTestAPI { if (params?.filter) { url += `filter=${params.filter}&` } + if (params?.excludedAttributes) { + url += `excludedAttributes=${params.excludedAttributes}&` + } const res = await this.call(url, "get", requestSettings) return res.body as ScimGroupListResponse } From c83cf33707f9df318c6def4c7dc73f4b3c76a73a Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 14 Apr 2023 15:14:41 +0100 Subject: [PATCH 4/4] Test get group without members --- .../worker/src/api/routes/global/tests/scim.spec.ts | 10 ++++++++++ packages/worker/src/tests/api/scim/groups.ts | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index 4381d86c7f..db47493685 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -715,6 +715,16 @@ describe("scim", () => { status: 404, }) }) + + it("should allow excluding members", async () => { + const response = await findScimGroup(group.id, { + qs: "excludedAttributes=members", + }) + + const { members, ...expectedResponse } = group + + expect(response).toEqual(expectedResponse) + }) }) describe("DELETE /api/global/scim/v2/groups/:id", () => { diff --git a/packages/worker/src/tests/api/scim/groups.ts b/packages/worker/src/tests/api/scim/groups.ts index c494036530..d2df007614 100644 --- a/packages/worker/src/tests/api/scim/groups.ts +++ b/packages/worker/src/tests/api/scim/groups.ts @@ -58,9 +58,12 @@ export class ScimGroupsAPI extends ScimTestAPI { return res.body as ScimGroupResponse } - find = async (id: string, requestSettings?: Partial) => { + find = async ( + id: string, + requestSettings?: Partial & { qs?: string } + ) => { const res = await this.call( - `/api/global/scim/v2/groups/${id}`, + `/api/global/scim/v2/groups/${id}?${requestSettings?.qs}`, "get", requestSettings )