Merge pull request #13137 from Budibase/BUDI-8046/allow-syncing-existing-users

Link existing users on SCIM creation
This commit is contained in:
Adria Navarro 2024-02-27 12:27:05 +01:00 committed by GitHub
commit 34ac3a3952
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 70 additions and 8 deletions

@ -1 +1 @@
Subproject commit 183b35d3acd42433dcb2d32bcd89a36abe13afec Subproject commit ec9dd27aee79f206e595d36a438ca17efdcfde40

View File

@ -10,8 +10,6 @@ import {
import { TestConfiguration } from "../../../../tests" import { TestConfiguration } from "../../../../tests"
import { events } from "@budibase/backend-core" import { events } from "@budibase/backend-core"
// this test can 409 - retries reduce issues with this
jest.retryTimes(2, { logErrorsBeforeRetry: true })
jest.setTimeout(30000) jest.setTimeout(30000)
describe("scim", () => { describe("scim", () => {
@ -367,13 +365,77 @@ describe("scim", () => {
}) })
}) })
it("creating an existing user name returns a conflict", async () => { it("creating an external user that conflicts an internal one syncs the existing user", async () => {
const body = structures.scim.createUserRequest() const { body: internalUser } = await config.api.users.saveUser(
structures.users.user()
)
await postScimUser({ body }) const scimUserData = {
externalId: structures.uuid(),
email: internalUser.email,
firstName: structures.generator.first(),
lastName: structures.generator.last(),
username: structures.generator.name(),
}
const scimUserRequest = structures.scim.createUserRequest(scimUserData)
const res = await postScimUser({ body }, { expect: 409 }) const res = await postScimUser(
expect((res as any).message).toBe("Email already in use") { body: scimUserRequest },
{ expect: 200 }
)
const expectedScimUser: ScimUserResponse = {
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
id: internalUser._id!,
externalId: scimUserRequest.externalId,
meta: {
resourceType: "User",
// @ts-ignore
created: mocks.date.MOCK_DATE.toISOString(),
// @ts-ignore
lastModified: mocks.date.MOCK_DATE.toISOString(),
},
userName: scimUserData.username,
name: {
formatted: `${scimUserData.firstName} ${scimUserData.lastName}`,
familyName: scimUserData.lastName,
givenName: scimUserData.firstName,
},
active: true,
emails: [
{
value: internalUser.email,
type: "work",
primary: true,
},
],
}
expect(res).toEqual(expectedScimUser)
})
it("a user cannot be SCIM synchronised with another SCIM user", async () => {
const { body: internalUser } = await config.api.users.saveUser(
structures.users.user()
)
await postScimUser(
{
body: structures.scim.createUserRequest({
email: internalUser.email,
}),
},
{ expect: 200 }
)
await postScimUser(
{
body: structures.scim.createUserRequest({
email: internalUser.email,
}),
},
{ expect: 409 }
)
}) })
}) })