From d452f5cf0d3d050658a4b50c01daa5aaa68a58e5 Mon Sep 17 00:00:00 2001 From: adrinr Date: Thu, 16 Mar 2023 15:04:10 +0100 Subject: [PATCH] Handle string boolean requests --- .../types/src/api/web/global/scim/users.ts | 6 ++++-- .../api/routes/global/tests/scim/users.spec.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/types/src/api/web/global/scim/users.ts b/packages/types/src/api/web/global/scim/users.ts index 8748b4e8e6..72b7078bb4 100644 --- a/packages/types/src/api/web/global/scim/users.ts +++ b/packages/types/src/api/web/global/scim/users.ts @@ -1,5 +1,7 @@ import { ScimResource, ScimMeta, ScimPatchOperation } from "scim-patch" +type BooleanString = boolean | "True" | "False" + export interface ScimUserResponse extends ScimResource { schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"] id: string @@ -13,7 +15,7 @@ export interface ScimUserResponse extends ScimResource { familyName: string givenName: string } - active: boolean + active: BooleanString emails: [ { value: string @@ -30,7 +32,7 @@ export interface ScimCreateUserRequest { ] externalId: string userName: string - active: boolean + active: BooleanString emails: [ { primary: true diff --git a/packages/worker/src/api/routes/global/tests/scim/users.spec.ts b/packages/worker/src/api/routes/global/tests/scim/users.spec.ts index eff82ab766..d0c15ca532 100644 --- a/packages/worker/src/api/routes/global/tests/scim/users.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim/users.spec.ts @@ -395,6 +395,24 @@ describe("/api/global/scim/v2/users", () => { const persistedUser = await config.api.scimUsersAPI.find(user.id) expect(persistedUser).toEqual(expectedScimUser) }) + + it("can deactive an active user", async () => { + const body: ScimUpdateRequest = { + schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], + Operations: [{ op: "Replace", path: "active", value: "False" }], + } + + const response = await patchScimUser({ id: user.id, body }) + + const expectedScimUser: ScimUserResponse = { + ...user, + active: false, + } + expect(response).toEqual(expectedScimUser) + + const persistedUser = await config.api.scimUsersAPI.find(user.id) + expect(persistedUser).toEqual(expectedScimUser) + }) }) describe("DELETE /api/global/scim/v2/users/:id", () => {