@budibase/worker 2.13.51 → 2.13.53

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.13.51",
4
+ "version": "2.13.53",
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.13.51",
41
- "@budibase/pro": "2.13.51",
42
- "@budibase/string-templates": "2.13.51",
43
- "@budibase/types": "2.13.51",
40
+ "@budibase/backend-core": "2.13.53",
41
+ "@budibase/pro": "2.13.53",
42
+ "@budibase/string-templates": "2.13.53",
43
+ "@budibase/types": "2.13.53",
44
44
  "@koa/router": "8.0.8",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
46
46
  "@types/global-agent": "2.1.1",
@@ -107,5 +107,5 @@
107
107
  }
108
108
  }
109
109
  },
110
- "gitHead": "de9602636388e8008fea9001494a816d5fc387e8"
110
+ "gitHead": "fdca8d1da7a9fd7ccd26a0aca8c19da4699325d3"
111
111
  }
@@ -30,6 +30,7 @@ async function init() {
30
30
  ENABLE_EMAIL_TEST_MODE: "1",
31
31
  HTTP_LOGGING: "0",
32
32
  VERSION: "0.0.0+local",
33
+ PASSWORD_MIN_LENGTH: "1",
33
34
  }
34
35
 
35
36
  config = { ...config, ...existingConfig }
@@ -122,10 +122,10 @@ export const resetUpdate = async (ctx: Ctx<PasswordResetUpdateRequest>) => {
122
122
  ctx.body = {
123
123
  message: "password reset successfully.",
124
124
  }
125
- } catch (err) {
125
+ } catch (err: any) {
126
126
  console.warn(err)
127
127
  // hide any details of the error for security
128
- ctx.throw(400, "Cannot reset password.")
128
+ ctx.throw(400, err.message || "Cannot reset password.")
129
129
  }
130
130
  }
131
131
 
@@ -229,7 +229,7 @@ describe("/api/global/auth", () => {
229
229
  )
230
230
 
231
231
  expect(res.body).toEqual({
232
- message: "Cannot reset password.",
232
+ message: "Password change is disabled for this user",
233
233
  status: 400,
234
234
  })
235
235
  }
