@budibase/worker 2.3.17-alpha.0 → 2.3.17
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.
- package/coverage/clover.xml +2199 -0
- package/coverage/coverage-final.json +84 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +431 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +934 -0
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1348 -0
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
- package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +251 -0
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +838 -0
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +595 -0
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
- package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +251 -0
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +475 -0
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/index.html +116 -0
- package/coverage/lcov-report/src/api/routes/index.ts.html +202 -0
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
- package/coverage/lcov-report/src/constants/index.html +116 -0
- package/coverage/lcov-report/src/constants/index.ts.html +637 -0
- package/coverage/lcov-report/src/constants/templates/index.html +116 -0
- package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
- package/coverage/lcov-report/src/db/index.html +116 -0
- package/coverage/lcov-report/src/db/index.ts.html +115 -0
- package/coverage/lcov-report/src/environment.ts.html +388 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/index.ts.html +394 -0
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
- package/coverage/lcov-report/src/middleware/index.html +116 -0
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
- package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
- package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/index.html +116 -0
- package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
- package/coverage/lcov-report/src/sdk/users/events.ts.html +601 -0
- package/coverage/lcov-report/src/sdk/users/index.html +146 -0
- package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1999 -0
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1075 -0
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
- package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
- package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
- package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
- package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
- package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/index.html +356 -0
- package/coverage/lcov-report/src/tests/api/index.ts.html +238 -0
- package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
- package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
- package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
- package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/users.ts.html +514 -0
- package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
- package/coverage/lcov-report/src/tests/index.html +146 -0
- package/coverage/lcov-report/src/tests/index.ts.html +103 -0
- package/coverage/lcov-report/src/tests/mocks/email.ts.html +115 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
- package/coverage/lcov-report/src/tests/structures/index.html +161 -0
- package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
- package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
- package/coverage/lcov-report/src/utilities/appService.ts.html +208 -0
- package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
- package/coverage/lcov-report/src/utilities/index.html +206 -0
- package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
- package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
- package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
- package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
- package/coverage/lcov.info +4187 -0
- package/jest.config.ts +2 -3
- package/package.json +5 -7
- package/src/api/routes/global/tests/auth.spec.ts +22 -30
- package/src/api/routes/global/tests/configs.spec.ts +94 -114
- package/src/api/routes/global/tests/roles.spec.ts +14 -19
- package/src/api/routes/global/tests/users.spec.ts +34 -33
- package/src/index.ts +7 -6
- package/src/sdk/users/users.ts +1 -0
- package/src/tests/TestConfiguration.ts +11 -41
- package/src/tests/api/auth.ts +3 -7
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/users.ts +2 -2
- package/src/tests/jestSetup.ts +2 -9
- package/src/tests/structures/index.ts +2 -0
- package/__mocks__/node-fetch.ts +0 -23
- package/jest-testcontainers-config.js +0 -8
- package/src/ddApm.ts +0 -7
- package/src/elasticApm.ts +0 -10
package/jest.config.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Config } from "@jest/types"
|
|
2
2
|
import * as fs from "fs"
|
|
3
|
-
const preset = require("ts-jest/jest-preset")
|
|
4
3
|
|
|
5
4
|
const config: Config.InitialOptions = {
|
|
6
|
-
|
|
7
|
-
preset: "@trendyol/jest-testcontainers",
|
|
5
|
+
testEnvironment: "node",
|
|
8
6
|
setupFiles: ["./src/tests/jestEnv.ts"],
|
|
9
7
|
setupFilesAfterEnv: ["./src/tests/jestSetup.ts"],
|
|
10
8
|
collectCoverageFrom: ["src/**/*.{js,ts}"],
|
|
@@ -20,6 +18,7 @@ if (!process.env.CI) {
|
|
|
20
18
|
"@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
|
|
21
19
|
"@budibase/backend-core": "<rootDir>/../backend-core/src",
|
|
22
20
|
"@budibase/types": "<rootDir>/../types/src",
|
|
21
|
+
"^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
|
|
23
22
|
}
|
|
24
23
|
// add pro sources if they exist
|
|
25
24
|
if (fs.existsSync("../../../budibase-pro")) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.3.17
|
|
4
|
+
"version": "2.3.17",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -36,17 +36,16 @@
|
|
|
36
36
|
"author": "Budibase",
|
|
37
37
|
"license": "GPL-3.0",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@budibase/backend-core": "2.3.17
|
|
39
|
+
"@budibase/backend-core": "^2.3.17",
|
|
40
40
|
"@budibase/pro": "2.3.16",
|
|
41
|
-
"@budibase/string-templates": "2.3.17
|
|
42
|
-
"@budibase/types": "2.3.17
|
|
41
|
+
"@budibase/string-templates": "^2.3.17",
|
|
42
|
+
"@budibase/types": "^2.3.17",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
46
46
|
"@types/global-agent": "2.1.1",
|
|
47
47
|
"aws-sdk": "2.1030.0",
|
|
48
48
|
"bcryptjs": "2.4.3",
|
|
49
|
-
"dd-trace": "3.13.2",
|
|
50
49
|
"dotenv": "8.6.0",
|
|
51
50
|
"elastic-apm-node": "3.38.0",
|
|
52
51
|
"global-agent": "3.0.0",
|
|
@@ -73,7 +72,6 @@
|
|
|
73
72
|
"devDependencies": {
|
|
74
73
|
"@swc/core": "^1.3.25",
|
|
75
74
|
"@swc/jest": "^0.2.24",
|
|
76
|
-
"@trendyol/jest-testcontainers": "^2.1.1",
|
|
77
75
|
"@types/jest": "26.0.23",
|
|
78
76
|
"@types/jsonwebtoken": "8.5.1",
|
|
79
77
|
"@types/koa": "2.13.4",
|
|
@@ -99,5 +97,5 @@
|
|
|
99
97
|
"typescript": "4.7.3",
|
|
100
98
|
"update-dotenv": "1.1.1"
|
|
101
99
|
},
|
|
102
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "a57c922b91c1df8dc276588a5ad583a0c1aea52c"
|
|
103
101
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
2
|
import { TestConfiguration, mocks } from "../../../../tests"
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
|
-
import { events
|
|
5
|
-
import { structures } from "@budibase/backend-core/tests"
|
|
4
|
+
import { events } from "@budibase/backend-core"
|
|
6
5
|
|
|
7
6
|
const expectSetAuthCookie = (res: any) => {
|
|
8
7
|
expect(
|
|
@@ -41,43 +40,36 @@ describe("/api/global/auth", () => {
|
|
|
41
40
|
|
|
42
41
|
describe("POST /api/global/auth/:tenantId/reset", () => {
|
|
43
42
|
it("should generate password reset email", async () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
userEmail
|
|
49
|
-
)
|
|
50
|
-
const user = await config.getUser(userEmail)
|
|
51
|
-
|
|
52
|
-
expect(res.body).toEqual({
|
|
53
|
-
message: "Please check your email for a reset link.",
|
|
54
|
-
})
|
|
55
|
-
expect(sendMailMock).toHaveBeenCalled()
|
|
43
|
+
const { res, code } = await config.api.auth.requestPasswordReset(
|
|
44
|
+
sendMailMock
|
|
45
|
+
)
|
|
46
|
+
const user = await config.getUser("test@test.com")
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
expect(events.user.passwordResetRequested).toBeCalledWith(user)
|
|
48
|
+
expect(res.body).toEqual({
|
|
49
|
+
message: "Please check your email for a reset link.",
|
|
60
50
|
})
|
|
51
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
52
|
+
|
|
53
|
+
expect(code).toBeDefined()
|
|
54
|
+
expect(events.user.passwordResetRequested).toBeCalledTimes(1)
|
|
55
|
+
expect(events.user.passwordResetRequested).toBeCalledWith(user)
|
|
61
56
|
})
|
|
62
57
|
})
|
|
63
58
|
|
|
64
59
|
describe("POST /api/global/auth/:tenantId/reset/update", () => {
|
|
65
60
|
it("should reset password", async () => {
|
|
66
|
-
await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)
|
|
72
|
-
const user = await config.getUser(userEmail)
|
|
73
|
-
delete user.password
|
|
61
|
+
const { code } = await config.api.auth.requestPasswordReset(
|
|
62
|
+
sendMailMock
|
|
63
|
+
)
|
|
64
|
+
const user = await config.getUser("test@test.com")
|
|
65
|
+
delete user.password
|
|
74
66
|
|
|
75
|
-
|
|
67
|
+
const res = await config.api.auth.updatePassword(code)
|
|
68
|
+
|
|
69
|
+
expect(res.body).toEqual({ message: "password reset successfully." })
|
|
70
|
+
expect(events.user.passwordReset).toBeCalledTimes(1)
|
|
71
|
+
expect(events.user.passwordReset).toBeCalledWith(user)
|
|
76
72
|
|
|
77
|
-
expect(res.body).toEqual({ message: "password reset successfully." })
|
|
78
|
-
expect(events.user.passwordReset).toBeCalledTimes(1)
|
|
79
|
-
expect(events.user.passwordReset).toBeCalledWith(user)
|
|
80
|
-
})
|
|
81
73
|
// TODO: Login using new password
|
|
82
74
|
})
|
|
83
75
|
})
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
3
|
import { TestConfiguration, structures, mocks } from "../../../../tests"
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
import { Config,
|
|
5
|
+
import { Config, events } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
describe("configs", () => {
|
|
8
8
|
const config = new TestConfiguration()
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
beforeAll(async () => {
|
|
11
11
|
await config.beforeAll()
|
|
12
12
|
})
|
|
13
13
|
|
|
@@ -113,64 +113,56 @@ describe("configs", () => {
|
|
|
113
113
|
|
|
114
114
|
describe("create", () => {
|
|
115
115
|
it("should create activated OIDC config", async () => {
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await config.deleteConfig(Config.OIDC)
|
|
124
|
-
})
|
|
116
|
+
await saveOIDCConfig()
|
|
117
|
+
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
118
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
119
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
120
|
+
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
121
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
122
|
+
await config.deleteConfig(Config.OIDC)
|
|
125
123
|
})
|
|
126
124
|
|
|
127
125
|
it("should create deactivated OIDC config", async () => {
|
|
128
|
-
await
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await config.deleteConfig(Config.OIDC)
|
|
135
|
-
})
|
|
126
|
+
await saveOIDCConfig({ activated: false })
|
|
127
|
+
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
128
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
129
|
+
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
130
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
131
|
+
await config.deleteConfig(Config.OIDC)
|
|
136
132
|
})
|
|
137
133
|
})
|
|
138
134
|
|
|
139
135
|
describe("update", () => {
|
|
140
136
|
it("should update OIDC config to deactivated", async () => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
await config.deleteConfig(Config.OIDC)
|
|
155
|
-
})
|
|
137
|
+
const oidcConf = await saveOIDCConfig()
|
|
138
|
+
jest.clearAllMocks()
|
|
139
|
+
await saveOIDCConfig(
|
|
140
|
+
{ ...oidcConf.config.configs[0], activated: false },
|
|
141
|
+
oidcConf._id,
|
|
142
|
+
oidcConf._rev
|
|
143
|
+
)
|
|
144
|
+
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
145
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
146
|
+
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
147
|
+
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
148
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
|
|
149
|
+
await config.deleteConfig(Config.OIDC)
|
|
156
150
|
})
|
|
157
151
|
|
|
158
152
|
it("should update OIDC config to activated", async () => {
|
|
159
|
-
await
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
await config.deleteConfig(Config.OIDC)
|
|
173
|
-
})
|
|
153
|
+
const oidcConf = await saveOIDCConfig({ activated: false })
|
|
154
|
+
jest.clearAllMocks()
|
|
155
|
+
await saveOIDCConfig(
|
|
156
|
+
{ ...oidcConf.config.configs[0], activated: true },
|
|
157
|
+
oidcConf._id,
|
|
158
|
+
oidcConf._rev
|
|
159
|
+
)
|
|
160
|
+
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
161
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
162
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
163
|
+
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
164
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
165
|
+
await config.deleteConfig(Config.OIDC)
|
|
174
166
|
})
|
|
175
167
|
})
|
|
176
168
|
})
|
|
@@ -187,26 +179,22 @@ describe("configs", () => {
|
|
|
187
179
|
|
|
188
180
|
describe("create", () => {
|
|
189
181
|
it("should create SMTP config", async () => {
|
|
190
|
-
await
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
await config.deleteConfig(Config.SMTP)
|
|
196
|
-
})
|
|
182
|
+
await config.deleteConfig(Config.SMTP)
|
|
183
|
+
await saveSMTPConfig()
|
|
184
|
+
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
185
|
+
expect(events.email.SMTPCreated).toBeCalledTimes(1)
|
|
186
|
+
await config.deleteConfig(Config.SMTP)
|
|
197
187
|
})
|
|
198
188
|
})
|
|
199
189
|
|
|
200
190
|
describe("update", () => {
|
|
201
191
|
it("should update SMTP config", async () => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
await config.deleteConfig(Config.SMTP)
|
|
209
|
-
})
|
|
192
|
+
const smtpConf = await saveSMTPConfig()
|
|
193
|
+
jest.clearAllMocks()
|
|
194
|
+
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
195
|
+
expect(events.email.SMTPCreated).not.toBeCalled()
|
|
196
|
+
expect(events.email.SMTPUpdated).toBeCalledTimes(1)
|
|
197
|
+
await config.deleteConfig(Config.SMTP)
|
|
210
198
|
})
|
|
211
199
|
})
|
|
212
200
|
})
|
|
@@ -223,73 +211,65 @@ describe("configs", () => {
|
|
|
223
211
|
|
|
224
212
|
describe("create", () => {
|
|
225
213
|
it("should create settings config with default settings", async () => {
|
|
226
|
-
await
|
|
227
|
-
await config.deleteConfig(Config.SETTINGS)
|
|
214
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
228
215
|
|
|
229
|
-
|
|
216
|
+
await saveSettingsConfig()
|
|
230
217
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
})
|
|
218
|
+
expect(events.org.nameUpdated).not.toBeCalled()
|
|
219
|
+
expect(events.org.logoUpdated).not.toBeCalled()
|
|
220
|
+
expect(events.org.platformURLUpdated).not.toBeCalled()
|
|
235
221
|
})
|
|
236
222
|
|
|
237
223
|
it("should create settings config with non-default settings", async () => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
config.modeCloud()
|
|
253
|
-
})
|
|
224
|
+
config.modeSelf()
|
|
225
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
226
|
+
const conf = {
|
|
227
|
+
company: "acme",
|
|
228
|
+
logoUrl: "http://example.com",
|
|
229
|
+
platformUrl: "http://example.com",
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
await saveSettingsConfig(conf)
|
|
233
|
+
|
|
234
|
+
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
235
|
+
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
236
|
+
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
237
|
+
config.modeCloud()
|
|
254
238
|
})
|
|
255
239
|
})
|
|
256
240
|
|
|
257
241
|
describe("update", () => {
|
|
258
242
|
it("should update settings config", async () => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
config.modeCloud()
|
|
277
|
-
})
|
|
243
|
+
config.modeSelf()
|
|
244
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
245
|
+
const settingsConfig = await saveSettingsConfig()
|
|
246
|
+
settingsConfig.config.company = "acme"
|
|
247
|
+
settingsConfig.config.logoUrl = "http://example.com"
|
|
248
|
+
settingsConfig.config.platformUrl = "http://example.com"
|
|
249
|
+
|
|
250
|
+
await saveSettingsConfig(
|
|
251
|
+
settingsConfig.config,
|
|
252
|
+
settingsConfig._id,
|
|
253
|
+
settingsConfig._rev
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
257
|
+
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
258
|
+
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
259
|
+
config.modeCloud()
|
|
278
260
|
})
|
|
279
261
|
})
|
|
280
262
|
})
|
|
281
263
|
})
|
|
282
264
|
|
|
283
265
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
|
284
|
-
await
|
|
285
|
-
await config.saveSmtpConfig()
|
|
266
|
+
await config.saveSmtpConfig()
|
|
286
267
|
|
|
287
|
-
|
|
288
|
-
|
|
268
|
+
const res = await config.api.configs.getConfigChecklist()
|
|
269
|
+
const checklist = res.body
|
|
289
270
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
})
|
|
271
|
+
expect(checklist.apps.checked).toBeFalsy()
|
|
272
|
+
expect(checklist.smtp.checked).toBeTruthy()
|
|
273
|
+
expect(checklist.adminUser.checked).toBeTruthy()
|
|
294
274
|
})
|
|
295
275
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { structures, TestConfiguration } from "../../../../tests"
|
|
2
2
|
import { context, db, permissions, roles } from "@budibase/backend-core"
|
|
3
3
|
import { Mock } from "jest-mock"
|
|
4
|
-
import { Database } from "@budibase/types"
|
|
5
4
|
|
|
6
5
|
jest.mock("@budibase/backend-core", () => {
|
|
7
6
|
const core = jest.requireActual("@budibase/backend-core")
|
|
@@ -17,13 +16,14 @@ jest.mock("@budibase/backend-core", () => {
|
|
|
17
16
|
}
|
|
18
17
|
})
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const appDb = db.getDB("app_test")
|
|
20
|
+
const mockAppDB = context.getAppDB as Mock
|
|
21
|
+
mockAppDB.mockReturnValue(appDb)
|
|
22
22
|
|
|
23
23
|
async function addAppMetadata() {
|
|
24
24
|
await appDb.put({
|
|
25
25
|
_id: "app_metadata",
|
|
26
|
-
appId:
|
|
26
|
+
appId: "app_test",
|
|
27
27
|
name: "New App",
|
|
28
28
|
version: "version",
|
|
29
29
|
url: "url",
|
|
@@ -39,17 +39,10 @@ describe("/api/global/roles", () => {
|
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
beforeAll(async () => {
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
beforeEach(async () => {
|
|
46
|
-
appId = db.generateAppID()
|
|
47
|
-
appDb = db.getDB(appId)
|
|
48
|
-
const mockAppDB = context.getAppDB as Mock
|
|
49
|
-
mockAppDB.mockReturnValue(appDb)
|
|
50
|
-
|
|
51
|
-
await addAppMetadata()
|
|
42
|
+
console.debug(role)
|
|
52
43
|
appDb.put(role)
|
|
44
|
+
await addAppMetadata()
|
|
45
|
+
await config.beforeAll()
|
|
53
46
|
})
|
|
54
47
|
|
|
55
48
|
afterAll(async () => {
|
|
@@ -64,14 +57,16 @@ describe("/api/global/roles", () => {
|
|
|
64
57
|
it("retrieves roles", async () => {
|
|
65
58
|
const res = await config.api.roles.get()
|
|
66
59
|
expect(res.body).toBeDefined()
|
|
67
|
-
expect(res.body[
|
|
68
|
-
expect(res.body[
|
|
60
|
+
expect(res.body["app_test"].roles.length).toEqual(5)
|
|
61
|
+
expect(res.body["app_test"].roles.map((r: any) => r._id)).toContain(
|
|
62
|
+
role._id
|
|
63
|
+
)
|
|
69
64
|
})
|
|
70
65
|
})
|
|
71
66
|
|
|
72
67
|
describe("GET api/global/roles/:appId", () => {
|
|
73
68
|
it("finds a role by appId", async () => {
|
|
74
|
-
const res = await config.api.roles.find(
|
|
69
|
+
const res = await config.api.roles.find("app_test")
|
|
75
70
|
expect(res.body).toBeDefined()
|
|
76
71
|
expect(res.body.name).toEqual("New App")
|
|
77
72
|
})
|
|
@@ -84,9 +79,9 @@ describe("/api/global/roles", () => {
|
|
|
84
79
|
app_test: "role1",
|
|
85
80
|
}
|
|
86
81
|
const userResponse = await config.createUser(user)
|
|
87
|
-
const res = await config.api.roles.remove(
|
|
82
|
+
const res = await config.api.roles.remove("app_test")
|
|
88
83
|
const updatedUser = await config.api.users.getUser(userResponse._id!)
|
|
89
|
-
expect(updatedUser.body.roles).not.toHaveProperty(
|
|
84
|
+
expect(updatedUser.body.roles).not.toHaveProperty("app_test")
|
|
90
85
|
expect(res.body.message).toEqual("App role removed from all users")
|
|
91
86
|
})
|
|
92
87
|
})
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { InviteUsersResponse, User } from "@budibase/types"
|
|
2
2
|
|
|
3
3
|
jest.mock("nodemailer")
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
TestConfiguration,
|
|
6
|
+
mocks,
|
|
7
|
+
structures,
|
|
8
|
+
TENANT_1,
|
|
9
|
+
} from "../../../../tests"
|
|
5
10
|
const sendMailMock = mocks.email.mock()
|
|
6
|
-
import {
|
|
11
|
+
import { events, tenancy } from "@budibase/backend-core"
|
|
7
12
|
|
|
8
13
|
describe("/api/global/users", () => {
|
|
9
14
|
const config = new TestConfiguration()
|
|
@@ -22,18 +27,16 @@ describe("/api/global/users", () => {
|
|
|
22
27
|
|
|
23
28
|
describe("invite", () => {
|
|
24
29
|
it("should be able to generate an invitation", async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(events.user.invited).toBeCalledTimes(1)
|
|
36
|
-
})
|
|
30
|
+
const email = structures.users.newEmail()
|
|
31
|
+
const { code, res } = await config.api.users.sendUserInvite(
|
|
32
|
+
sendMailMock,
|
|
33
|
+
email
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
expect(res.body).toEqual({ message: "Invitation has been sent." })
|
|
37
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
38
|
+
expect(code).toBeDefined()
|
|
39
|
+
expect(events.user.invited).toBeCalledTimes(1)
|
|
37
40
|
})
|
|
38
41
|
|
|
39
42
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
@@ -50,22 +53,20 @@ describe("/api/global/users", () => {
|
|
|
50
53
|
})
|
|
51
54
|
|
|
52
55
|
it("should be able to create new user from invite", async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(events.user.inviteAccepted).toBeCalledWith(user)
|
|
68
|
-
})
|
|
56
|
+
const email = structures.users.newEmail()
|
|
57
|
+
const { code } = await config.api.users.sendUserInvite(
|
|
58
|
+
sendMailMock,
|
|
59
|
+
email
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const res = await config.api.users.acceptInvite(code)
|
|
63
|
+
|
|
64
|
+
expect(res.body._id).toBeDefined()
|
|
65
|
+
const user = await config.getUser(email)
|
|
66
|
+
expect(user).toBeDefined()
|
|
67
|
+
expect(user._id).toEqual(res.body._id)
|
|
68
|
+
expect(events.user.inviteAccepted).toBeCalledTimes(1)
|
|
69
|
+
expect(events.user.inviteAccepted).toBeCalledWith(user)
|
|
69
70
|
})
|
|
70
71
|
})
|
|
71
72
|
|
|
@@ -117,7 +118,7 @@ describe("/api/global/users", () => {
|
|
|
117
118
|
const user = await config.createUser()
|
|
118
119
|
jest.clearAllMocks()
|
|
119
120
|
|
|
120
|
-
await tenancy.doInTenant(
|
|
121
|
+
await tenancy.doInTenant(TENANT_1, async () => {
|
|
121
122
|
const response = await config.api.users.bulkCreateUsers([user])
|
|
122
123
|
|
|
123
124
|
expect(response.created?.successful.length).toBe(0)
|
|
@@ -230,7 +231,7 @@ describe("/api/global/users", () => {
|
|
|
230
231
|
const user = await config.createUser()
|
|
231
232
|
jest.clearAllMocks()
|
|
232
233
|
|
|
233
|
-
await tenancy.doInTenant(
|
|
234
|
+
await tenancy.doInTenant(TENANT_1, async () => {
|
|
234
235
|
delete user._id
|
|
235
236
|
const response = await config.api.users.saveUser(user, 400)
|
|
236
237
|
|
|
@@ -443,7 +444,7 @@ describe("/api/global/users", () => {
|
|
|
443
444
|
})
|
|
444
445
|
|
|
445
446
|
it("should not be able to update email address", async () => {
|
|
446
|
-
const email =
|
|
447
|
+
const email = "email@test.com"
|
|
447
448
|
const user = await config.createUser(structures.users.user({ email }))
|
|
448
449
|
user.email = "new@test.com"
|
|
449
450
|
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
// need to load environment first
|
|
2
|
+
import env from "./environment"
|
|
4
3
|
|
|
4
|
+
// enable APM if configured
|
|
5
5
|
if (process.env.ELASTIC_APM_ENABLED) {
|
|
6
|
-
require("
|
|
6
|
+
const apm = require("elastic-apm-node").start({
|
|
7
|
+
serviceName: process.env.SERVICE,
|
|
8
|
+
environment: process.env.BUDIBASE_ENVIRONMENT,
|
|
9
|
+
})
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
// need to load environment first
|
|
10
|
-
import env from "./environment"
|
|
11
12
|
import { Scope } from "@sentry/node"
|
|
12
13
|
import { Event } from "@sentry/types/dist/event"
|
|
13
14
|
import Application from "koa"
|
package/src/sdk/users/users.ts
CHANGED
|
@@ -264,6 +264,7 @@ export const save = async (
|
|
|
264
264
|
builtUser._rev = response.rev
|
|
265
265
|
|
|
266
266
|
await eventHelpers.handleSaveEvents(builtUser, dbUser)
|
|
267
|
+
await addTenant(tenantId, _id, email)
|
|
267
268
|
await cache.user.invalidateUser(response.id)
|
|
268
269
|
|
|
269
270
|
// let server know to sync user
|