Tests configs
This commit is contained in:
parent
d0772ee142
commit
1a9653a4db
|
@ -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)
|
||||
|
|
|
@ -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 =>
|
||||
|
|
|
@ -11,59 +11,58 @@ import { events } from "@budibase/backend-core"
|
|||
|
||||
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", () => {
|
||||
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<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 () => {
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue