@budibase/worker 2.4.44-alpha.11 → 2.4.44-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.4.44-alpha.11",
4
+ "version": "2.4.44-alpha.13",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -37,10 +37,10 @@
37
37
  "author": "Budibase",
38
38
  "license": "GPL-3.0",
39
39
  "dependencies": {
40
- "@budibase/backend-core": "2.4.44-alpha.11",
41
- "@budibase/pro": "2.4.44-alpha.10",
42
- "@budibase/string-templates": "2.4.44-alpha.11",
43
- "@budibase/types": "2.4.44-alpha.11",
40
+ "@budibase/backend-core": "2.4.44-alpha.13",
41
+ "@budibase/pro": "2.4.44-alpha.12",
42
+ "@budibase/string-templates": "2.4.44-alpha.13",
43
+ "@budibase/types": "2.4.44-alpha.13",
44
44
  "@koa/router": "8.0.8",
45
45
  "@sentry/node": "6.17.7",
46
46
  "@techpass/passport-openidconnect": "0.3.2",
@@ -102,5 +102,5 @@
102
102
  "typescript": "4.7.3",
103
103
  "update-dotenv": "1.1.1"
104
104
  },
105
- "gitHead": "4648691c554058fff87d93c1c02cce7fc8263a38"
105
+ "gitHead": "8450b2ecd96fe84154f113b8b9c8dd27483c73f7"
106
106
  }
@@ -255,6 +255,45 @@ describe("scim", () => {
255
255
  )
256
256
  })
257
257
 
258
+ it("a new user can minim information", async () => {
259
+ const userData = {
260
+ externalId: structures.uuid(),
261
+ email: structures.generator.email(),
262
+ username: structures.generator.name(),
263
+ firstName: undefined,
264
+ lastName: undefined,
265
+ }
266
+ const body = structures.scim.createUserRequest(userData)
267
+
268
+ const response = await postScimUser({ body })
269
+
270
+ const expectedScimUser = {
271
+ schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
272
+ id: expect.any(String),
273
+ externalId: userData.externalId,
274
+ meta: {
275
+ resourceType: "User",
276
+ created: mocks.date.MOCK_DATE.toISOString(),
277
+ lastModified: mocks.date.MOCK_DATE.toISOString(),
278
+ },
279
+ userName: userData.username,
280
+ active: true,
281
+ emails: [
282
+ {
283
+ value: userData.email,
284
+ type: "work",
285
+ primary: true,
286
+ },
287
+ ],
288
+ }
289
+ expect(response).toEqual(expectedScimUser)
290
+
291
+ const persistedUsers = await config.api.scimUsersAPI.get()
292
+ expect(persistedUsers.Resources).toEqual(
293
+ expect.arrayContaining([expectedScimUser])
294
+ )
295
+ })
296
+
258
297
  it("an event is dispatched", async () => {
259
298
  const body = structures.scim.createUserRequest()
260
299
 
@@ -318,6 +357,15 @@ describe("scim", () => {
318
357
  await postScimUser({ body }, { expect: 500 })
319
358
  })
320
359
  })
360
+
361
+ it("creating an existing user name returns a conflict", async () => {
362
+ const body = structures.scim.createUserRequest()
363
+
364
+ await postScimUser({ body })
365
+
366
+ const res = await postScimUser({ body }, { expect: 409 })
367
+ expect((res as any).message).toBe("Email already in use")
368
+ })
321
369
  })
322
370
 
323
371
  describe("GET /api/global/scim/v2/users/:id", () => {
@@ -389,7 +437,7 @@ describe("scim", () => {
389
437
  name: {
390
438
  ...user.name,
391
439
  familyName: newFamilyName,
392
- formatted: `${user.name.givenName} ${newFamilyName}`,
440
+ formatted: `${user.name!.givenName} ${newFamilyName}`,
393
441
  },
394
442
  }
395
443
  expect(response).toEqual(expectedScimUser)
@@ -48,7 +48,7 @@ describe("/api/global/users", () => {
48
48
  400
49
49
  )
50
50
 
51
- expect(res.body.message).toBe("Unavailable")
51
+ expect(res.body.message).toBe(`Unavailable`)
52
52
  expect(sendMailMock).toHaveBeenCalledTimes(0)
53
53
  expect(code).toBeUndefined()
54
54
  expect(events.user.invited).toBeCalledTimes(0)
@@ -225,7 +225,9 @@ describe("/api/global/users", () => {
225
225
 
226
226
  const response = await config.api.users.saveUser(user, 400)
227
227
 
228
- expect(response.body.message).toBe(`Unavailable`)
228
+ expect(response.body.message).toBe(
229
+ `Email already in use: '${user.email}'`
230
+ )
229
231
  expect(events.user.created).toBeCalledTimes(0)
230
232
  })
231
233
 
@@ -237,7 +239,9 @@ describe("/api/global/users", () => {
237
239
  delete user._id
238
240
  const response = await config.api.users.saveUser(user, 400)
239
241
 
240
- expect(response.body.message).toBe(`Unavailable`)
242
+ expect(response.body.message).toBe(
243
+ `Email already in use: '${user.email}'`
244
+ )
241
245
  expect(events.user.created).toBeCalledTimes(0)
242
246
  })
243
247
  })
@@ -249,7 +253,9 @@ describe("/api/global/users", () => {
249
253
 
250
254
  const response = await config.api.users.saveUser(user, 400)
251
255
 
252
- expect(response.body.message).toBe(`Unavailable`)
256
+ expect(response.body.message).toBe(
257
+ `Email already in use: '${user.email}'`
258
+ )
253
259
  expect(events.user.created).toBeCalledTimes(0)
254
260
  })
255
261
 
@@ -16,6 +16,7 @@ import {
16
16
  ViewName,
17
17
  env as coreEnv,
18
18
  context,
19
+ EmailUnavailableError,
19
20
  } from "@budibase/backend-core"
20
21
  import {
21
22
  AccountMetadata,
@@ -158,7 +159,7 @@ const validateUniqueUser = async (email: string, tenantId: string) => {
158
159
  if (env.MULTI_TENANCY) {
159
160
  const tenantUser = await getPlatformUser(email)
160
161
  if (tenantUser != null && tenantUser.tenantId !== tenantId) {
161
- throw `Unavailable`
162
+ throw new EmailUnavailableError(email)
162
163
  }
163
164
  }
164
165
 
@@ -166,7 +167,7 @@ const validateUniqueUser = async (email: string, tenantId: string) => {
166
167
  if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
167
168
  const account = await accounts.getAccount(email)
168
169
  if (account && account.verified && account.tenantId !== tenantId) {
169
- throw `Unavailable`
170
+ throw new EmailUnavailableError(email)
170
171
  }
171
172
  }
172
173
  }
@@ -235,7 +236,7 @@ export const save = async (
235
236
  // no id was specified - load from email instead
236
237
  dbUser = await usersCore.getGlobalUserByEmail(email)
237
238
  if (dbUser && dbUser._id !== _id) {
238
- throw `Unavailable`
239
+ throw new EmailUnavailableError(email)
239
240
  }
240
241
  }
241
242