@budibase/worker 2.1.32-alpha.8 → 2.1.33

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 (182) hide show
  1. package/package.json +23 -13
  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 +31 -35
  5. package/src/api/controllers/global/configs.js +17 -17
  6. package/src/api/controllers/global/self.ts +2 -2
  7. package/src/api/controllers/global/users.ts +1 -3
  8. package/src/api/controllers/system/{environment.ts → environment.js} +2 -3
  9. package/src/api/controllers/system/{status.ts → status.js} +3 -4
  10. package/src/api/controllers/system/tenants.ts +51 -8
  11. package/src/api/index.ts +6 -29
  12. package/src/api/routes/global/auth.js +39 -22
  13. package/src/api/routes/global/configs.js +9 -9
  14. package/src/api/routes/global/templates.ts +2 -2
  15. package/src/api/routes/global/tests/auth.spec.ts +64 -134
  16. package/src/api/routes/global/tests/configs.spec.ts +35 -34
  17. package/src/api/routes/global/tests/email.spec.ts +3 -4
  18. package/src/api/routes/global/tests/realEmail.spec.ts +3 -2
  19. package/src/api/routes/global/tests/self.spec.ts +4 -3
  20. package/src/api/routes/global/tests/users.spec.ts +43 -51
  21. package/src/api/routes/system/environment.js +8 -0
  22. package/src/api/routes/system/status.js +8 -0
  23. package/src/api/routes/system/tenants.js +12 -0
  24. package/src/api/routes/system/tests/accounts.spec.ts +6 -5
  25. package/src/constants/{index.ts → index.js} +64 -57
  26. package/src/constants/templates/index.js +2 -2
  27. package/src/db/index.js +11 -0
  28. package/src/index.ts +1 -1
  29. package/src/middleware/cloudRestricted.js +2 -2
  30. package/src/tests/TestConfiguration.ts +49 -98
  31. package/src/tests/api/accounts.ts +8 -5
  32. package/src/tests/api/auth.ts +6 -3
  33. package/src/tests/api/configs.ts +8 -15
  34. package/src/tests/api/email.ts +6 -3
  35. package/src/tests/api/index.ts +0 -15
  36. package/src/tests/api/self.ts +6 -11
  37. package/src/tests/api/users.ts +6 -38
  38. package/src/tests/index.ts +1 -5
  39. package/src/tests/structures/accounts.ts +24 -0
  40. package/src/tests/structures/configs.js +6 -6
  41. package/src/tests/structures/index.ts +2 -4
  42. package/src/tests/structures/users.ts +0 -1
  43. package/src/utilities/appService.js +3 -3
  44. package/src/utilities/{email.ts → email.js} +45 -78
  45. package/src/utilities/{redis.ts → redis.js} +24 -29
  46. package/src/utilities/templates.js +49 -0
  47. package/tsconfig.build.json +2 -2
  48. package/tsconfig.json +1 -3
  49. package/__mocks__/aws-sdk.ts +0 -15
  50. package/__mocks__/oauth.ts +0 -57
  51. package/coverage/clover.xml +0 -2160
  52. package/coverage/coverage-final.json +0 -78
  53. package/coverage/lcov-report/base.css +0 -224
  54. package/coverage/lcov-report/block-navigation.js +0 -87
  55. package/coverage/lcov-report/favicon.png +0 -0
  56. package/coverage/lcov-report/index.html +0 -431
  57. package/coverage/lcov-report/prettify.css +0 -1
  58. package/coverage/lcov-report/prettify.js +0 -2
  59. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  60. package/coverage/lcov-report/sorter.js +0 -196
  61. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -913
  62. package/coverage/lcov-report/src/api/controllers/global/configs.js.html +0 -1390
  63. package/coverage/lcov-report/src/api/controllers/global/email.js.html +0 -193
  64. package/coverage/lcov-report/src/api/controllers/global/index.html +0 -236
  65. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
  66. package/coverage/lcov-report/src/api/controllers/global/roles.js.html +0 -289
  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 -796
  70. package/coverage/lcov-report/src/api/controllers/global/workspaces.js.html +0 -253
  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 -583
  80. package/coverage/lcov-report/src/api/routes/global/auth.js.html +0 -349
  81. package/coverage/lcov-report/src/api/routes/global/configs.js.html +0 -460
  82. package/coverage/lcov-report/src/api/routes/global/email.js.html +0 -196
  83. package/coverage/lcov-report/src/api/routes/global/index.html +0 -236
  84. package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
  85. package/coverage/lcov-report/src/api/routes/global/roles.js.html +0 -121
  86. package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
  87. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
  88. package/coverage/lcov-report/src/api/routes/global/users.js.html +0 -403
  89. package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +0 -199
  90. package/coverage/lcov-report/src/api/routes/index.html +0 -116
  91. package/coverage/lcov-report/src/api/routes/index.ts.html +0 -193
  92. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
  93. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
  94. package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
  95. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
  96. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
  97. package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
  98. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
  99. package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
  100. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
  101. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
  102. package/coverage/lcov-report/src/constants/index.html +0 -116
  103. package/coverage/lcov-report/src/constants/index.ts.html +0 -613
  104. package/coverage/lcov-report/src/constants/templates/index.html +0 -116
  105. package/coverage/lcov-report/src/constants/templates/index.js.html +0 -304
  106. package/coverage/lcov-report/src/db/index.html +0 -116
  107. package/coverage/lcov-report/src/db/index.ts.html +0 -115
  108. package/coverage/lcov-report/src/environment.ts.html +0 -364
  109. package/coverage/lcov-report/src/index.html +0 -131
  110. package/coverage/lcov-report/src/index.ts.html +0 -397
  111. package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +0 -136
  112. package/coverage/lcov-report/src/middleware/index.html +0 -116
  113. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
  114. package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
  115. package/coverage/lcov-report/src/migrations/index.html +0 -116
  116. package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
  117. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
  118. package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
  119. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
  120. package/coverage/lcov-report/src/sdk/index.html +0 -116
  121. package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
  122. package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -577
  123. package/coverage/lcov-report/src/sdk/users/index.html +0 -146
  124. package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
  125. package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1903
  126. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1051
  127. package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
  128. package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
  129. package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
  130. package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
  131. package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
  132. package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
  133. package/coverage/lcov-report/src/tests/api/index.html +0 -296
  134. package/coverage/lcov-report/src/tests/api/index.ts.html +0 -205
  135. package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
  136. package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
  137. package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
  138. package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
  139. package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
  140. package/coverage/lcov-report/src/tests/api/users.ts.html +0 -511
  141. package/coverage/lcov-report/src/tests/controllers.js.html +0 -106
  142. package/coverage/lcov-report/src/tests/index.html +0 -146
  143. package/coverage/lcov-report/src/tests/index.ts.html +0 -139
  144. package/coverage/lcov-report/src/tests/mocks/email.js.html +0 -115
  145. package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
  146. package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
  147. package/coverage/lcov-report/src/tests/structures/configs.js.html +0 -313
  148. package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
  149. package/coverage/lcov-report/src/tests/structures/index.html +0 -161
  150. package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
  151. package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
  152. package/coverage/lcov-report/src/utilities/appService.js.html +0 -184
  153. package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
  154. package/coverage/lcov-report/src/utilities/fileSystem.js.html +0 -100
  155. package/coverage/lcov-report/src/utilities/index.html +0 -206
  156. package/coverage/lcov-report/src/utilities/index.js.html +0 -112
  157. package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
  158. package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
  159. package/coverage/lcov-report/src/utilities/users.js.html +0 -136
  160. package/coverage/lcov.info +0 -3986
  161. package/jest.config.ts +0 -29
  162. package/src/api/routes/global/tests/license.spec.ts +0 -31
  163. package/src/api/routes/global/tests/roles.spec.ts +0 -27
  164. package/src/api/routes/global/tests/templates.spec.ts +0 -35
  165. package/src/api/routes/global/tests/workspaces.spec.ts +0 -29
  166. package/src/api/routes/system/environment.ts +0 -8
  167. package/src/api/routes/system/status.ts +0 -8
  168. package/src/api/routes/system/tenants.ts +0 -13
  169. package/src/api/routes/system/tests/environment.spec.ts +0 -29
  170. package/src/api/routes/system/tests/migrations.spec.ts +0 -63
  171. package/src/api/routes/system/tests/restore.spec.ts +0 -36
  172. package/src/api/routes/system/tests/status.spec.ts +0 -48
  173. package/src/api/routes/system/tests/tenants.spec.ts +0 -61
  174. package/src/db/index.ts +0 -10
  175. package/src/middleware/tests/tenancy.spec.ts +0 -73
  176. package/src/tests/api/base.ts +0 -16
  177. package/src/tests/api/environment.ts +0 -15
  178. package/src/tests/api/migrations.ts +0 -22
  179. package/src/tests/api/restore.ts +0 -14
  180. package/src/tests/api/status.ts +0 -12
  181. package/src/tests/api/tenants.ts +0 -15
  182. package/src/utilities/templates.ts +0 -49
