@budibase/worker 2.4.44-alpha.10 → 2.4.44-alpha.12

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.10",
4
+ "version": "2.4.44-alpha.12",
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.10",
41
- "@budibase/pro": "2.4.44-alpha.9",
42
- "@budibase/string-templates": "2.4.44-alpha.10",
43
- "@budibase/types": "2.4.44-alpha.10",
40
+ "@budibase/backend-core": "2.4.44-alpha.12",
41
+ "@budibase/pro": "2.4.44-alpha.11",
42
+ "@budibase/string-templates": "2.4.44-alpha.12",
43
+ "@budibase/types": "2.4.44-alpha.12",
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": "e1b120d9f0399e668c5870e612652a7bc684f47d"
105
+ "gitHead": "6c376568d6f2cc8d6836299a82261693ffec50dd"
106
106
  }
@@ -318,6 +318,15 @@ describe("scim", () => {
318
318
  await postScimUser({ body }, { expect: 500 })
319
319
  })
320
320
  })
321
+
322
+ it("creating an existing user name returns a conflict", async () => {
323
+ const body = structures.scim.createUserRequest()
324
+
325
+ await postScimUser({ body })
326
+
327
+ const res = await postScimUser({ body }, { expect: 409 })
328
+ expect((res as any).message).toBe("Email already in use")
329
+ })
321
330
  })
322
331
 
323
332
  describe("GET /api/global/scim/v2/users/:id", () => {
@@ -399,53 +408,19 @@ describe("scim", () => {
399
408
  })
400
409
 
401
410
  it.each([false, "false", "False"])(
402
- "can deactive an active user (sending %s)",
403
- async activeValue => {
404
- const body: ScimUpdateRequest = {
405
- schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
406
- Operations: [{ op: "Replace", path: "active", value: activeValue }],
407
- }
408
-
409
- const response = await patchScimUser({ id: user.id, body })
410
-
411
- const expectedScimUser: ScimUserResponse = {
412
- ...user,
413
- active: false,
414
- }
415
- expect(response).toEqual(expectedScimUser)
416
-
417
- const persistedUser = await config.api.scimUsersAPI.find(user.id)
418
- expect(persistedUser).toEqual(expectedScimUser)
419
- }
420
- )
421
-
422
- it.each([true, "true", "True"])(
423
- "can activate an inactive user (sending %s)",
411
+ "deactivating an active user (sending %s) will delete it",
424
412
  async activeValue => {
425
- // Deactivate user
426
- await patchScimUser({
427
- id: user.id,
428
- body: {
429
- schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
430
- Operations: [{ op: "Replace", path: "active", value: true }],
431
- },
432
- })
433
-
434
413
  const body: ScimUpdateRequest = {
435
414
  schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
436
415
  Operations: [{ op: "Replace", path: "active", value: activeValue }],
437
416
  }
438
417
 
439
- const response = await patchScimUser({ id: user.id, body })
440
-
441
- const expectedScimUser: ScimUserResponse = {
442
- ...user,
443
- active: true,
444
- }
445
- expect(response).toEqual(expectedScimUser)
418
+ await patchScimUser(
419
+ { id: user.id, body },
420
+ { expect: 204, skipContentTypeCheck: true }
421
+ )
446
422
 
447
- const persistedUser = await config.api.scimUsersAPI.find(user.id)
448
- expect(persistedUser).toEqual(expectedScimUser)
423
+ await config.api.scimUsersAPI.find(user.id, { expect: 404 })
449
424
  }
450
425
  )
451
426
 
@@ -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
 
@@ -4,6 +4,7 @@ import { TestAPI } from "../base"
4
4
  const defaultConfig = {
5
5
  expect: 200,
6
6
  setHeaders: true,
7
+ skipContentTypeCheck: false,
7
8
  }
8
9
 
9
10
  export type RequestSettings = typeof defaultConfig
@@ -27,7 +28,7 @@ export abstract class ScimTestAPI extends TestAPI {
27
28
  "application/scim+json; charset=utf-8"
28
29
  )
29
30
 
30
- if (method !== "delete") {
31
+ if (method !== "delete" && !requestSettings?.skipContentTypeCheck) {
31
32
  request = request.expect("Content-Type", /json/)
32
33
  }
33
34