diff --git a/packages/backend-core/src/constants/misc.ts b/packages/backend-core/src/constants/misc.ts index a4a1806618..e7fa4ea472 100644 --- a/packages/backend-core/src/constants/misc.ts +++ b/packages/backend-core/src/constants/misc.ts @@ -40,6 +40,7 @@ export enum Config { GOOGLE = "google", OIDC = "oidc", OIDC_LOGOS = "logos_oidc", + SCIM = "scim", } export const MIN_VALID_DATE = new Date(-2147483647000) diff --git a/packages/types/src/documents/global/config.ts b/packages/types/src/documents/global/config.ts index 68ea18ccc2..751006f01c 100644 --- a/packages/types/src/documents/global/config.ts +++ b/packages/types/src/documents/global/config.ts @@ -108,7 +108,7 @@ export interface OIDCWellKnownConfig { } export interface SCIMConfig extends Config { - enabled: boolean + config: { enabled: boolean } } export const isSettingsConfig = (config: Config): config is SettingsConfig => 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 325ab0331d..ba176f5e3f 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -11,59 +11,58 @@ import { events } from "@budibase/backend-core" mocks.licenses.useScimIntegration() -const unauthorisedTests = ( - fn: ( - ...params: any //settings: RequestSettings - ) => Promise -) => { - describe("unauthorised calls", () => { - it("unauthorised calls are not allowed", async () => { - const response = await fn(...Array(fn.length - 1).fill({}), { - setHeaders: false, - expect: 403, - }) - - expect(response).toEqual({ message: "Tenant id not set", status: 403 }) - }) - - it("cannot be called when feature is disabled", async () => { - mocks.licenses.useCloudFree() - const response = await fn(...Array(fn.length - 1).fill({}), { - expect: 400, - }) - - expect(response).toEqual({ - error: { - code: "feature_disabled", - featureName: "scim", - }, - message: "scim is not currently enabled", - 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, - }) - }) - }) -} - describe("scim", () => { - beforeEach(() => { + beforeEach(async () => { jest.resetAllMocks() tk.freeze(mocks.date.MOCK_DATE) mocks.licenses.useScimIntegration() + + await config.setSCIMConfig(true) }) const config = new TestConfiguration() + const unauthorisedTests = (fn: (...params: any) => Promise) => { + describe("unauthorised calls", () => { + it("unauthorised calls are not allowed", async () => { + const response = await fn(...Array(fn.length - 1).fill({}), { + setHeaders: false, + expect: 403, + }) + + expect(response).toEqual({ message: "Tenant id not set", status: 403 }) + }) + + it("cannot be called when feature is disabled", async () => { + mocks.licenses.useCloudFree() + const response = await fn(...Array(fn.length - 1).fill({}), { + expect: 400, + }) + + expect(response).toEqual({ + error: { + code: "feature_disabled", + featureName: "scim", + }, + message: "scim is not currently enabled", + status: 400, + }) + }) + + it("cannot be called when feature is enabled but the config disabled", async () => { + await config.setSCIMConfig(false) + const response = await fn(...Array(fn.length - 1).fill({}), { + expect: 400, + }) + + expect(response).toEqual({ + message: "SCIM is not enabled", + status: 400, + }) + }) + }) + } + beforeAll(async () => { await config.beforeAll() }) @@ -73,7 +72,7 @@ describe("scim", () => { }) describe("/api/global/scim/v2/users", () => { - describe.only("GET /api/global/scim/v2/users", () => { + describe("GET /api/global/scim/v2/users", () => { const getScimUsers = config.api.scimUsersAPI.get unauthorisedTests(getScimUsers) diff --git a/packages/worker/src/tests/TestConfiguration.ts b/packages/worker/src/tests/TestConfiguration.ts index 5e606143f2..a79ac0e189 100644 --- a/packages/worker/src/tests/TestConfiguration.ts +++ b/packages/worker/src/tests/TestConfiguration.ts @@ -25,7 +25,13 @@ import { utils, } from "@budibase/backend-core" import structures, { CSRF_TOKEN } from "./structures" -import { SaveUserResponse, User, AuthToken } from "@budibase/types" +import { + SaveUserResponse, + User, + AuthToken, + SCIMConfig, + ConfigType, +} from "@budibase/types" import API from "./api" class TestConfiguration { @@ -335,6 +341,19 @@ class TestConfiguration { controllers.config.save ) } + + // CONFIGS - SCIM + + async setSCIMConfig(enabled: boolean) { + await this.deleteConfig(Config.SCIM) + const config: SCIMConfig = { + type: ConfigType.SCIM, + config: { enabled }, + } + + await this._req(config, null, controllers.config.save) + return config + } } export default TestConfiguration