@@ -1,7 +1,7 @@
1
1
  const { readStaticFile } = require("../../utilities/fileSystem")
2
2
  const {
3
3
  EmailTemplatePurpose,
4
- TemplateType,
4
+ TemplateTypes,
5
5
  TemplatePurpose,
6
6
  GLOBAL_OWNER,
7
7
  } = require("../index")
@@ -26,7 +26,7 @@ exports.EmailTemplates = {
26
26
  exports.addBaseTemplates = (templates, type = null) => {
27
27
  let purposeList
28
28
  switch (type) {
29
- case TemplateType.EMAIL:
29
+ case TemplateTypes.EMAIL:
30
30
  purposeList = Object.values(EmailTemplatePurpose)
31
31
  break
32
32
  default:
@@ -0,0 +1,11 @@
1
+ const core = require("@budibase/backend-core")
2
+ const env = require("../environment")
3
+
4
+ exports.init = () => {
5
+ const dbConfig = {}
6
+ if (env.isTest() && !env.COUCH_DB_URL) {
7
+ dbConfig.inMemory = true
8
+ dbConfig.allDbs = true
9
+ }
10
+ core.init({ db: dbConfig })
11
+ }
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ import { Scope } from "@sentry/node"
13
13
  import { Event } from "@sentry/types/dist/event"
14
14
  import Application from "koa"
15
15
  import { bootstrap } from "global-agent"
16
- import * as db from "./db"
16
+ import db from "./db"
17
17
  db.init()
18
18
  const Koa = require("koa")
19
19
  const destroyable = require("server-destroy")
@@ -1,5 +1,5 @@
1
1
  const env = require("../environment")
2
- const { Header } = require("@budibase/backend-core/constants")
2
+ const { Headers } = require("@budibase/backend-core/constants")
3
3
 
4
4
  /**
5
5
  * This is a restricted endpoint in the cloud.
@@ -7,7 +7,7 @@ const { Header } = require("@budibase/backend-core/constants")
7
7
  */
8
8
  module.exports = async (ctx, next) => {
9
9
  if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
10
- const apiKey = ctx.request.headers[Header.API_KEY]
10
+ const apiKey = ctx.request.headers[Headers.API_KEY]
11
11
  if (apiKey !== env.INTERNAL_API_KEY) {
12
12
  ctx.throw(403, "Unauthorized")
13
13
  }
@@ -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
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) => {
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
  }
@@ -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
4
  exports.oidc = conf => {
5
5
  return {
6
- type: Config.OIDC,
6
+ type: Configs.OIDC,
7
7
  config: {
8
8
  configs: [
9
9
  {
@@ -23,7 +23,7 @@ exports.oidc = conf => {
23
23
 
24
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",
@@ -35,7 +35,7 @@ exports.google = conf => {
35
35
 
36
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",
@@ -49,7 +49,7 @@ exports.smtp = conf => {
49
49
 
50
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",
@@ -65,7 +65,7 @@ exports.smtpEthereal = () => {
65
65
 
66
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
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(),