1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +13:00

Make scim info extensible and the object unaware of the data

This commit is contained in:
adrinr 2023-04-03 19:06:03 +01:00
parent ad4f70b826
commit e0bcc42c80
3 changed files with 66 additions and 12 deletions

View file

@ -9,7 +9,6 @@ type Emails =
type: "work"
primary: boolean
}[]
| undefined
export interface ScimUserResponse extends ScimResource {
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"]
@ -26,7 +25,7 @@ export interface ScimUserResponse extends ScimResource {
givenName: string
}
active: BooleanString
emails: Emails
emails?: Emails
}
export interface ScimCreateUserRequest {
@ -37,7 +36,7 @@ export interface ScimCreateUserRequest {
externalId: string
userName: string
active: BooleanString
emails: Emails
emails?: Emails
meta: {
resourceType: "User"
}

View file

@ -53,12 +53,7 @@ export interface User extends Document {
dayPassRecordedAt?: string
userGroups?: string[]
onboardedAt?: string
scimInfo?: {
isSync: boolean
userName: string
externalId: string
displayName?: string
}
scimInfo?: { isSync: true } & Record<string, any>
}
export enum UserStatus {

View file

@ -2,6 +2,7 @@ import tk from "timekeeper"
import _ from "lodash"
import { mocks, structures } from "@budibase/backend-core/tests"
import {
ScimCreateUserRequest,
ScimGroupResponse,
ScimUpdateRequest,
ScimUserResponse,
@ -176,7 +177,9 @@ describe("scim", () => {
const response = await getScimUsers({
params: {
filter: encodeURI(
`emails[type eq "work"].value eq "${userToFetch?.emails[0].value}"`
`emails[type eq "work"].value eq "${
userToFetch?.emails![0].value
}"`
),
},
})
@ -259,6 +262,61 @@ describe("scim", () => {
expect(events.user.created).toBeCalledTimes(1)
})
it("if the username is an email, the user name will be used as email", async () => {
const email = structures.generator.email()
const body: ScimCreateUserRequest = structures.scim.createUserRequest(
{ username: email }
)
delete body.emails
await postScimUser({ body })
const user = await config.getUser(email)
expect(user).toBeDefined()
expect(user.email).toEqual(email)
})
it("if multiple emails are provided, the first primary one is used as email", async () => {
const email = structures.generator.email()
const body: ScimCreateUserRequest = {
...structures.scim.createUserRequest(),
emails: [
{
primary: false,
type: "work",
value: structures.generator.email(),
},
{
primary: true,
type: "work",
value: email,
},
{
primary: true,
type: "work",
value: structures.generator.email(),
},
],
}
await postScimUser({ body })
const user = await config.getUser(email)
expect(user).toBeDefined()
expect(user.email).toEqual(email)
})
it("if no email is provided and the user name is not an email, an exception is thrown", async () => {
const body: ScimCreateUserRequest = structures.scim.createUserRequest(
{ username: structures.generator.name() }
)
delete body.emails
await postScimUser({ body }, { expect: 500 })
})
})
})
@ -392,21 +450,23 @@ describe("scim", () => {
)
it("supports updating unmapped fields", async () => {
const value = structures.generator.letter()
const body: ScimUpdateRequest = {
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
Operations: [
{
op: "Add",
path: "preferredLanguage",
value: structures.generator.letter(),
value,
},
],
}
const response = await patchScimUser({ id: user.id, body })
const expectedScimUser: ScimUserResponse = {
const expectedScimUser = {
...user,
preferredLanguage: value,
}
expect(response).toEqual(expectedScimUser)