diff --git a/packages/backend-core/tests/utilities/structures/index.ts b/packages/backend-core/tests/utilities/structures/index.ts index ca77f476d0..c6e3195ebf 100644 --- a/packages/backend-core/tests/utilities/structures/index.ts +++ b/packages/backend-core/tests/utilities/structures/index.ts @@ -9,3 +9,4 @@ export * as sso from "./sso" export * as tenant from "./tenants" export * as users from "./users" export { generator } from "./generator" +export * as scim from "./scim" diff --git a/packages/backend-core/tests/utilities/structures/scim.ts b/packages/backend-core/tests/utilities/structures/scim.ts new file mode 100644 index 0000000000..2c9ad6c622 --- /dev/null +++ b/packages/backend-core/tests/utilities/structures/scim.ts @@ -0,0 +1,67 @@ +import { ScimCreateGroupRequest, ScimCreateUserRequest } from "@budibase/types" +import { uuid } from "./common" +import { generator } from "./generator" + +export function createUserRequest(userData?: { + externalId?: string + email?: string + firstName?: string + lastName?: string + username?: string +}) { + const { + externalId = uuid(), + email = generator.email(), + firstName = generator.first(), + lastName = generator.last(), + username = generator.name(), + } = userData || {} + + const user: ScimCreateUserRequest = { + schemas: [ + "urn:ietf:params:scim:schemas:core:2.0:User", + "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", + ], + externalId, + userName: username, + active: true, + emails: [ + { + primary: true, + type: "work", + value: email, + }, + ], + meta: { + resourceType: "User", + }, + name: { + formatted: generator.name(), + familyName: lastName, + givenName: firstName, + }, + roles: [], + } + return user +} + +export function createGroupRequest(groupData?: { + externalId?: string + displayName?: string +}) { + const { externalId = uuid(), displayName = generator.word() } = + groupData || {} + + const group: ScimCreateGroupRequest = { + schemas: [ + "urn:ietf:params:scim:schemas:core:2.0:Group", + "http://schemas.microsoft.com/2006/11/ResourceManagement/ADSCIM/2.0/Group", + ], + externalId: externalId, + displayName: displayName, + meta: { + resourceType: "Group", + }, + } + return group +} diff --git a/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts b/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts index 904c20cf92..a553fbb7dd 100644 --- a/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts @@ -2,38 +2,17 @@ import tk from "timekeeper" import _ from "lodash" import { mocks, structures } from "@budibase/backend-core/tests" import { - ScimCreateGroupRequest, ScimGroupResponse, ScimUpdateRequest, + ScimUserResponse, } from "@budibase/types" import { TestConfiguration } from "../../../../../tests" mocks.licenses.useScimIntegration() -function createScimCreateGroupRequest(groupData?: { - externalId?: string - displayName?: string -}) { - const { - externalId = structures.uuid(), - displayName = structures.generator.word(), - } = groupData || {} - - const group: ScimCreateGroupRequest = { - schemas: [ - "urn:ietf:params:scim:schemas:core:2.0:Group", - "http://schemas.microsoft.com/2006/11/ResourceManagement/ADSCIM/2.0/Group", - ], - externalId: externalId, - displayName: displayName, - meta: { - resourceType: "Group", - }, - } - return group -} - describe("/api/global/scim/v2/groups", () => { + let users: ScimUserResponse[] + beforeEach(() => { tk.freeze(mocks.date.MOCK_DATE) @@ -44,6 +23,13 @@ describe("/api/global/scim/v2/groups", () => { beforeAll(async () => { await config.beforeAll() + + for (let i = 0; i < 30; i++) { + const body = structures.scim.createUserRequest() + users.push(await config.api.scimUsersAPI.post({ body })) + } + + users = users.sort((a, b) => (a.id > b.id ? 1 : -1)) }) afterAll(async () => { @@ -100,7 +86,7 @@ describe("/api/global/scim/v2/groups", () => { groups = [] for (let i = 0; i < groupCount; i++) { - const body = createScimCreateGroupRequest() + const body = structures.scim.createGroupRequest() groups.push(await config.api.scimGroupsAPI.post({ body })) } @@ -156,7 +142,7 @@ describe("/api/global/scim/v2/groups", () => { externalId: structures.uuid(), displayName: structures.generator.word(), } - const body = createScimCreateGroupRequest(groupData) + const body = structures.scim.createGroupRequest(groupData) const response = await postScimGroup({ body }) @@ -188,7 +174,7 @@ describe("/api/global/scim/v2/groups", () => { let group: ScimGroupResponse beforeEach(async () => { - const body = createScimCreateGroupRequest() + const body = structures.scim.createGroupRequest() group = await config.api.scimGroupsAPI.post({ body }) }) @@ -233,7 +219,7 @@ describe("/api/global/scim/v2/groups", () => { let group: ScimGroupResponse beforeEach(async () => { - const body = createScimCreateGroupRequest() + const body = structures.scim.createGroupRequest() group = await config.api.scimGroupsAPI.post({ body }) }) @@ -273,7 +259,7 @@ describe("/api/global/scim/v2/groups", () => { let group: ScimGroupResponse beforeEach(async () => { - const body = createScimCreateGroupRequest() + const body = structures.scim.createGroupRequest() group = await config.api.scimGroupsAPI.post({ body }) }) 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 c8753af405..a26be36e62 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 @@ -10,49 +10,6 @@ import { TestConfiguration } from "../../../../../tests" mocks.licenses.useScimIntegration() -function createScimCreateUserRequest(userData?: { - externalId?: string - email?: string - firstName?: string - lastName?: string - username?: string -}) { - const { - externalId = structures.uuid(), - email = structures.generator.email(), - firstName = structures.generator.first(), - lastName = structures.generator.last(), - username = structures.generator.name(), - } = userData || {} - - const user: ScimCreateUserRequest = { - schemas: [ - "urn:ietf:params:scim:schemas:core:2.0:User", - "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", - ], - externalId, - userName: username, - active: true, - emails: [ - { - primary: true, - type: "work", - value: email, - }, - ], - meta: { - resourceType: "User", - }, - name: { - formatted: structures.generator.name(), - familyName: lastName, - givenName: firstName, - }, - roles: [], - } - return user -} - describe("/api/global/scim/v2/users", () => { let mockedTime = new Date(structures.generator.timestamp()) @@ -124,7 +81,7 @@ describe("/api/global/scim/v2/users", () => { users = [] for (let i = 0; i < userCount; i++) { - const body = createScimCreateUserRequest() + const body = structures.scim.createUserRequest() users.push(await config.api.scimUsersAPI.post({ body })) } @@ -248,7 +205,7 @@ describe("/api/global/scim/v2/users", () => { lastName: structures.generator.last(), username: structures.generator.name(), } - const body = createScimCreateUserRequest(userData) + const body = structures.scim.createUserRequest(userData) const response = await postScimUser({ body }) @@ -293,7 +250,7 @@ describe("/api/global/scim/v2/users", () => { let user: ScimUserResponse beforeEach(async () => { - const body = createScimCreateUserRequest() + const body = structures.scim.createUserRequest() user = await config.api.scimUsersAPI.post({ body }) }) @@ -338,7 +295,7 @@ describe("/api/global/scim/v2/users", () => { let user: ScimUserResponse beforeEach(async () => { - const body = createScimCreateUserRequest() + const body = structures.scim.createUserRequest() user = await config.api.scimUsersAPI.post({ body }) }) @@ -481,7 +438,7 @@ describe("/api/global/scim/v2/users", () => { let user: ScimUserResponse beforeEach(async () => { - const body = createScimCreateUserRequest() + const body = structures.scim.createUserRequest() user = await config.api.scimUsersAPI.post({ body }) })