Tests configs

This commit is contained in:
adrinr 2023-03-27 17:58:32 +01:00
parent d0772ee142
commit 1a9653a4db
4 changed files with 67 additions and 48 deletions

View File

@ -40,6 +40,7 @@ export enum Config {
GOOGLE = "google", GOOGLE = "google",
OIDC = "oidc", OIDC = "oidc",
OIDC_LOGOS = "logos_oidc", OIDC_LOGOS = "logos_oidc",
SCIM = "scim",
} }
export const MIN_VALID_DATE = new Date(-2147483647000) export const MIN_VALID_DATE = new Date(-2147483647000)

View File

@ -108,7 +108,7 @@ export interface OIDCWellKnownConfig {
} }
export interface SCIMConfig extends Config { export interface SCIMConfig extends Config {
enabled: boolean config: { enabled: boolean }
} }
export const isSettingsConfig = (config: Config): config is SettingsConfig => export const isSettingsConfig = (config: Config): config is SettingsConfig =>

View File

@ -11,59 +11,58 @@ import { events } from "@budibase/backend-core"
mocks.licenses.useScimIntegration() mocks.licenses.useScimIntegration()
const unauthorisedTests = (
fn: (
...params: any //settings: RequestSettings
) => Promise<any>
) => {
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", () => { describe("scim", () => {
beforeEach(() => { beforeEach(async () => {
jest.resetAllMocks() jest.resetAllMocks()
tk.freeze(mocks.date.MOCK_DATE) tk.freeze(mocks.date.MOCK_DATE)
mocks.licenses.useScimIntegration() mocks.licenses.useScimIntegration()
await config.setSCIMConfig(true)
}) })
const config = new TestConfiguration() const config = new TestConfiguration()
const unauthorisedTests = (fn: (...params: any) => Promise<any>) => {
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 () => { beforeAll(async () => {
await config.beforeAll() await config.beforeAll()
}) })
@ -73,7 +72,7 @@ describe("scim", () => {
}) })
describe("/api/global/scim/v2/users", () => { 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 const getScimUsers = config.api.scimUsersAPI.get
unauthorisedTests(getScimUsers) unauthorisedTests(getScimUsers)

View File

@ -25,7 +25,13 @@ import {
utils, utils,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import structures, { CSRF_TOKEN } from "./structures" 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" import API from "./api"
class TestConfiguration { class TestConfiguration {
@ -335,6 +341,19 @@ class TestConfiguration {
controllers.config.save 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 export default TestConfiguration