@budibase/worker 2.3.17 → 2.3.18-alpha.0

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.
Files changed (166) hide show
  1. package/__mocks__/node-fetch.ts +23 -0
  2. package/jest-testcontainers-config.js +8 -0
  3. package/jest.config.ts +3 -2
  4. package/package.json +10 -7
  5. package/scripts/dev/manage.js +1 -0
  6. package/src/api/controllers/global/auth.ts +77 -70
  7. package/src/api/controllers/global/self.ts +28 -44
  8. package/src/api/controllers/global/users.ts +65 -25
  9. package/src/api/controllers/system/accounts.ts +7 -5
  10. package/src/api/controllers/system/tenants.ts +4 -8
  11. package/src/api/index.ts +4 -20
  12. package/src/api/routes/global/auth.ts +10 -7
  13. package/src/api/routes/global/tests/auth.spec.ts +226 -17
  14. package/src/api/routes/global/tests/configs.spec.ts +5 -5
  15. package/src/api/routes/global/tests/roles.spec.ts +20 -14
  16. package/src/api/routes/global/tests/self.spec.ts +3 -4
  17. package/src/api/routes/global/tests/users.spec.ts +24 -27
  18. package/src/api/routes/system/tenants.ts +1 -1
  19. package/src/api/routes/system/tests/accounts.spec.ts +4 -4
  20. package/src/api/routes/system/tests/migrations.spec.ts +2 -2
  21. package/src/api/routes/system/tests/restore.spec.ts +2 -2
  22. package/src/api/routes/system/tests/status.spec.ts +5 -5
  23. package/src/ddApm.ts +7 -0
  24. package/src/elasticApm.ts +10 -0
  25. package/src/environment.ts +15 -1
  26. package/src/index.ts +12 -7
  27. package/src/middleware/tests/tenancy.spec.ts +4 -4
  28. package/src/migrations/functions/globalInfoSyncUsers.ts +4 -3
  29. package/src/sdk/accounts/index.ts +2 -1
  30. package/src/sdk/accounts/{accounts.ts → metadata.ts} +0 -1
  31. package/src/sdk/auth/auth.ts +86 -0
  32. package/src/sdk/auth/index.ts +1 -0
  33. package/src/sdk/tenants/index.ts +1 -0
  34. package/src/sdk/tenants/tenants.ts +76 -0
  35. package/src/sdk/users/events.ts +4 -0
  36. package/src/sdk/users/index.ts +1 -0
  37. package/src/sdk/users/tests/users.spec.ts +52 -0
  38. package/src/sdk/users/users.ts +53 -46
  39. package/src/tests/TestConfiguration.ts +41 -62
  40. package/src/tests/api/auth.ts +42 -14
  41. package/src/tests/api/base.ts +2 -1
  42. package/src/tests/api/configs.ts +2 -2
  43. package/src/tests/api/restore.ts +1 -0
  44. package/src/tests/api/users.ts +2 -2
  45. package/src/tests/jestEnv.ts +2 -1
  46. package/src/tests/jestSetup.ts +10 -6
  47. package/src/tests/logging.ts +34 -0
  48. package/src/tests/structures/index.ts +0 -4
  49. package/src/utilities/email.ts +3 -3
  50. package/coverage/clover.xml +0 -2199
  51. package/coverage/coverage-final.json +0 -84
  52. package/coverage/lcov-report/base.css +0 -224
  53. package/coverage/lcov-report/block-navigation.js +0 -87
  54. package/coverage/lcov-report/favicon.png +0 -0
  55. package/coverage/lcov-report/index.html +0 -431
  56. package/coverage/lcov-report/prettify.css +0 -1
  57. package/coverage/lcov-report/prettify.js +0 -2
  58. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  59. package/coverage/lcov-report/sorter.js +0 -196
  60. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -934
  61. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1348
  62. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
  63. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +0 -136
  64. package/coverage/lcov-report/src/api/controllers/global/index.html +0 -251
  65. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
  66. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
  67. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
  68. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
  69. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -838
  70. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
  71. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
  72. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
  73. package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
  74. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
  75. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
  76. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
  77. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
  78. package/coverage/lcov-report/src/api/index.html +0 -116
  79. package/coverage/lcov-report/src/api/index.ts.html +0 -595
  80. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
  81. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
  82. package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
  83. package/coverage/lcov-report/src/api/routes/global/events.ts.html +0 -109
  84. package/coverage/lcov-report/src/api/routes/global/index.html +0 -251
  85. package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
  86. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
  87. package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
  88. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
  89. package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -475
  90. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
  91. package/coverage/lcov-report/src/api/routes/index.html +0 -116
  92. package/coverage/lcov-report/src/api/routes/index.ts.html +0 -202
  93. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
  94. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
  95. package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
  96. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
  97. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
  98. package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
  99. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
  100. package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
  101. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
  102. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
  103. package/coverage/lcov-report/src/constants/index.html +0 -116
  104. package/coverage/lcov-report/src/constants/index.ts.html +0 -637
  105. package/coverage/lcov-report/src/constants/templates/index.html +0 -116
  106. package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
  107. package/coverage/lcov-report/src/db/index.html +0 -116
  108. package/coverage/lcov-report/src/db/index.ts.html +0 -115
  109. package/coverage/lcov-report/src/environment.ts.html +0 -388
  110. package/coverage/lcov-report/src/index.html +0 -131
  111. package/coverage/lcov-report/src/index.ts.html +0 -394
  112. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
  113. package/coverage/lcov-report/src/middleware/index.html +0 -116
  114. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
  115. package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
  116. package/coverage/lcov-report/src/migrations/index.html +0 -116
  117. package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
  118. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
  119. package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
  120. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
  121. package/coverage/lcov-report/src/sdk/index.html +0 -116
  122. package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
  123. package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -601
  124. package/coverage/lcov-report/src/sdk/users/index.html +0 -146
  125. package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
  126. package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1999
  127. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1075
  128. package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
  129. package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
  130. package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
  131. package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
  132. package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
  133. package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
  134. package/coverage/lcov-report/src/tests/api/groups.ts.html +0 -163
  135. package/coverage/lcov-report/src/tests/api/index.html +0 -356
  136. package/coverage/lcov-report/src/tests/api/index.ts.html +0 -238
  137. package/coverage/lcov-report/src/tests/api/license.ts.html +0 -136
  138. package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
  139. package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
  140. package/coverage/lcov-report/src/tests/api/roles.ts.html +0 -181
  141. package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
  142. package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
  143. package/coverage/lcov-report/src/tests/api/templates.ts.html +0 -175
  144. package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
  145. package/coverage/lcov-report/src/tests/api/users.ts.html +0 -514
  146. package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
  147. package/coverage/lcov-report/src/tests/index.html +0 -146
  148. package/coverage/lcov-report/src/tests/index.ts.html +0 -103
  149. package/coverage/lcov-report/src/tests/mocks/email.ts.html +0 -115
  150. package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
  151. package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
  152. package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
  153. package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
  154. package/coverage/lcov-report/src/tests/structures/index.html +0 -161
  155. package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
  156. package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
  157. package/coverage/lcov-report/src/utilities/appService.ts.html +0 -208
  158. package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
  159. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
  160. package/coverage/lcov-report/src/utilities/index.html +0 -206
  161. package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
  162. package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
  163. package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
  164. package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
  165. package/coverage/lcov.info +0 -4187
  166. package/src/tests/structures/users.ts +0 -37
