From d0772ee142ac12f5b1ace0092a83cf494b03babb Mon Sep 17 00:00:00 2001 From: adrinr Date: Mon, 27 Mar 2023 17:52:20 +0100 Subject: [PATCH] Test when scim is disabled --- packages/backend-core/src/configs/configs.ts | 5 +++++ packages/types/src/documents/global/config.ts | 7 +++++++ .../worker/src/api/routes/global/tests/scim.spec.ts | 13 ++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/backend-core/src/configs/configs.ts b/packages/backend-core/src/configs/configs.ts index b461497747..d38f02a10e 100644 --- a/packages/backend-core/src/configs/configs.ts +++ b/packages/backend-core/src/configs/configs.ts @@ -5,6 +5,7 @@ import { GoogleInnerConfig, OIDCConfig, OIDCInnerConfig, + SCIMConfig, SettingsConfig, SettingsInnerConfig, SMTPConfig, @@ -242,3 +243,7 @@ export async function getSMTPConfig( } } } + +export async function getSCIMConfig(): Promise { + return getConfig(ConfigType.SCIM) +} diff --git a/packages/types/src/documents/global/config.ts b/packages/types/src/documents/global/config.ts index b2da6278c7..68ea18ccc2 100644 --- a/packages/types/src/documents/global/config.ts +++ b/packages/types/src/documents/global/config.ts @@ -107,6 +107,10 @@ export interface OIDCWellKnownConfig { userinfo_endpoint: string } +export interface SCIMConfig extends Config { + enabled: boolean +} + export const isSettingsConfig = (config: Config): config is SettingsConfig => config.type === ConfigType.SETTINGS @@ -119,6 +123,9 @@ export const isGoogleConfig = (config: Config): config is GoogleConfig => export const isOIDCConfig = (config: Config): config is OIDCConfig => config.type === ConfigType.OIDC +export const isSCIMConfig = (config: Config): config is SCIMConfig => + config.type === ConfigType.SCIM + export enum ConfigType { SETTINGS = "settings", ACCOUNT = "account", 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 1f50e28430..325ab0331d 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -41,6 +41,17 @@ const unauthorisedTests = ( status: 400, }) }) + + it("cannot be called when feature is enabled but the config disabled", async () => { + const response = await fn(...Array(fn.length - 1).fill({}), { + expect: 400, + }) + + expect(response).toEqual({ + message: "SCIM is not enabled", + status: 400, + }) + }) }) } @@ -62,7 +73,7 @@ describe("scim", () => { }) describe("/api/global/scim/v2/users", () => { - describe("GET /api/global/scim/v2/users", () => { + describe.only("GET /api/global/scim/v2/users", () => { const getScimUsers = config.api.scimUsersAPI.get unauthorisedTests(getScimUsers)