@budibase/worker 2.1.43-alpha.1 → 2.1.43

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 (208) hide show
  1. package/package.json +24 -14
  2. package/{src/tests/jestSetup.ts → scripts/jestSetup.js} +3 -12
  3. package/scripts/localdomain.js +7 -33
  4. package/src/api/controllers/global/auth.ts +43 -51
  5. package/src/api/controllers/global/{configs.ts → configs.js} +114 -119
  6. package/src/api/controllers/global/{email.ts → email.js} +5 -6
  7. package/src/api/controllers/global/roles.js +68 -0
  8. package/src/api/controllers/global/self.ts +2 -2
  9. package/src/api/controllers/global/users.ts +2 -4
  10. package/src/api/controllers/global/{workspaces.ts → workspaces.js} +18 -15
  11. package/src/api/controllers/system/{environment.ts → environment.js} +2 -3
  12. package/src/api/controllers/system/restore.ts +1 -1
  13. package/src/api/controllers/system/{status.ts → status.js} +3 -4
  14. package/src/api/controllers/system/tenants.ts +51 -8
  15. package/src/api/index.ts +8 -31
  16. package/src/api/routes/global/{auth.ts → auth.js} +48 -31
  17. package/src/api/routes/global/{configs.ts → configs.js} +23 -22
  18. package/src/api/routes/global/{email.ts → email.js} +10 -9
  19. package/src/api/routes/global/license.ts +1 -1
  20. package/src/api/routes/global/roles.js +12 -0
  21. package/src/api/routes/global/self.ts +2 -2
  22. package/src/api/routes/global/templates.ts +4 -4
  23. package/src/api/routes/global/tests/auth.spec.ts +64 -134
  24. package/src/api/routes/global/tests/configs.spec.ts +35 -34
  25. package/src/api/routes/global/tests/email.spec.ts +3 -4
  26. package/src/api/routes/global/tests/realEmail.spec.ts +3 -2
  27. package/src/api/routes/global/tests/self.spec.ts +4 -3
  28. package/src/api/routes/global/tests/users.spec.ts +45 -61
  29. package/src/api/routes/global/{users.ts → users.js} +26 -28
  30. package/src/api/routes/global/{workspaces.ts → workspaces.js} +10 -9
  31. package/src/api/routes/index.ts +1 -2
  32. package/src/api/routes/system/accounts.ts +1 -1
  33. package/src/api/routes/system/environment.js +8 -0
  34. package/src/api/routes/system/migrations.ts +1 -1
  35. package/src/api/routes/system/restore.ts +1 -1
  36. package/src/api/routes/system/status.js +8 -0
  37. package/src/api/routes/system/tenants.js +12 -0
  38. package/src/api/routes/system/tests/accounts.spec.ts +6 -5
  39. package/src/api/routes/validation/users.ts +3 -3
  40. package/src/constants/{index.ts → index.js} +64 -57
  41. package/src/constants/templates/{index.ts → index.js} +19 -23
  42. package/src/db/index.js +11 -0
  43. package/src/environment.ts +7 -9
  44. package/src/index.ts +16 -15
  45. package/src/middleware/{cloudRestricted.ts → cloudRestricted.js} +4 -5
  46. package/src/tests/TestConfiguration.ts +50 -99
  47. package/src/tests/api/accounts.ts +8 -5
  48. package/src/tests/api/auth.ts +6 -3
  49. package/src/tests/api/configs.ts +8 -15
  50. package/src/tests/api/email.ts +6 -3
  51. package/src/tests/api/index.ts +0 -15
  52. package/src/tests/api/self.ts +6 -11
  53. package/src/tests/api/users.ts +6 -38
  54. package/src/tests/controllers.js +7 -0
  55. package/src/tests/index.ts +1 -5
  56. package/src/tests/structures/accounts.ts +24 -0
  57. package/src/tests/structures/{configs.ts → configs.js} +11 -11
  58. package/src/tests/structures/index.ts +3 -5
  59. package/src/tests/structures/users.ts +0 -1
  60. package/src/utilities/appService.js +33 -0
  61. package/src/utilities/{email.ts → email.js} +45 -78
  62. package/src/utilities/fileSystem.js +5 -0
  63. package/src/utilities/{index.ts → index.js} +1 -1
  64. package/src/utilities/{redis.ts → redis.js} +24 -29
  65. package/src/utilities/templates.js +49 -0
  66. package/src/utilities/users.js +17 -0
  67. package/tsconfig.build.json +3 -2
  68. package/tsconfig.json +1 -3
  69. package/__mocks__/aws-sdk.ts +0 -15
  70. package/__mocks__/oauth.ts +0 -57
  71. package/coverage/clover.xml +0 -2157
  72. package/coverage/coverage-final.json +0 -78
  73. package/coverage/lcov-report/base.css +0 -224
  74. package/coverage/lcov-report/block-navigation.js +0 -87
  75. package/coverage/lcov-report/favicon.png +0 -0
  76. package/coverage/lcov-report/index.html +0 -431
  77. package/coverage/lcov-report/prettify.css +0 -1
  78. package/coverage/lcov-report/prettify.js +0 -2
  79. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  80. package/coverage/lcov-report/sorter.js +0 -196
  81. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -925
  82. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1405
  83. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
  84. package/coverage/lcov-report/src/api/controllers/global/index.html +0 -236
  85. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
  86. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
  87. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
  88. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
  89. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -796
  90. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
  91. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
  92. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
  93. package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
  94. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
  95. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
  96. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
  97. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
  98. package/coverage/lcov-report/src/api/index.html +0 -116
  99. package/coverage/lcov-report/src/api/index.ts.html +0 -583
  100. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
  101. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
  102. package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
  103. package/coverage/lcov-report/src/api/routes/global/index.html +0 -236
  104. package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
  105. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
  106. package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
  107. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
  108. package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -433
  109. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
  110. package/coverage/lcov-report/src/api/routes/index.html +0 -116
  111. package/coverage/lcov-report/src/api/routes/index.ts.html +0 -196
  112. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
  113. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
  114. package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
  115. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
  116. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
  117. package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
  118. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
  119. package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
  120. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
  121. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
  122. package/coverage/lcov-report/src/constants/index.html +0 -116
  123. package/coverage/lcov-report/src/constants/index.ts.html +0 -613
  124. package/coverage/lcov-report/src/constants/templates/index.html +0 -116
  125. package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
  126. package/coverage/lcov-report/src/db/index.html +0 -116
  127. package/coverage/lcov-report/src/db/index.ts.html +0 -115
  128. package/coverage/lcov-report/src/environment.ts.html +0 -373
  129. package/coverage/lcov-report/src/index.html +0 -131
  130. package/coverage/lcov-report/src/index.ts.html +0 -394
  131. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
  132. package/coverage/lcov-report/src/middleware/index.html +0 -116
  133. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
  134. package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
  135. package/coverage/lcov-report/src/migrations/index.html +0 -116
  136. package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
  137. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
  138. package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
  139. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
  140. package/coverage/lcov-report/src/sdk/index.html +0 -116
  141. package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
  142. package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -577
  143. package/coverage/lcov-report/src/sdk/users/index.html +0 -146
  144. package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
  145. package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1903
  146. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1051
  147. package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
  148. package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
  149. package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
  150. package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
  151. package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
  152. package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
  153. package/coverage/lcov-report/src/tests/api/index.html +0 -296
  154. package/coverage/lcov-report/src/tests/api/index.ts.html +0 -205
  155. package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
  156. package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
  157. package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
  158. package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
  159. package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
  160. package/coverage/lcov-report/src/tests/api/users.ts.html +0 -511
  161. package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
  162. package/coverage/lcov-report/src/tests/index.html +0 -146
  163. package/coverage/lcov-report/src/tests/index.ts.html +0 -139
  164. package/coverage/lcov-report/src/tests/mocks/email.js.html +0 -115
  165. package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
  166. package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
  167. package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
  168. package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
  169. package/coverage/lcov-report/src/tests/structures/index.html +0 -161
  170. package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
  171. package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
  172. package/coverage/lcov-report/src/utilities/appService.ts.html +0 -181
  173. package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
  174. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
  175. package/coverage/lcov-report/src/utilities/index.html +0 -206
  176. package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
  177. package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
  178. package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
  179. package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
  180. package/coverage/lcov.info +0 -3970
  181. package/jest.config.ts +0 -29
  182. package/src/api/controllers/global/roles.ts +0 -66
  183. package/src/api/routes/global/roles.ts +0 -16
  184. package/src/api/routes/global/tests/license.spec.ts +0 -31
  185. package/src/api/routes/global/tests/roles.spec.ts +0 -27
  186. package/src/api/routes/global/tests/templates.spec.ts +0 -35
  187. package/src/api/routes/global/tests/workspaces.spec.ts +0 -29
  188. package/src/api/routes/system/environment.ts +0 -8
  189. package/src/api/routes/system/status.ts +0 -8
  190. package/src/api/routes/system/tenants.ts +0 -13
  191. package/src/api/routes/system/tests/environment.spec.ts +0 -29
  192. package/src/api/routes/system/tests/migrations.spec.ts +0 -63
  193. package/src/api/routes/system/tests/restore.spec.ts +0 -36
  194. package/src/api/routes/system/tests/status.spec.ts +0 -48
  195. package/src/api/routes/system/tests/tenants.spec.ts +0 -61
  196. package/src/db/index.ts +0 -10
  197. package/src/middleware/tests/tenancy.spec.ts +0 -73
  198. package/src/tests/api/base.ts +0 -16
  199. package/src/tests/api/environment.ts +0 -15
  200. package/src/tests/api/migrations.ts +0 -22
  201. package/src/tests/api/restore.ts +0 -14
  202. package/src/tests/api/status.ts +0 -12
  203. package/src/tests/api/tenants.ts +0 -15
  204. package/src/tests/controllers.ts +0 -5
  205. package/src/utilities/appService.ts +0 -32
  206. package/src/utilities/fileSystem.ts +0 -5
  207. package/src/utilities/templates.ts +0 -49
  208. package/src/utilities/users.ts +0 -16
