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