@budibase/worker 2.1.32-alpha.8 → 2.1.32

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
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,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 = new Router()
5
-
6
- router.get("/api/system/environment", controller.fetch)
7
-
8
- export default router
@@ -1,8 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../../controllers/system/status"
3
-
4
- const router = new Router()
5
-
6
- router.get("/api/system/status", controller.fetch)
7
-
8
- export default 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 = new Router()
6
-
7
- router.delete(
8
- "/api/system/tenants/:tenantId",
9
- middleware.adminOnly,
10
- controller.delete
11
- )
12
-
13
- export default 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
- }
@@ -1,15 +0,0 @@
1
- import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI, TestAPIOpts } from "./base"
3
-
4
- export class TenantAPI extends TestAPI {
5
- constructor(config: TestConfiguration) {
6
- super(config)
7
- }
8
-
9
- delete = (tenantId: string, opts?: TestAPIOpts) => {
10
- return this.request
11
- .delete(`/api/system/tenants/${tenantId}`)
12
- .set(opts?.headers)
13
- .expect(opts?.status ? opts.status : 204)
14
- }
15
- }
@@ -1,49 +0,0 @@
1
- import { db as dbCore, tenancy } from "@budibase/backend-core"
2
- import {
3
- Config,
4
- InternalTemplateBinding,
5
- LOGO_URL,
6
- EmailTemplatePurpose,
7
- } from "../constants"
8
- import { checkSlashesInUrl } from "./index"
9
- const BASE_COMPANY = "Budibase"
10
-
11
- export async function getSettingsTemplateContext(
12
- purpose: EmailTemplatePurpose,
13
- code?: string
14
- ) {
15
- const db = tenancy.getGlobalDB()
16
- // TODO: use more granular settings in the future if required
17
- let settings =
18
- (await dbCore.getScopedConfig(db, { type: Config.SETTINGS })) || {}
19
- const URL = settings.platformUrl
20
- const context: any = {
21
- [InternalTemplateBinding.LOGO_URL]:
22
- checkSlashesInUrl(`${URL}/${settings.logoUrl}`) || LOGO_URL,
23
- [InternalTemplateBinding.PLATFORM_URL]: URL,
24
- [InternalTemplateBinding.COMPANY]: settings.company || BASE_COMPANY,
25
- [InternalTemplateBinding.DOCS_URL]:
26
- settings.docsUrl || "https://docs.budibase.com/",
27
- [InternalTemplateBinding.LOGIN_URL]: checkSlashesInUrl(
28
- tenancy.addTenantToUrl(`${URL}/login`)
29
- ),
30
- [InternalTemplateBinding.CURRENT_DATE]: new Date().toISOString(),
31
- [InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(),
32
- }
33
- // attach purpose specific context
34
- switch (purpose) {
35
- case EmailTemplatePurpose.PASSWORD_RECOVERY:
36
- context[InternalTemplateBinding.RESET_CODE] = code
37
- context[InternalTemplateBinding.RESET_URL] = checkSlashesInUrl(
38
- tenancy.addTenantToUrl(`${URL}/builder/auth/reset?code=${code}`)
39
- )
40
- break
41
- case EmailTemplatePurpose.INVITATION:
42
- context[InternalTemplateBinding.INVITE_CODE] = code
43
- context[InternalTemplateBinding.INVITE_URL] = checkSlashesInUrl(
44
- tenancy.addTenantToUrl(`${URL}/builder/invite?code=${code}`)
45
- )
46
- break
47
- }
48
- return context
49
- }