@@ -1,42 +1,41 @@
1
1
  import "./mocks"
2
- import * as dbConfig from "../db"
2
+ import dbConfig from "../db"
3
3
  dbConfig.init()
4
4
  import env from "../environment"
5
- import * as controllers from "./controllers"
5
+ import controllers from "./controllers"
6
6
  const supertest = require("supertest")
7
- import { Config } from "../constants"
7
+ import { Configs } from "../constants"
8
8
  import {
9
9
  users,
10
10
  tenancy,
11
+ Cookies,
12
+ Headers,
11
13
  sessions,
12
14
  auth,
13
- constants,
14
- env as coreEnv,
15
15
  } from "@budibase/backend-core"
16
- import structures, { TENANT_ID, TENANT_1, CSRF_TOKEN } from "./structures"
16
+ import { TENANT_ID, TENANT_1, CSRF_TOKEN } from "./structures"
17
+ import structures from "./structures"
17
18
  import { CreateUserResponse, User, AuthToken } from "@budibase/types"
18
- import API from "./api"
19
19
 
20
20
  enum Mode {
21
- CLOUD = "cloud",
21
+ ACCOUNT = "account",
22
22
  SELF = "self",
23
23
  }
24
24
 
25
25
  class TestConfiguration {
26
26
  server: any
27
27
  request: any
28
- api: API
29
28
  defaultUser?: User
30
29
  tenant1User?: User
31
30
 
32
31
  constructor(
33
32
  opts: { openServer: boolean; mode: Mode } = {
34
33
  openServer: true,
35
- mode: Mode.CLOUD,
34
+ mode: Mode.ACCOUNT,
36
35
  }
37
36
  ) {
38
- if (opts.mode === Mode.CLOUD) {
39
- this.modeCloud()
37
+ if (opts.mode === Mode.ACCOUNT) {
38
+ this.modeAccount()
40
39
  } else if (opts.mode === Mode.SELF) {
41
40
  this.modeSelf()
42
41
  }
@@ -47,8 +46,6 @@ class TestConfiguration {
47
46
  // we need the request for logging in, involves cookies, hard to fake
48
47
  this.request = supertest(this.server)
49
48
  }
50
-
51
- this.api = new API(this)
52
49
  }
53
50
 
54
51
  getRequest() {
@@ -57,24 +54,20 @@ class TestConfiguration {
57
54
 
58
55
  // MODES
59
56
 
60
- setMultiTenancy = (value: boolean) => {
61
- env._set("MULTI_TENANCY", value)
62
- coreEnv._set("MULTI_TENANCY", value)
63
- }
64
-
65
- setSelfHosted = (value: boolean) => {
66
- env._set("SELF_HOSTED", value)
67
- coreEnv._set("SELF_HOSTED", value)
68
- }
69
-
70
- modeCloud = () => {
71
- this.setSelfHosted(false)
72
- this.setMultiTenancy(true)
57
+ modeAccount = () => {
58
+ env.SELF_HOSTED = false
59
+ // @ts-ignore
60
+ env.MULTI_TENANCY = true
61
+ // @ts-ignore
62
+ env.DISABLE_ACCOUNT_PORTAL = false
73
63
  }
74
64
 
75
65
  modeSelf = () => {
76
- this.setSelfHosted(true)
77
- this.setMultiTenancy(false)
66
+ env.SELF_HOSTED = true
67
+ // @ts-ignore
68
+ env.MULTI_TENANCY = false
69
+ // @ts-ignore
70
+ env.DISABLE_ACCOUNT_PORTAL = true
78
71
  }
79
72
 
80
73
  // UTILS
@@ -121,25 +114,6 @@ class TestConfiguration {
121
114
 
122
115
  // TENANCY
123
116
 
124
- createTenant = async (): Promise<User> => {
125
- // create user / new tenant
126
- const res = await this.api.users.createAdminUser()
127
-
128
- // return the created user
129
- const userRes = await this.api.users.getUser(res.userId, {
130
- headers: {
131
- ...this.internalAPIHeaders(),
132
- [constants.Header.TENANT_ID]: res.tenantId,
133
- },
134
- })
135
-
136
- // create a session for the new user
137
- const user = userRes.body
138
- await this.createSession(user)
139
-
140
- return user
141
- }
142
-
143
117
  getTenantId() {
144
118
  try {
145
119
  return tenancy.getTenantId()
@@ -148,32 +122,35 @@ class TestConfiguration {
148
122
  }
149
123
  }
150
124
 
151
- // AUTH
125
+ // USER / AUTH
152
126
 
153
- async _createSession({
154
- userId,
155
- tenantId,
156
- }: {
157
- userId: string
158
- tenantId: string
159
- }) {
160
- await sessions.createASession(userId!, {
161
- sessionId: "sessionid",
162
- tenantId: tenantId,
163
- csrfToken: CSRF_TOKEN,
127
+ async createDefaultUser() {
128
+ const user = structures.users.adminUser({
129
+ email: "test@test.com",
130
+ password: "test",
164
131
  })
132
+ this.defaultUser = await this.createUser(user)
133
+ }
134
+
135
+ async createTenant1User() {
136
+ const user = structures.users.adminUser({
137
+ email: "tenant1@test.com",
138
+ password: "test",
139
+ })
140
+ this.tenant1User = await this.createUser(user)
165
141
  }
166
142
 
167
143
  async createSession(user: User) {
168
- return this._createSession({ userId: user._id!, tenantId: user.tenantId })
144
+ await sessions.createASession(user._id!, {
145
+ sessionId: "sessionid",
146
+ tenantId: user.tenantId,
147
+ csrfToken: CSRF_TOKEN,
148
+ })
169
149
  }
170
150
 
171
151
  cookieHeader(cookies: any) {
172
- if (!Array.isArray(cookies)) {
173
- cookies = [cookies]
174
- }
175
152
  return {
176
- Cookie: cookies,
153
+ Cookie: [cookies],
177
154
  }
178
155
  }
179
156
 
@@ -186,8 +163,8 @@ class TestConfiguration {
186
163
  const authCookie = auth.jwt.sign(authToken, env.JWT_SECRET)
187
164
  return {
188
165
  Accept: "application/json",
189
- ...this.cookieHeader([`${constants.Cookie.Auth}=${authCookie}`]),
190
- [constants.Header.CSRF_TOKEN]: CSRF_TOKEN,
166
+ ...this.cookieHeader([`${Cookies.Auth}=${authCookie}`]),
167
+ [Headers.CSRF_TOKEN]: CSRF_TOKEN,
191
168
  }
192
169
  }
193
170
 
@@ -202,32 +179,6 @@ class TestConfiguration {
202
179
  }
203
180
  }
204
181
 
205
- internalAPIHeaders() {
206
- return { [constants.Header.API_KEY]: env.INTERNAL_API_KEY }
207
- }
208
-
209
- adminOnlyResponse = () => {
210
- return { message: "Admin user only endpoint.", status: 403 }
211
- }
212
-
213
- // USERS
214
-
215
- async createDefaultUser() {
216
- const user = structures.users.adminUser({
217
- email: "test@test.com",
218
- password: "test",
219
- })
220
- this.defaultUser = await this.createUser(user)
221
- }
222
-
223
- async createTenant1User() {
224
- const user = structures.users.adminUser({
225
- email: "tenant1@test.com",
226
- password: "test",
227
- })
228
- this.tenant1User = await this.createUser(user)
229
- }
230
-
231
182
  async getUser(email: string): Promise<User> {
232
183
  return tenancy.doInTenant(this.getTenantId(), () => {
233
184
  return users.getGlobalUserByEmail(email)
@@ -272,7 +223,7 @@ class TestConfiguration {
272
223
  // CONFIGS - SETTINGS
273
224
 
274
225
  async saveSettingsConfig() {
275
- await this.deleteConfig(Config.SETTINGS)
226
+ await this.deleteConfig(Configs.SETTINGS)
276
227
  await this._req(
277
228
  structures.configs.settings(),
278
229
  null,
@@ -283,7 +234,7 @@ class TestConfiguration {
283
234
  // CONFIGS - GOOGLE
284
235
 
285
236
  async saveGoogleConfig() {
286
- await this.deleteConfig(Config.GOOGLE)
237
+ await this.deleteConfig(Configs.GOOGLE)
287
238
  await this._req(structures.configs.google(), null, controllers.config.save)
288
239
  }
289
240
 
@@ -291,11 +242,11 @@ class TestConfiguration {
291
242
 
292
243
  getOIDConfigCookie(configId: string) {
293
244
  const token = auth.jwt.sign(configId, env.JWT_SECRET)
294
- return this.cookieHeader([[`${constants.Cookie.OIDC_CONFIG}=${token}`]])
245
+ return this.cookieHeader([[`${Cookies.OIDC_CONFIG}=${token}`]])
295
246
  }
296
247
 
297
248
  async saveOIDCConfig() {
298
- await this.deleteConfig(Config.OIDC)
249
+ await this.deleteConfig(Configs.OIDC)
299
250
  const config = structures.configs.oidc()
300
251
 
301
252
  await this._req(config, null, controllers.config.save)
@@ -305,12 +256,12 @@ class TestConfiguration {
305
256
  // CONFIGS - SMTP
306
257
 
307
258
  async saveSmtpConfig() {
308
- await this.deleteConfig(Config.SMTP)
259
+ await this.deleteConfig(Configs.SMTP)
309
260
  await this._req(structures.configs.smtp(), null, controllers.config.save)
310
261
  }
311
262
 
312
263
  async saveEtherealSmtpConfig() {
313
- await this.deleteConfig(Config.SMTP)
264
+ await this.deleteConfig(Configs.SMTP)
314
265
  await this._req(
315
266
  structures.configs.smtpEthereal(),
316
267
  null,
@@ -1,17 +1,20 @@
1
1
  import { Account, AccountMetadata } from "@budibase/types"
2
2
  import TestConfiguration from "../TestConfiguration"
3
- import { TestAPI } from "./base"
4
3
 
5
- export class AccountAPI extends TestAPI {
4
+ export class AccountAPI {
5
+ config: TestConfiguration
6
+ request: any
7
+
6
8
  constructor(config: TestConfiguration) {
7
- super(config)
9
+ this.config = config
10
+ this.request = config.request
8
11
  }
9
12
 
10
13
  saveMetadata = async (account: Account) => {
11
14
  const res = await this.request
12
15
  .put(`/api/system/accounts/${account.accountId}/metadata`)
13
16
  .send(account)
14
- .set(this.config.internalAPIHeaders())
17
+ .set(this.config.defaultHeaders())
15
18
  .expect("Content-Type", /json/)
16
19
  .expect(200)
17
20
  return res.body as AccountMetadata
@@ -20,6 +23,6 @@ export class AccountAPI extends TestAPI {
20
23
  destroyMetadata = (accountId: string) => {
21
24
  return this.request
22
25
  .del(`/api/system/accounts/${accountId}/metadata`)
23
- .set(this.config.internalAPIHeaders())
26
+ .set(this.config.defaultHeaders())
24
27
  }
25
28
  }
@@ -1,9 +1,12 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
3
2
 
4
- export class AuthAPI extends TestAPI {
3
+ export class AuthAPI {
4
+ config: TestConfiguration
5
+ request: any
6
+
5
7
  constructor(config: TestConfiguration) {
6
- super(config)
8
+ this.config = config
9
+ this.request = config.request
7
10
  }
8
11
 
9
12
  updatePassword = (code: string) => {
@@ -1,9 +1,12 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
3
2
 
4
- export class ConfigAPI extends TestAPI {
3
+ export class ConfigAPI {
4
+ config: TestConfiguration
5
+ request: any
6
+
5
7
  constructor(config: TestConfiguration) {
6
- super(config)
8
+ this.config = config
9
+ this.request = config.request
7
10
  }
8
11
 
9
12
  getConfigChecklist = () => {
@@ -23,20 +26,10 @@ export class ConfigAPI extends TestAPI {
23
26
  .expect(200)
24
27
  }
25
28
 
26
- OIDCCallback = (configId: string, preAuthRes: any) => {
27
- const cookie = this.config.cookieHeader(preAuthRes.get("set-cookie"))
28
- const setKoaSession = cookie.Cookie.find((c: string) =>
29
- c.includes("koa:sess")
30
- )
31
- const koaSession = setKoaSession.split("=")[1] + "=="
32
- const sessionContent = JSON.parse(
33
- Buffer.from(koaSession, "base64").toString("utf-8")
34
- )
35
- const handle = sessionContent["openidconnect:localhost"].state.handle
29
+ OIDCCallback = (configId: string) => {
36
30
  return this.request
37
31
  .get(`/api/global/auth/${this.config.getTenantId()}/oidc/callback`)
38
- .query({ code: "test", state: handle })
39
- .set(cookie)
32
+ .set(this.config.getOIDConfigCookie(configId))
40
33
  }
41
34
 
42
35
  getOIDCConfig = (configId: string) => {
@@ -1,9 +1,12 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
3
2
 
4
- export class EmailAPI extends TestAPI {
3
+ export class EmailAPI {
4
+ config: TestConfiguration
5
+ request: any
6
+
5
7
  constructor(config: TestConfiguration) {
6
- super(config)
8
+ this.config = config
9
+ this.request = config.request
7
10
  }
8
11
 
9
12
  sendEmail = (purpose: string) => {
@@ -5,11 +5,6 @@ import { ConfigAPI } from "./configs"
5
5
  import { EmailAPI } from "./email"
6
6
  import { SelfAPI } from "./self"
7
7
  import { UserAPI } from "./users"
8
- import { EnvironmentAPI } from "./environment"
9
- import { MigrationAPI } from "./migrations"
10
- import { StatusAPI } from "./status"
11
- import { RestoreAPI } from "./restore"
12
- import { TenantAPI } from "./tenants"
13
8
 
14
9
  export default class API {
15
10
  accounts: AccountAPI
@@ -18,11 +13,6 @@ export default class API {
18
13
  emails: EmailAPI
19
14
  self: SelfAPI
20
15
  users: UserAPI
21
- environment: EnvironmentAPI
22
- migrations: MigrationAPI
23
- status: StatusAPI
24
- restore: RestoreAPI
25
- tenants: TenantAPI
26
16
 
27
17
  constructor(config: TestConfiguration) {
28
18
  this.accounts = new AccountAPI(config)
@@ -31,10 +21,5 @@ export default class API {
31
21
  this.emails = new EmailAPI(config)
32
22
  this.self = new SelfAPI(config)
33
23
  this.users = new UserAPI(config)
34
- this.environment = new EnvironmentAPI(config)
35
- this.migrations = new MigrationAPI(config)
36
- this.status = new StatusAPI(config)
37
- this.restore = new RestoreAPI(config)
38
- this.tenants = new TenantAPI(config)
39
24
  }
40
25
  }
@@ -1,10 +1,13 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
2
  import { User } from "@budibase/types"
3
- import { TestAPI } from "./base"
4
3
 
5
- export class SelfAPI extends TestAPI {
4
+ export class SelfAPI {
5
+ config: TestConfiguration
6
+ request: any
7
+
6
8
  constructor(config: TestConfiguration) {
7
- super(config)
9
+ this.config = config
10
+ this.request = config.request
8
11
  }
9
12
 
10
13
  updateSelf = (user: User) => {
@@ -15,12 +18,4 @@ export class SelfAPI extends TestAPI {
15
18
  .expect("Content-Type", /json/)
16
19
  .expect(200)
17
20
  }
18
-
19
- getSelf = (user: User) => {
20
- return this.request
21
- .get(`/api/global/self`)
22
- .set(this.config.authHeaders(user))
23
- .expect("Content-Type", /json/)
24
- .expect(200)
25
- }
26
21
  }
@@ -3,16 +3,16 @@ import {
3
3
  BulkUserRequest,
4
4
  InviteUsersRequest,
5
5
  User,
6
- CreateAdminUserRequest,
7
6
  } from "@budibase/types"
8
- import * as structures from "../structures"
9
- import { generator } from "@budibase/backend-core/tests"
10
7
  import TestConfiguration from "../TestConfiguration"
11
- import { TestAPI, TestAPIOpts } from "./base"
12
8
 
13
- export class UserAPI extends TestAPI {
9
+ export class UserAPI {
10
+ config: TestConfiguration
11
+ request: any
12
+
14
13
  constructor(config: TestConfiguration) {
15
- super(config)
14
+ this.config = config
15
+ this.request = config.request
16
16
  }
17
17
 
18
18
  // INVITE
@@ -91,30 +91,6 @@ export class UserAPI extends TestAPI {
91
91
 
92
92
  // USER
93
93
 
94
- createAdminUser = async (
95
- request?: CreateAdminUserRequest,
96
- opts?: TestAPIOpts
97
- ) => {
98
- if (!request) {
99
- request = {
100
- email: structures.email(),
101
- password: generator.string(),
102
- tenantId: structures.uuid(),
103
- }
104
- }
105
- const res = await this.request
106
- .post(`/api/global/users/init`)
107
- .send(request)
108
- .set(this.config.internalAPIHeaders())
109
- .expect("Content-Type", /json/)
110
- .expect(opts?.status ? opts.status : 200)
111
-
112
- return {
113
- ...request,
114
- userId: res.body._id,
115
- }
116
- }
117
-
118
94
  saveUser = (user: User, status?: number, headers?: any) => {
119
95
  return this.request
120
96
  .post(`/api/global/users`)
@@ -131,12 +107,4 @@ export class UserAPI extends TestAPI {
131
107
  .expect("Content-Type", /json/)
132
108
  .expect(status ? status : 200)
133
109
  }
134
-
135
- getUser = (userId: string, opts?: TestAPIOpts) => {
136
- return this.request
137
- .get(`/api/global/users/${userId}`)
138
- .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
139
- .expect("Content-Type", /json/)
140
- .expect(opts?.status ? opts.status : 200)
141
- }
142
110
  }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ email: require("../api/controllers/global/email"),
3
+ workspaces: require("../api/controllers/global/workspaces"),
4
+ config: require("../api/controllers/global/configs"),
5
+ templates: require("../api/controllers/global/templates"),
6
+ users: require("../api/controllers/global/users"),
7
+ }
@@ -1,14 +1,10 @@
1
- import mocks from "./mocks"
2
- import { generator } from "@budibase/backend-core/tests"
3
1
  import TestConfiguration from "./TestConfiguration"
4
2
  import structures from "./structures"
3
+ import mocks from "./mocks"
5
4
  import API from "./api"
6
- import { v4 as uuid } from "uuid"
7
5
 
8
6
  const pkg = {
9
7
  structures,
10
- generator,
11
- uuid,
12
8
  TENANT_1: structures.TENANT_1,
13
9
  mocks,
14
10
  TestConfiguration,
@@ -0,0 +1,24 @@
1
+ import { Account, AuthType, Hosting, CloudAccount } from "@budibase/types"
2
+ import { v4 as uuid } from "uuid"
3
+ import { utils } from "@budibase/backend-core"
4
+
5
+ export const account = (): Account => {
6
+ return {
7
+ email: `${uuid()}@test.com`,
8
+ tenantId: utils.newid(),
9
+ hosting: Hosting.SELF,
10
+ authType: AuthType.SSO,
11
+ accountId: uuid(),
12
+ createdAt: Date.now(),
13
+ verified: true,
14
+ verificationSent: true,
15
+ tier: "FREE",
16
+ }
17
+ }
18
+
19
+ export const cloudAccount = (): CloudAccount => {
20
+ return {
21
+ ...account(),
22
+ budibaseUserId: uuid(),
23
+ }
24
+ }
@@ -1,9 +1,9 @@
1
- const { Config } = require("../../constants")
1
+ const { Configs } = require("../../constants")
2
2
  const { utils } = require("@budibase/backend-core")
3
3
 
4
- export function oidc(conf?: any) {
4
+ exports.oidc = conf => {
5
5
  return {
6
- type: Config.OIDC,
6
+ type: Configs.OIDC,
7
7
  config: {
8
8
  configs: [
9
9
  {
@@ -21,9 +21,9 @@ export function oidc(conf?: any) {
21
21
  }
22
22
  }
23
23
 
24
- export function google(conf?: any) {
24
+ exports.google = conf => {
25
25
  return {
26
- type: Config.GOOGLE,
26
+ type: Configs.GOOGLE,
27
27
  config: {
28
28
  clientID: "clientId",
29
29
  clientSecret: "clientSecret",
@@ -33,9 +33,9 @@ export function google(conf?: any) {
33
33
  }
34
34
  }
35
35
 
36
- export function smtp(conf?: any) {
36
+ exports.smtp = conf => {
37
37
  return {
38
- type: Config.SMTP,
38
+ type: Configs.SMTP,
39
39
  config: {
40
40
  port: 12345,
41
41
  host: "smtptesthost.com",
@@ -47,9 +47,9 @@ export function smtp(conf?: any) {
47
47
  }
48
48
  }
49
49
 
50
- export function smtpEthereal() {
50
+ exports.smtpEthereal = () => {
51
51
  return {
52
- type: Config.SMTP,
52
+ type: Configs.SMTP,
53
53
  config: {
54
54
  port: 587,
55
55
  host: "smtp.ethereal.email",
@@ -63,9 +63,9 @@ export function smtpEthereal() {
63
63
  }
64
64
  }
65
65
 
66
- export function settings(conf?: any) {
66
+ exports.settings = conf => {
67
67
  return {
68
- type: Config.SETTINGS,
68
+ type: Configs.SETTINGS,
69
69
  config: {
70
70
  platformUrl: "http://localhost:10000",
71
71
  logoUrl: "",
@@ -1,18 +1,16 @@
1
- import { structures } from "@budibase/backend-core/tests"
2
- import * as configs from "./configs"
1
+ import configs from "./configs"
3
2
  import * as users from "./users"
4
3
  import * as groups from "./groups"
5
- import { v4 as uuid } from "uuid"
4
+ import * as accounts from "./accounts"
6
5
 
7
6
  const TENANT_ID = "default"
8
7
  const TENANT_1 = "tenant1"
9
8
  const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
9
 
11
10
  const pkg = {
12
- ...structures,
13
- uuid,
14
11
  configs,
15
12
  users,
13
+ accounts,
16
14
  TENANT_ID,
17
15
  TENANT_1,
18
16
  CSRF_TOKEN,
@@ -5,7 +5,6 @@ import { v4 as uuid } from "uuid"
5
5
  export const newEmail = () => {
6
6
  return `${uuid()}@test.com`
7
7
  }
8
-
9
8
  export const user = (userProps?: any): User => {
10
9
  return {
11
10
  email: newEmail(),
@@ -0,0 +1,33 @@
1
+ const fetch = require("node-fetch")
2
+ const { Headers } = require("@budibase/backend-core/constants")
3
+ const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
4
+ const { checkSlashesInUrl } = require("../utilities")
5
+ const env = require("../environment")
6
+
7
+ async function makeAppRequest(url, method, body) {
8
+ if (env.isTest()) {
9
+ return
10
+ }
11
+ const request = { headers: {} }
12
+ request.headers[Headers.API_KEY] = env.INTERNAL_API_KEY
13
+ if (isTenantIdSet()) {
14
+ request.headers[Headers.TENANT_ID] = getTenantId()
15
+ }
16
+ if (body) {
17
+ request.headers["Content-Type"] = "application/json"
18
+ request.body = JSON.stringify(body)
19
+ }
20
+ request.method = method
21
+ return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
22
+ }
23
+
24
+ exports.syncUserInApps = async userId => {
25
+ const response = await makeAppRequest(
26
+ `/api/users/metadata/sync/${userId}`,
27
+ "POST",
28
+ {}
29
+ )
30
+ if (response && response.status !== 200) {
31
+ throw "Unable to sync user."
32
+ }
33
+ }