@@ -261,8 +261,12 @@ describe("/api/global/auth", () => {
261
261
  )
262
262
 
263
263
  // convert to account owner now that password has been requested
264
- const account = structures.accounts.ssoAccount() as CloudAccount
265
- mocks.accounts.getAccount.mockReturnValueOnce(
264
+ const account: CloudAccount = {
265
+ ...structures.accounts.ssoAccount(),
266
+ budibaseUserId: "budibaseUserId",
267
+ email: user.email,
268
+ }
269
+ mocks.accounts.getAccountByTenantId.mockReturnValueOnce(
266
270
  Promise.resolve(account)
267
271
  )
268
272
 
@@ -1,6 +1,6 @@
1
1
  import tk from "timekeeper"
2
2
  import _ from "lodash"
3
- import { mocks, structures } from "@budibase/backend-core/tests"
3
+ import { generator, mocks, structures } from "@budibase/backend-core/tests"
4
4
  import {
5
5
  ScimCreateUserRequest,
6
6
  ScimGroupResponse,
@@ -14,9 +14,14 @@ import { events } from "@budibase/backend-core"
14
14
  jest.retryTimes(2, { logErrorsBeforeRetry: true })
15
15
  jest.setTimeout(30000)
16
16
 
17
- mocks.licenses.useScimIntegration()
18
-
19
17
  describe("scim", () => {
18
+ beforeAll(async () => {
19
+ tk.freeze(mocks.date.MOCK_DATE)
20
+ mocks.licenses.useScimIntegration()
21
+
22
+ await config.setSCIMConfig(true)
23
+ })
24
+
20
25
  beforeEach(async () => {
21
26
  jest.resetAllMocks()
22
27
  tk.freeze(mocks.date.MOCK_DATE)
@@ -570,8 +575,15 @@ describe("scim", () => {
570
575
  beforeAll(async () => {
571
576
  groups = []
572
577
 
573
- for (let i = 0; i < groupCount; i++) {
574
- const body = structures.scim.createGroupRequest()
578
+ const groupNames = generator.unique(
579
+ () => generator.word(),
580
+ groupCount
581
+ )
582
+
583
+ for (const groupName of groupNames) {
584
+ const body = structures.scim.createGroupRequest({
585
+ displayName: groupName,
586
+ })
575
587
  groups.push(await config.api.scimGroupsAPI.post({ body }))
576
588
  }
577
589
 
@@ -79,6 +79,9 @@ export const resetUpdate = async (resetCode: string, password: string) => {
79
79
  user.password = password
80
80
  user = await userSdk.db.save(user)
81
81
 
82
+ await cache.passwordReset.invalidateCode(resetCode)
83
+ await sessions.invalidateSessions(userId)
84
+
82
85
  // remove password from the user before sending events
83
86
  delete user.password
84
87
  await events.user.passwordReset(user)
@@ -0,0 +1,70 @@
1
+ import { cache, context, sessions, utils } from "@budibase/backend-core"
2
+ import { loginUser, resetUpdate } from "../auth"
3
+ import { generator, structures } from "@budibase/backend-core/tests"
4
+ import { TestConfiguration } from "../../../tests"
5
+
6
+ describe("auth", () => {
7
+ const config = new TestConfiguration()
8
+
9
+ describe("resetUpdate", () => {
10
+ it("providing a valid code will update the password", async () => {
11
+ await context.doInTenant(structures.tenant.id(), async () => {
12
+ const user = await config.createUser()
13
+ const previousPassword = user.password
14
+
15
+ const code = await cache.passwordReset.createCode(user._id!, {})
16
+ const newPassword = generator.hash()
17
+
18
+ await resetUpdate(code, newPassword)
19
+
20
+ const persistedUser = await config.getUser(user.email)
21
+ expect(persistedUser.password).not.toBe(previousPassword)
22
+ expect(
23
+ await utils.compare(newPassword, persistedUser.password!)
24
+ ).toBeTruthy()
25
+ })
26
+ })
27
+
28
+ it("wrong code will not allow to reset the password", async () => {
29
+ await context.doInTenant(structures.tenant.id(), async () => {
30
+ const code = generator.hash()
31
+ const newPassword = generator.hash()
32
+
33
+ await expect(resetUpdate(code, newPassword)).rejects.toThrow(
34
+ "Provided information is not valid, cannot reset password - please try again."
35
+ )
36
+ })
37
+ })
38
+
39
+ it("the same code cannot be used twice", async () => {
40
+ await context.doInTenant(structures.tenant.id(), async () => {
41
+ const user = await config.createUser()
42
+
43
+ const code = await cache.passwordReset.createCode(user._id!, {})
44
+ const newPassword = generator.hash()
45
+
46
+ await resetUpdate(code, newPassword)
47
+ await expect(resetUpdate(code, newPassword)).rejects.toThrow(
48
+ "Provided information is not valid, cannot reset password - please try again."
49
+ )
50
+ })
51
+ })
52
+
53
+ it("updating the password will invalidate all the sessions", async () => {
54
+ await context.doInTenant(structures.tenant.id(), async () => {
55
+ const user = await config.createUser()
56
+
57
+ await loginUser(user)
58
+
59
+ expect(await sessions.getSessionsForUser(user._id!)).toHaveLength(1)
60
+
61
+ const code = await cache.passwordReset.createCode(user._id!, {})
62
+ const newPassword = generator.hash()
63
+
64
+ await resetUpdate(code, newPassword)
65
+
66
+ expect(await sessions.getSessionsForUser(user._id!)).toHaveLength(0)
67
+ })
68
+ })
69
+ })
70
+ })
@@ -1,6 +1,5 @@
1
1
  import { structures, mocks } from "../../../tests"
2
2
  import { env, context } from "@budibase/backend-core"
3
- import * as users from "../users"
4
3
  import { db as userDb } from "../"
5
4
  import { CloudAccount } from "@budibase/types"
6
5
 
@@ -45,7 +45,7 @@ class TestConfiguration {
45
45
  tenantId: string
46
46
  user?: User
47
47
  apiKey?: string
48
- userPassword = "test"
48
+ userPassword = "password"
49
49
 
50
50
  constructor(opts: { openServer: boolean } = { openServer: true }) {
51
51
  // default to cloud hosting
@@ -101,7 +101,7 @@ export class UserAPI extends TestAPI {
101
101
  if (!request) {
102
102
  request = {
103
103
  email: structures.email(),
104
- password: generator.string(),
104
+ password: generator.string({ length: 8 }),
105
105
  tenantId: structures.tenant.id(),
106
106
  }
107
107
  }