@@ -1,20 +1,39 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
3
 
4
4
  export class AuthAPI extends TestAPI {
5
5
  constructor(config: TestConfiguration) {
6
6
  super(config)
7
7
  }
8
8
 
9
- updatePassword = (code: string) => {
9
+ updatePassword = (
10
+ resetCode: string,
11
+ password: string,
12
+ opts?: TestAPIOpts
13
+ ) => {
10
14
  return this.request
11
15
  .post(`/api/global/auth/${this.config.getTenantId()}/reset/update`)
12
16
  .send({
13
- password: "newpassword",
14
- resetCode: code,
17
+ password,
18
+ resetCode,
15
19
  })
16
20
  .expect("Content-Type", /json/)
17
- .expect(200)
21
+ .expect(opts?.status ? opts.status : 200)
22
+ }
23
+
24
+ login = (
25
+ tenantId: string,
26
+ email: string,
27
+ password: string,
28
+ opts?: TestAPIOpts
29
+ ) => {
30
+ return this.request
31
+ .post(`/api/global/auth/${tenantId}/login`)
32
+ .send({
33
+ username: email,
34
+ password: password,
35
+ })
36
+ .expect(opts?.status ? opts.status : 200)
18
37
  }
19
38
 
20
39
  logout = () => {
@@ -24,22 +43,31 @@ export class AuthAPI extends TestAPI {
24
43
  .expect(200)
25
44
  }
26
45
 
27
- requestPasswordReset = async (sendMailMock: any) => {
46
+ requestPasswordReset = async (
47
+ sendMailMock: any,
48
+ email: string,
49
+ opts?: TestAPIOpts
50
+ ) => {
28
51
  await this.config.saveSmtpConfig()
29
52
  await this.config.saveSettingsConfig()
30
- await this.config.createUser()
53
+
31
54
  const res = await this.request
32
55
  .post(`/api/global/auth/${this.config.getTenantId()}/reset`)
33
56
  .send({
34
- email: "test@test.com",
57
+ email: email,
35
58
  })
36
59
  .expect("Content-Type", /json/)
37
- .expect(200)
38
- const emailCall = sendMailMock.mock.calls[0][0]
39
- const parts = emailCall.html.split(
40
- `http://localhost:10000/builder/auth/reset?code=`
41
- )
42
- const code = parts[1].split('"')[0].split("&")[0]
60
+ .expect(opts?.status ? opts.status : 200)
61
+
62
+ let code: string | undefined
63
+ if (res.status === 200) {
64
+ const emailCall = sendMailMock.mock.calls[0][0]
65
+ const parts = emailCall.html.split(
66
+ `http://localhost:10000/builder/auth/reset?code=`
67
+ )
68
+ code = parts[1].split('"')[0].split("&")[0]
69
+ }
70
+
43
71
  return { code, res }
44
72
  }
45
73
  }
@@ -1,4 +1,5 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
+ import { SuperTest, Test } from "supertest"
2
3
 
3
4
  export interface TestAPIOpts {
4
5
  headers?: any
@@ -7,7 +8,7 @@ export interface TestAPIOpts {
7
8
 
8
9
  export abstract class TestAPI {
9
10
  config: TestConfiguration
10
- request: any
11
+ request: SuperTest<Test>
11
12
 
12
13
  protected constructor(config: TestConfiguration) {
13
14
  this.config = config
@@ -10,8 +10,8 @@ export class ConfigAPI extends TestAPI {
10
10
  return this.request
11
11
  .get(`/api/global/configs/checklist`)
12
12
  .set(this.config.defaultHeaders())
13
- .expect("Content-Type", /json/)
14
13
  .expect(200)
14
+ .expect("Content-Type", /json/)
15
15
  }
16
16
 
17
17
  saveConfig = (data: any) => {
@@ -19,8 +19,8 @@ export class ConfigAPI extends TestAPI {
19
19
  .post(`/api/global/configs`)
20
20
  .send(data)
21
21
  .set(this.config.defaultHeaders())
22
- .expect("Content-Type", /json/)
23
22
  .expect(200)
23
+ .expect("Content-Type", /json/)
24
24
  }
25
25
 
26
26
  OIDCCallback = (configId: string, preAuthRes: any) => {
@@ -9,6 +9,7 @@ export class RestoreAPI extends TestAPI {
9
9
  restored = (opts?: TestAPIOpts) => {
10
10
  return this.request
11
11
  .post(`/api/system/restored`)
12
+ .set(this.config.tenantIdHeaders())
12
13
  .expect(opts?.status ? opts.status : 200)
13
14
  }
14
15
  }
@@ -26,8 +26,8 @@ export class UserAPI extends TestAPI {
26
26
  email,
27
27
  })
28
28
  .set(this.config.defaultHeaders())
29
- .expect("Content-Type", /json/)
30
29
  .expect(status)
30
+ .expect("Content-Type", /json/)
31
31
 
32
32
  if (status !== 200) {
33
33
  return { code: undefined, res }
@@ -100,7 +100,7 @@ export class UserAPI extends TestAPI {
100
100
  request = {
101
101
  email: structures.email(),
102
102
  password: generator.string(),
103
- tenantId: structures.uuid(),
103
+ tenantId: structures.tenant.id(),
104
104
  }
105
105
  }
106
106
  const res = await this.request
@@ -1,7 +1,8 @@
1
1
  process.env.SELF_HOSTED = "0"
2
2
  process.env.NODE_ENV = "jest"
3
3
  process.env.JWT_SECRET = "test-jwtsecret"
4
- process.env.LOG_LEVEL = "silent"
4
+ process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
5
+ process.env.ENABLE_4XX_HTTP_LOGGING = "0"
5
6
  process.env.MULTI_TENANCY = "1"
6
7
  process.env.MINIO_URL = "http://localhost"
7
8
  process.env.MINIO_ACCESS_KEY = "test"
@@ -1,4 +1,8 @@
1
- import { mocks } from "@budibase/backend-core/tests"
1
+ import "./logging"
2
+
3
+ import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
4
+ import env from "../environment"
5
+ import { env as coreEnv } from "@budibase/backend-core"
2
6
 
3
7
  // must explicitly enable fetch mock
4
8
  mocks.fetch.enable()
@@ -8,12 +12,12 @@ mocks.fetch.enable()
8
12
  const tk = require("timekeeper")
9
13
  tk.freeze(mocks.date.MOCK_DATE)
10
14
 
11
- if (!process.env.DEBUG) {
12
- global.console.log = jest.fn() // console.log are ignored in tests
13
- }
14
-
15
15
  if (!process.env.CI) {
16
16
  // set a longer timeout in dev for debugging
17
17
  // 100 seconds
18
- jest.setTimeout(100000)
18
+ jest.setTimeout(100 * 1000)
19
+ } else {
20
+ jest.setTimeout(10 * 1000)
19
21
  }
22
+
23
+ testContainerUtils.setupEnv(env, coreEnv)
@@ -0,0 +1,34 @@
1
+ export enum LogLevel {
2
+ TRACE = "trace",
3
+ DEBUG = "debug",
4
+ INFO = "info",
5
+ WARN = "warn",
6
+ ERROR = "error",
7
+ }
8
+
9
+ const LOG_INDEX: { [key in LogLevel]: number } = {
10
+ [LogLevel.TRACE]: 1,
11
+ [LogLevel.DEBUG]: 2,
12
+ [LogLevel.INFO]: 3,
13
+ [LogLevel.WARN]: 4,
14
+ [LogLevel.ERROR]: 5,
15
+ }
16
+
17
+ const setIndex = LOG_INDEX[process.env.LOG_LEVEL as LogLevel]
18
+
19
+ if (setIndex > LOG_INDEX.trace) {
20
+ global.console.trace = jest.fn()
21
+ }
22
+
23
+ if (setIndex > LOG_INDEX.debug) {
24
+ global.console.debug = jest.fn()
25
+ }
26
+
27
+ if (setIndex > LOG_INDEX.info) {
28
+ global.console.info = jest.fn()
29
+ global.console.log = jest.fn()
30
+ }
31
+
32
+ if (setIndex > LOG_INDEX.warn) {
33
+ global.console.warn = jest.fn()
34
+ }
@@ -1,20 +1,16 @@
1
1
  import { structures } from "@budibase/backend-core/tests"
2
2
  import * as configs from "./configs"
3
- import * as users from "./users"
4
3
  import * as groups from "./groups"
5
4
  import { v4 as uuid } from "uuid"
6
5
 
7
6
  export const TENANT_ID = "default"
8
- export const TENANT_1 = "tenant1"
9
7
  export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
8
 
11
9
  const pkg = {
12
10
  ...structures,
13
11
  uuid,
14
12
  configs,
15
- users,
16
13
  TENANT_ID,
17
- TENANT_1,
18
14
  CSRF_TOKEN,
19
15
  groups,
20
16
  }
@@ -26,7 +26,7 @@ type SendEmailOpts = {
26
26
  automation?: boolean
27
27
  }
28
28
 
29
- const TEST_MODE = false
29
+ const TEST_MODE = env.ENABLE_EMAIL_TEST_MODE && env.isDev()
30
30
  const TYPE = TemplateType.EMAIL
31
31
 
32
32
  const FULL_EMAIL_PURPOSES = [
@@ -62,8 +62,8 @@ function createSMTPTransport(config: any) {
62
62
  host: "smtp.ethereal.email",
63
63
  secure: false,
64
64
  auth: {
65
- user: "don.bahringer@ethereal.email",
66
- pass: "yCKSH8rWyUPbnhGYk9",
65
+ user: "wyatt.zulauf29@ethereal.email",
66
+ pass: "tEwDtHBWWxusVWAPfa",
67
67
  },
68
68
  }
69
69
  }