@budibase/worker 2.1.40-alpha.6 → 2.1.42

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 +59 -51
  29. package/src/api/routes/global/{users.ts → users.js} +32 -26
  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 +8 -40
  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 -2153
  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 -409
  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 -3958
  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
package/jest.config.ts DELETED
@@ -1,29 +0,0 @@
1
- import { Config } from "@jest/types"
2
- import * as fs from "fs"
3
-
4
- const config: Config.InitialOptions = {
5
- preset: "ts-jest",
6
- testEnvironment: "node",
7
- setupFiles: ["./src/tests/jestSetup.ts"],
8
- collectCoverageFrom: ["src/**/*.{js,ts}"],
9
- coverageReporters: ["lcov", "json", "clover"],
10
- }
11
-
12
- if (!process.env.CI) {
13
- // use sources when not in CI
14
- config.moduleNameMapper = {
15
- "@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
16
- "@budibase/backend-core": "<rootDir>/../backend-core/src",
17
- "@budibase/types": "<rootDir>/../types/src",
18
- "^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
19
- }
20
- // add pro sources if they exist
21
- if (fs.existsSync("../../../budibase-pro")) {
22
- config.moduleNameMapper["@budibase/pro"] =
23
- "<rootDir>/../../../budibase-pro/packages/pro/src"
24
- }
25
- } else {
26
- console.log("Running tests with compiled dependency sources")
27
- }
28
-
29
- export default config
@@ -1,66 +0,0 @@
1
- import {
2
- db as dbCore,
3
- roles,
4
- context,
5
- cache,
6
- tenancy,
7
- } from "@budibase/backend-core"
8
- import { BBContext, App } from "@budibase/types"
9
- import { allUsers } from "../../../sdk/users"
10
-
11
- export async function fetch(ctx: BBContext) {
12
- const tenantId = ctx.user!.tenantId
13
- // always use the dev apps as they'll be most up to date (true)
14
- const apps = (await dbCore.getAllApps({ tenantId, all: true })) as App[]
15
- const promises = []
16
- for (let app of apps) {
17
- // use dev app IDs
18
- promises.push(roles.getAllRoles(app.appId))
19
- }
20
- const roleList = await Promise.all(promises)
21
- const response: any = {}
22
- for (let app of apps) {
23
- const deployedAppId = dbCore.getProdAppID(app.appId)
24
- response[deployedAppId] = {
25
- roles: roleList.shift(),
26
- name: app.name,
27
- version: app.version,
28
- url: app.url,
29
- }
30
- }
31
- ctx.body = response
32
- }
33
-
34
- export async function find(ctx: BBContext) {
35
- const appId = ctx.params.appId
36
- await context.doInAppContext(dbCore.getDevAppID(appId), async () => {
37
- const db = context.getAppDB()
38
- const app = await db.get(dbCore.DocumentType.APP_METADATA)
39
- ctx.body = {
40
- roles: await roles.getAllRoles(),
41
- name: app.name,
42
- version: app.version,
43
- url: app.url,
44
- }
45
- })
46
- }
47
-
48
- export async function removeAppRole(ctx: BBContext) {
49
- const { appId } = ctx.params
50
- const db = tenancy.getGlobalDB()
51
- const users = await allUsers()
52
- const bulk = []
53
- const cacheInvalidations = []
54
- for (let user of users) {
55
- if (user.roles[appId]) {
56
- cacheInvalidations.push(cache.user.invalidateUser(user._id))
57
- delete user.roles[appId]
58
- bulk.push(user)
59
- }
60
- }
61
- await db.bulkDocs(bulk)
62
- await Promise.all(cacheInvalidations)
63
- ctx.body = {
64
- message: "App role removed from all users",
65
- }
66
- }
@@ -1,16 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../../controllers/global/roles"
3
- import { auth } from "@budibase/backend-core"
4
-
5
- const router: Router = new Router()
6
-
7
- router
8
- .get("/api/global/roles", auth.builderOrAdmin, controller.fetch)
9
- .get("/api/global/roles/:appId", auth.builderOrAdmin, controller.find)
10
- .delete(
11
- "/api/global/roles/:appId",
12
- auth.builderOrAdmin,
13
- controller.removeAppRole
14
- )
15
-
16
- export = router
@@ -1,31 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- // TODO
4
-
5
- describe("/api/global/license", () => {
6
- const config = new TestConfiguration()
7
-
8
- beforeAll(async () => {
9
- await config.beforeAll()
10
- })
11
-
12
- afterAll(async () => {
13
- await config.afterAll()
14
- })
15
-
16
- afterEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe("POST /api/global/license/activate", () => {
21
- it("activates license", () => {})
22
- })
23
-
24
- describe("POST /api/global/license/refresh", () => {})
25
-
26
- describe("GET /api/global/license/info", () => {})
27
-
28
- describe("DELETE /api/global/license/info", () => {})
29
-
30
- describe("GET /api/global/license/usage", () => {})
31
- })
@@ -1,27 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- // TODO
4
-
5
- describe("/api/global/roles", () => {
6
- const config = new TestConfiguration()
7
-
8
- beforeAll(async () => {
9
- await config.beforeAll()
10
- })
11
-
12
- afterAll(async () => {
13
- await config.afterAll()
14
- })
15
-
16
- afterEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe("GET /api/global/roles", () => {
21
- it("retrieves roles", () => {})
22
- })
23
-
24
- describe("GET /api/global/roles/:appId", () => {})
25
-
26
- describe("DELETE /api/global/roles/:appId", () => {})
27
- })
@@ -1,35 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- // TODO
4
-
5
- describe("/api/global/template", () => {
6
- const config = new TestConfiguration()
7
-
8
- beforeAll(async () => {
9
- await config.beforeAll()
10
- })
11
-
12
- afterAll(async () => {
13
- await config.afterAll()
14
- })
15
-
16
- afterEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe("GET /api/global/template/definitions", () => {
21
- it("retrieves definitions", () => {})
22
- })
23
-
24
- describe("POST /api/global/template", () => {})
25
-
26
- describe("GET /api/global/template", () => {})
27
-
28
- describe("GET /api/global/template/:type", () => {})
29
-
30
- describe("GET /api/global/template/:ownerId", () => {})
31
-
32
- describe("GET /api/global/template/:id", () => {})
33
-
34
- describe("DELETE /api/global/template/:id/:rev", () => {})
35
- })
@@ -1,29 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- // TODO
4
-
5
- describe("/api/global/workspaces", () => {
6
- const config = new TestConfiguration()
7
-
8
- beforeAll(async () => {
9
- await config.beforeAll()
10
- })
11
-
12
- afterAll(async () => {
13
- await config.afterAll()
14
- })
15
-
16
- afterEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe("GET /api/global/workspaces", () => {
21
- it("retrieves workspaces", () => {})
22
- })
23
-
24
- describe("DELETE /api/global/workspaces/:id", () => {})
25
-
26
- describe("GET /api/global/workspaces", () => {})
27
-
28
- describe("GET /api/global/workspaces/:id", () => {})
29
- })
@@ -1,8 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../../controllers/system/environment"
3
-
4
- const router: Router = new Router()
5
-
6
- router.get("/api/system/environment", controller.fetch)
7
-
8
- export = router
@@ -1,8 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../../controllers/system/status"
3
-
4
- const router: Router = new Router()
5
-
6
- router.get("/api/system/status", controller.fetch)
7
-
8
- export = router
@@ -1,13 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../../controllers/system/tenants"
3
- import { middleware } from "@budibase/backend-core"
4
-
5
- const router: Router = new Router()
6
-
7
- router.delete(
8
- "/api/system/tenants/:tenantId",
9
- middleware.adminOnly,
10
- controller.delete
11
- )
12
-
13
- export = router
@@ -1,29 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- describe("/api/system/environment", () => {
4
- const config = new TestConfiguration()
5
-
6
- beforeAll(async () => {
7
- await config.beforeAll()
8
- })
9
-
10
- afterAll(async () => {
11
- await config.afterAll()
12
- })
13
-
14
- afterEach(() => {
15
- jest.clearAllMocks()
16
- })
17
-
18
- describe("GET /api/system/environment", () => {
19
- it("returns the expected environment", async () => {
20
- const env = await config.api.environment.getEnvironment()
21
- expect(env.body).toEqual({
22
- cloud: true,
23
- disableAccountPortal: false,
24
- isDev: false,
25
- multiTenancy: true,
26
- })
27
- })
28
- })
29
- })
@@ -1,63 +0,0 @@
1
- const migrateFn = jest.fn()
2
-
3
- import { TestConfiguration } from "../../../../tests"
4
-
5
- jest.mock("../../../../migrations", () => {
6
- return {
7
- ...jest.requireActual("../../../../migrations"),
8
- migrate: migrateFn,
9
- }
10
- })
11
-
12
- describe("/api/system/migrations", () => {
13
- const config = new TestConfiguration()
14
-
15
- beforeAll(async () => {
16
- await config.beforeAll()
17
- })
18
-
19
- afterAll(async () => {
20
- await config.afterAll()
21
- })
22
-
23
- afterEach(() => {
24
- jest.clearAllMocks()
25
- })
26
-
27
- describe("POST /api/system/migrations/run", () => {
28
- it("fails with no internal api key", async () => {
29
- const res = await config.api.migrations.runMigrations({
30
- headers: {},
31
- status: 403,
32
- })
33
- expect(res.text).toBe("Unauthorized - no public worker access")
34
- expect(migrateFn).toBeCalledTimes(0)
35
- })
36
-
37
- it("runs migrations", async () => {
38
- const res = await config.api.migrations.runMigrations()
39
- expect(res.text).toBe("OK")
40
- expect(migrateFn).toBeCalledTimes(1)
41
- })
42
- })
43
-
44
- describe("DELETE /api/system/migrations/definitions", () => {
45
- it("fails with no internal api key", async () => {
46
- const res = await config.api.migrations.getMigrationDefinitions({
47
- headers: {},
48
- status: 403,
49
- })
50
- expect(res.text).toBe("Unauthorized - no public worker access")
51
- })
52
-
53
- it("returns definitions", async () => {
54
- const res = await config.api.migrations.getMigrationDefinitions()
55
- expect(res.body).toEqual([
56
- {
57
- name: "global_info_sync_users",
58
- type: "global",
59
- },
60
- ])
61
- })
62
- })
63
- })
@@ -1,36 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
-
3
- describe("/api/system/restore", () => {
4
- const config = new TestConfiguration()
5
-
6
- beforeAll(async () => {
7
- await config.beforeAll()
8
- })
9
-
10
- afterAll(async () => {
11
- await config.afterAll()
12
- })
13
-
14
- afterEach(() => {
15
- jest.clearAllMocks()
16
- })
17
-
18
- describe("POST /api/global/restore", () => {
19
- it("doesn't allow restore in cloud", async () => {
20
- const res = await config.api.restore.restored({ status: 405 })
21
- expect(res.body).toEqual({
22
- message: "This operation is not allowed in cloud.",
23
- status: 405,
24
- })
25
- })
26
-
27
- it("restores in self host", async () => {
28
- config.modeSelf()
29
- const res = await config.api.restore.restored()
30
- expect(res.body).toEqual({
31
- message: "System prepared after restore.",
32
- })
33
- config.modeCloud()
34
- })
35
- })
36
- })
@@ -1,48 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
- import { accounts } from "@budibase/backend-core"
3
- import { mocks } from "@budibase/backend-core/tests"
4
-
5
- describe("/api/system/status", () => {
6
- const config = new TestConfiguration()
7
-
8
- beforeAll(async () => {
9
- await config.beforeAll()
10
- })
11
-
12
- afterAll(async () => {
13
- await config.afterAll()
14
- })
15
-
16
- afterEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe("GET /api/system/status", () => {
21
- it("returns status in self host", async () => {
22
- config.modeSelf()
23
- const res = await config.api.status.getStatus()
24
- expect(res.body).toEqual({
25
- health: {
26
- passing: true,
27
- },
28
- })
29
- expect(accounts.getStatus).toBeCalledTimes(0)
30
- config.modeCloud()
31
- })
32
-
33
- it("returns status in cloud", async () => {
34
- const value = {
35
- health: {
36
- passing: false,
37
- },
38
- }
39
-
40
- mocks.accounts.getStatus.mockReturnValueOnce(value)
41
-
42
- const res = await config.api.status.getStatus()
43
-
44
- expect(accounts.getStatus).toBeCalledTimes(1)
45
- expect(res.body).toEqual(value)
46
- })
47
- })
48
- })
@@ -1,61 +0,0 @@
1
- import { TestConfiguration } from "../../../../tests"
2
- import { tenancy } from "@budibase/backend-core"
3
-
4
- describe("/api/global/tenants", () => {
5
- const config = new TestConfiguration()
6
-
7
- beforeAll(async () => {
8
- await config.beforeAll()
9
- })
10
-
11
- afterAll(async () => {
12
- await config.afterAll()
13
- })
14
-
15
- afterEach(() => {
16
- jest.clearAllMocks()
17
- })
18
-
19
- describe("DELETE /api/system/tenants/:tenantId", () => {
20
- it("allows deleting the current tenant", async () => {
21
- const user = await config.createTenant()
22
-
23
- await config.api.tenants.delete(user.tenantId, {
24
- headers: config.authHeaders(user),
25
- })
26
- })
27
-
28
- it("rejects deleting another tenant", async () => {
29
- const user1 = await config.createTenant()
30
- // create a second user in another tenant
31
- const user2 = await config.createTenant()
32
-
33
- const status = 403
34
- const res = await config.api.tenants.delete(user1.tenantId, {
35
- status,
36
- headers: config.authHeaders(user2),
37
- })
38
-
39
- expect(res.body).toEqual({
40
- message: "Tenant ID does not match current user",
41
- status,
42
- })
43
- })
44
-
45
- it("rejects non-admin", async () => {
46
- const user1 = await config.createTenant()
47
- // create an internal non-admin user
48
- const user2 = await tenancy.doInTenant(user1.tenantId, () => {
49
- return config.createUser()
50
- })
51
- await config.createSession(user2)
52
-
53
- const res = await config.api.tenants.delete(user1.tenantId, {
54
- status: 403,
55
- headers: config.authHeaders(user2),
56
- })
57
-
58
- expect(res.body).toEqual(config.adminOnlyResponse())
59
- })
60
- })
61
- })
package/src/db/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import core from "@budibase/backend-core"
2
- import env from "../environment"
3
-
4
- export const init = () => {
5
- const dbConfig: any = {}
6
- if (env.isTest() && !env.COUCH_DB_URL) {
7
- dbConfig.inMemory = true
8
- }
9
- core.init({ db: dbConfig })
10
- }
@@ -1,73 +0,0 @@
1
- import { TestConfiguration, structures } from "../../tests"
2
- import { constants } from "@budibase/backend-core"
3
-
4
- describe("tenancy middleware", () => {
5
- const config = new TestConfiguration()
6
-
7
- beforeAll(async () => {
8
- await config.beforeAll()
9
- })
10
-
11
- afterAll(async () => {
12
- await config.afterAll()
13
- })
14
-
15
- afterEach(() => {
16
- jest.clearAllMocks()
17
- })
18
-
19
- it("should get tenant id from user", async () => {
20
- const user = await config.createTenant()
21
- await config.createSession(user)
22
- const res = await config.api.self.getSelf(user)
23
- expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
24
- })
25
-
26
- it("should get tenant id from header", async () => {
27
- const tenantId = structures.uuid()
28
- const headers = {
29
- [constants.Header.TENANT_ID]: tenantId,
30
- }
31
- const res = await config.request
32
- .get(`/api/global/configs/checklist`)
33
- .set(headers)
34
- expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
35
- })
36
-
37
- it("should get tenant id from query param", async () => {
38
- const tenantId = structures.uuid()
39
- const res = await config.request.get(
40
- `/api/global/configs/checklist?tenantId=${tenantId}`
41
- )
42
- expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
43
- })
44
-
45
- it("should get tenant id from subdomain", async () => {
46
- const tenantId = structures.uuid()
47
- const headers = {
48
- host: `${tenantId}.localhost:10000`,
49
- }
50
- const res = await config.request
51
- .get(`/api/global/configs/checklist`)
52
- .set(headers)
53
- expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
54
- })
55
-
56
- it("should get tenant id from path variable", async () => {
57
- const user = await config.createTenant()
58
- const res = await config.request
59
- .post(`/api/global/auth/${user.tenantId}/login`)
60
- .send({
61
- username: user.email,
62
- password: user.password,
63
- })
64
- expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
65
- })
66
-
67
- it("should throw when no tenant id is found", async () => {
68
- const res = await config.request.get(`/api/global/configs/checklist`)
69
- expect(res.status).toBe(403)
70
- expect(res.text).toBe("Tenant id not set")
71
- expect(res.headers[constants.Header.TENANT_ID]).toBe(undefined)
72
- })
73
- })
@@ -1,16 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
-
3
- export interface TestAPIOpts {
4
- headers?: any
5
- status?: number
6
- }
7
-
8
- export abstract class TestAPI {
9
- config: TestConfiguration
10
- request: any
11
-
12
- protected constructor(config: TestConfiguration) {
13
- this.config = config
14
- this.request = config.request
15
- }
16
- }
@@ -1,15 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
3
-
4
- export class EnvironmentAPI extends TestAPI {
5
- constructor(config: TestConfiguration) {
6
- super(config)
7
- }
8
-
9
- getEnvironment = () => {
10
- return this.request
11
- .get(`/api/system/environment`)
12
- .expect("Content-Type", /json/)
13
- .expect(200)
14
- }
15
- }
@@ -1,22 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI, TestAPIOpts } from "./base"
3
-
4
- export class MigrationAPI extends TestAPI {
5
- constructor(config: TestConfiguration) {
6
- super(config)
7
- }
8
-
9
- runMigrations = (opts?: TestAPIOpts) => {
10
- return this.request
11
- .post(`/api/system/migrations/run`)
12
- .set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
13
- .expect(opts?.status ? opts.status : 200)
14
- }
15
-
16
- getMigrationDefinitions = (opts?: TestAPIOpts) => {
17
- return this.request
18
- .get(`/api/system/migrations/definitions`)
19
- .set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
20
- .expect(opts?.status ? opts.status : 200)
21
- }
22
- }
@@ -1,14 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI, TestAPIOpts } from "./base"
3
-
4
- export class RestoreAPI extends TestAPI {
5
- constructor(config: TestConfiguration) {
6
- super(config)
7
- }
8
-
9
- restored = (opts?: TestAPIOpts) => {
10
- return this.request
11
- .post(`/api/system/restored`)
12
- .expect(opts?.status ? opts.status : 200)
13
- }
14
- }
@@ -1,12 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
3
-
4
- export class StatusAPI extends TestAPI {
5
- constructor(config: TestConfiguration) {
6
- super(config)
7
- }
8
-
9
- getStatus = () => {
10
- return this.request.get(`/api/system/status`).expect(200)
11
- }
12
- }