@budibase/worker 2.3.17 → 2.3.18-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 +10 -7
- package/scripts/dev/manage.js +1 -0
- package/src/api/controllers/global/auth.ts +77 -70
- package/src/api/controllers/global/self.ts +28 -44
- package/src/api/controllers/global/users.ts +65 -25
- package/src/api/controllers/system/accounts.ts +7 -5
- package/src/api/controllers/system/tenants.ts +4 -8
- package/src/api/index.ts +4 -20
- package/src/api/routes/global/auth.ts +10 -7
- package/src/api/routes/global/tests/auth.spec.ts +226 -17
- package/src/api/routes/global/tests/configs.spec.ts +5 -5
- package/src/api/routes/global/tests/roles.spec.ts +20 -14
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/users.spec.ts +24 -27
- package/src/api/routes/system/tenants.ts +1 -1
- package/src/api/routes/system/tests/accounts.spec.ts +4 -4
- package/src/api/routes/system/tests/migrations.spec.ts +2 -2
- package/src/api/routes/system/tests/restore.spec.ts +2 -2
- package/src/api/routes/system/tests/status.spec.ts +5 -5
- package/src/ddApm.ts +7 -0
- package/src/elasticApm.ts +10 -0
- package/src/environment.ts +15 -1
- package/src/index.ts +12 -7
- package/src/middleware/tests/tenancy.spec.ts +4 -4
- package/src/migrations/functions/globalInfoSyncUsers.ts +4 -3
- package/src/sdk/accounts/index.ts +2 -1
- package/src/sdk/accounts/{accounts.ts → metadata.ts} +0 -1
- package/src/sdk/auth/auth.ts +86 -0
- package/src/sdk/auth/index.ts +1 -0
- package/src/sdk/tenants/index.ts +1 -0
- package/src/sdk/tenants/tenants.ts +76 -0
- package/src/sdk/users/events.ts +4 -0
- package/src/sdk/users/index.ts +1 -0
- package/src/sdk/users/tests/users.spec.ts +52 -0
- package/src/sdk/users/users.ts +53 -46
- package/src/tests/TestConfiguration.ts +41 -62
- package/src/tests/api/auth.ts +42 -14
- package/src/tests/api/base.ts +2 -1
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/restore.ts +1 -0
- package/src/tests/api/users.ts +2 -2
- package/src/tests/jestEnv.ts +2 -1
- package/src/tests/jestSetup.ts +10 -6
- package/src/tests/logging.ts +34 -0
- package/src/tests/structures/index.ts +0 -4
- package/src/utilities/email.ts +3 -3
- 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
- package/src/tests/structures/users.ts +0 -37
|
@@ -7,7 +7,7 @@ import { Config, events } from "@budibase/backend-core"
|
|
|
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
|
|
|
@@ -221,7 +221,7 @@ describe("configs", () => {
|
|
|
221
221
|
})
|
|
222
222
|
|
|
223
223
|
it("should create settings config with non-default settings", async () => {
|
|
224
|
-
config.
|
|
224
|
+
config.selfHosted()
|
|
225
225
|
await config.deleteConfig(Config.SETTINGS)
|
|
226
226
|
const conf = {
|
|
227
227
|
company: "acme",
|
|
@@ -234,13 +234,13 @@ describe("configs", () => {
|
|
|
234
234
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
235
235
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
236
236
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
237
|
-
config.
|
|
237
|
+
config.cloudHosted()
|
|
238
238
|
})
|
|
239
239
|
})
|
|
240
240
|
|
|
241
241
|
describe("update", () => {
|
|
242
242
|
it("should update settings config", async () => {
|
|
243
|
-
config.
|
|
243
|
+
config.selfHosted()
|
|
244
244
|
await config.deleteConfig(Config.SETTINGS)
|
|
245
245
|
const settingsConfig = await saveSettingsConfig()
|
|
246
246
|
settingsConfig.config.company = "acme"
|
|
@@ -256,7 +256,7 @@ describe("configs", () => {
|
|
|
256
256
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
257
257
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
258
258
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
259
|
-
config.
|
|
259
|
+
config.cloudHosted()
|
|
260
260
|
})
|
|
261
261
|
})
|
|
262
262
|
})
|
|
@@ -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",
|
|
@@ -32,6 +32,7 @@ async function addAppMetadata() {
|
|
|
32
32
|
|
|
33
33
|
describe("/api/global/roles", () => {
|
|
34
34
|
const config = new TestConfiguration()
|
|
35
|
+
|
|
35
36
|
const role = new roles.Role(
|
|
36
37
|
db.generateRoleID("newRole"),
|
|
37
38
|
roles.BUILTIN_ROLE_IDS.BASIC,
|
|
@@ -39,12 +40,19 @@ describe("/api/global/roles", () => {
|
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
beforeAll(async () => {
|
|
42
|
-
console.debug(role)
|
|
43
|
-
appDb.put(role)
|
|
44
|
-
await addAppMetadata()
|
|
45
43
|
await config.beforeAll()
|
|
46
44
|
})
|
|
47
45
|
|
|
46
|
+
beforeEach(async () => {
|
|
47
|
+
appId = db.generateAppID(config.tenantId)
|
|
48
|
+
appDb = db.getDB(appId)
|
|
49
|
+
const mockAppDB = context.getAppDB as Mock
|
|
50
|
+
mockAppDB.mockReturnValue(appDb)
|
|
51
|
+
|
|
52
|
+
await addAppMetadata()
|
|
53
|
+
await appDb.put(role)
|
|
54
|
+
})
|
|
55
|
+
|
|
48
56
|
afterAll(async () => {
|
|
49
57
|
await config.afterAll()
|
|
50
58
|
})
|
|
@@ -57,16 +65,14 @@ describe("/api/global/roles", () => {
|
|
|
57
65
|
it("retrieves roles", async () => {
|
|
58
66
|
const res = await config.api.roles.get()
|
|
59
67
|
expect(res.body).toBeDefined()
|
|
60
|
-
expect(res.body[
|
|
61
|
-
expect(res.body[
|
|
62
|
-
role._id
|
|
63
|
-
)
|
|
68
|
+
expect(res.body[appId].roles.length).toEqual(5)
|
|
69
|
+
expect(res.body[appId].roles.map((r: any) => r._id)).toContain(role._id)
|
|
64
70
|
})
|
|
65
71
|
})
|
|
66
72
|
|
|
67
73
|
describe("GET api/global/roles/:appId", () => {
|
|
68
74
|
it("finds a role by appId", async () => {
|
|
69
|
-
const res = await config.api.roles.find(
|
|
75
|
+
const res = await config.api.roles.find(appId)
|
|
70
76
|
expect(res.body).toBeDefined()
|
|
71
77
|
expect(res.body.name).toEqual("New App")
|
|
72
78
|
})
|
|
@@ -79,9 +85,9 @@ describe("/api/global/roles", () => {
|
|
|
79
85
|
app_test: "role1",
|
|
80
86
|
}
|
|
81
87
|
const userResponse = await config.createUser(user)
|
|
82
|
-
const res = await config.api.roles.remove(
|
|
88
|
+
const res = await config.api.roles.remove(appId)
|
|
83
89
|
const updatedUser = await config.api.users.getUser(userResponse._id!)
|
|
84
|
-
expect(updatedUser.body.roles).not.toHaveProperty(
|
|
90
|
+
expect(updatedUser.body.roles).not.toHaveProperty(appId)
|
|
85
91
|
expect(res.body.message).toEqual("App role removed from all users")
|
|
86
92
|
})
|
|
87
93
|
})
|
|
@@ -30,7 +30,7 @@ describe("/api/global/self", () => {
|
|
|
30
30
|
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
|
|
31
31
|
expect(res.body._id).toBe(user._id)
|
|
32
32
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
33
|
-
expect(events.user.updated).toBeCalledWith(
|
|
33
|
+
expect(events.user.updated).toBeCalledWith(dbUser)
|
|
34
34
|
expect(events.user.passwordUpdated).not.toBeCalled()
|
|
35
35
|
})
|
|
36
36
|
|
|
@@ -44,12 +44,11 @@ describe("/api/global/self", () => {
|
|
|
44
44
|
const dbUser = await config.getUser(user.email)
|
|
45
45
|
user._rev = dbUser._rev
|
|
46
46
|
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
|
|
47
|
-
delete user.password
|
|
48
47
|
expect(res.body._id).toBe(user._id)
|
|
49
48
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
50
|
-
expect(events.user.updated).toBeCalledWith(
|
|
49
|
+
expect(events.user.updated).toBeCalledWith(dbUser)
|
|
51
50
|
expect(events.user.passwordUpdated).toBeCalledTimes(1)
|
|
52
|
-
expect(events.user.passwordUpdated).toBeCalledWith(
|
|
51
|
+
expect(events.user.passwordUpdated).toBeCalledWith(dbUser)
|
|
53
52
|
})
|
|
54
53
|
})
|
|
55
54
|
})
|
|
@@ -1,14 +1,11 @@
|
|
|
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 { events, tenancy, accounts as _accounts } from "@budibase/backend-core"
|
|
7
|
+
|
|
8
|
+
const accounts = jest.mocked(_accounts)
|
|
12
9
|
|
|
13
10
|
describe("/api/global/users", () => {
|
|
14
11
|
const config = new TestConfiguration()
|
|
@@ -25,7 +22,7 @@ describe("/api/global/users", () => {
|
|
|
25
22
|
jest.clearAllMocks()
|
|
26
23
|
})
|
|
27
24
|
|
|
28
|
-
describe("invite", () => {
|
|
25
|
+
describe("POST /api/global/users/invite", () => {
|
|
29
26
|
it("should be able to generate an invitation", async () => {
|
|
30
27
|
const email = structures.users.newEmail()
|
|
31
28
|
const { code, res } = await config.api.users.sendUserInvite(
|
|
@@ -42,7 +39,7 @@ describe("/api/global/users", () => {
|
|
|
42
39
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
43
40
|
const { code, res } = await config.api.users.sendUserInvite(
|
|
44
41
|
sendMailMock,
|
|
45
|
-
config.
|
|
42
|
+
config.user!.email,
|
|
46
43
|
400
|
|
47
44
|
)
|
|
48
45
|
|
|
@@ -70,7 +67,7 @@ describe("/api/global/users", () => {
|
|
|
70
67
|
})
|
|
71
68
|
})
|
|
72
69
|
|
|
73
|
-
describe("
|
|
70
|
+
describe("POST /api/global/users/multi/invite", () => {
|
|
74
71
|
it("should be able to generate an invitation", async () => {
|
|
75
72
|
const newUserInvite = () => ({
|
|
76
73
|
email: structures.users.newEmail(),
|
|
@@ -88,7 +85,7 @@ describe("/api/global/users", () => {
|
|
|
88
85
|
})
|
|
89
86
|
|
|
90
87
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
91
|
-
const request = [{ email: config.
|
|
88
|
+
const request = [{ email: config.user!.email, userInfo: {} }]
|
|
92
89
|
|
|
93
90
|
const res = await config.api.users.sendMultiUserInvite(request)
|
|
94
91
|
|
|
@@ -101,7 +98,7 @@ describe("/api/global/users", () => {
|
|
|
101
98
|
})
|
|
102
99
|
})
|
|
103
100
|
|
|
104
|
-
describe("bulk
|
|
101
|
+
describe("POST /api/global/users/bulk", () => {
|
|
105
102
|
it("should ignore users existing in the same tenant", async () => {
|
|
106
103
|
const user = await config.createUser()
|
|
107
104
|
jest.clearAllMocks()
|
|
@@ -118,7 +115,7 @@ describe("/api/global/users", () => {
|
|
|
118
115
|
const user = await config.createUser()
|
|
119
116
|
jest.clearAllMocks()
|
|
120
117
|
|
|
121
|
-
await tenancy.doInTenant(
|
|
118
|
+
await tenancy.doInTenant(config.getTenantId(), async () => {
|
|
122
119
|
const response = await config.api.users.bulkCreateUsers([user])
|
|
123
120
|
|
|
124
121
|
expect(response.created?.successful.length).toBe(0)
|
|
@@ -164,7 +161,7 @@ describe("/api/global/users", () => {
|
|
|
164
161
|
})
|
|
165
162
|
})
|
|
166
163
|
|
|
167
|
-
describe("
|
|
164
|
+
describe("POST /api/global/users", () => {
|
|
168
165
|
it("should be able to create a basic user", async () => {
|
|
169
166
|
const user = structures.users.user()
|
|
170
167
|
|
|
@@ -231,7 +228,7 @@ describe("/api/global/users", () => {
|
|
|
231
228
|
const user = await config.createUser()
|
|
232
229
|
jest.clearAllMocks()
|
|
233
230
|
|
|
234
|
-
await tenancy.doInTenant(
|
|
231
|
+
await tenancy.doInTenant(config.getTenantId(), async () => {
|
|
235
232
|
delete user._id
|
|
236
233
|
const response = await config.api.users.saveUser(user, 400)
|
|
237
234
|
|
|
@@ -243,7 +240,7 @@ describe("/api/global/users", () => {
|
|
|
243
240
|
it("should not be able to create user with the same email as an account", async () => {
|
|
244
241
|
const user = structures.users.user()
|
|
245
242
|
const account = structures.accounts.cloudAccount()
|
|
246
|
-
|
|
243
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
247
244
|
|
|
248
245
|
const response = await config.api.users.saveUser(user, 400)
|
|
249
246
|
|
|
@@ -284,7 +281,7 @@ describe("/api/global/users", () => {
|
|
|
284
281
|
})
|
|
285
282
|
})
|
|
286
283
|
|
|
287
|
-
describe("update", () => {
|
|
284
|
+
describe("POST /api/global/users (update)", () => {
|
|
288
285
|
it("should be able to update a basic user", async () => {
|
|
289
286
|
const user = await config.createUser()
|
|
290
287
|
jest.clearAllMocks()
|
|
@@ -299,7 +296,7 @@ describe("/api/global/users", () => {
|
|
|
299
296
|
})
|
|
300
297
|
|
|
301
298
|
it("should not allow a user to update their own admin/builder status", async () => {
|
|
302
|
-
const user = (await config.api.users.getUser(config.
|
|
299
|
+
const user = (await config.api.users.getUser(config.user?._id!))
|
|
303
300
|
.body as User
|
|
304
301
|
await config.api.users.saveUser({
|
|
305
302
|
...user,
|
|
@@ -444,7 +441,7 @@ describe("/api/global/users", () => {
|
|
|
444
441
|
})
|
|
445
442
|
|
|
446
443
|
it("should not be able to update email address", async () => {
|
|
447
|
-
const email =
|
|
444
|
+
const email = structures.email()
|
|
448
445
|
const user = await config.createUser(structures.users.user({ email }))
|
|
449
446
|
user.email = "new@test.com"
|
|
450
447
|
|
|
@@ -469,9 +466,9 @@ describe("/api/global/users", () => {
|
|
|
469
466
|
})
|
|
470
467
|
})
|
|
471
468
|
|
|
472
|
-
describe("bulk (delete)", () => {
|
|
469
|
+
describe("POST /api/global/users/bulk (delete)", () => {
|
|
473
470
|
it("should not be able to bulk delete current user", async () => {
|
|
474
|
-
const user = await config.
|
|
471
|
+
const user = await config.user!
|
|
475
472
|
|
|
476
473
|
const response = await config.api.users.bulkDeleteUsers([user._id!], 400)
|
|
477
474
|
|
|
@@ -483,7 +480,7 @@ describe("/api/global/users", () => {
|
|
|
483
480
|
const user = await config.createUser()
|
|
484
481
|
const account = structures.accounts.cloudAccount()
|
|
485
482
|
account.budibaseUserId = user._id!
|
|
486
|
-
|
|
483
|
+
accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
|
|
487
484
|
|
|
488
485
|
const response = await config.api.users.bulkDeleteUsers([user._id!])
|
|
489
486
|
|
|
@@ -498,7 +495,7 @@ describe("/api/global/users", () => {
|
|
|
498
495
|
|
|
499
496
|
it("should be able to bulk delete users", async () => {
|
|
500
497
|
const account = structures.accounts.cloudAccount()
|
|
501
|
-
|
|
498
|
+
accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
|
|
502
499
|
|
|
503
500
|
const builder = structures.users.builderUser()
|
|
504
501
|
const admin = structures.users.adminUser()
|
|
@@ -522,7 +519,7 @@ describe("/api/global/users", () => {
|
|
|
522
519
|
})
|
|
523
520
|
})
|
|
524
521
|
|
|
525
|
-
describe("
|
|
522
|
+
describe("DELETE /api/global/users/:userId", () => {
|
|
526
523
|
it("should be able to destroy a basic user", async () => {
|
|
527
524
|
const user = await config.createUser()
|
|
528
525
|
jest.clearAllMocks()
|
|
@@ -559,7 +556,7 @@ describe("/api/global/users", () => {
|
|
|
559
556
|
it("should not be able to destroy account owner", async () => {
|
|
560
557
|
const user = await config.createUser()
|
|
561
558
|
const account = structures.accounts.cloudAccount()
|
|
562
|
-
|
|
559
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
563
560
|
|
|
564
561
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
565
562
|
|
|
@@ -567,10 +564,10 @@ describe("/api/global/users", () => {
|
|
|
567
564
|
})
|
|
568
565
|
|
|
569
566
|
it("should not be able to destroy account owner as account owner", async () => {
|
|
570
|
-
const user = await config.
|
|
567
|
+
const user = await config.user!
|
|
571
568
|
const account = structures.accounts.cloudAccount()
|
|
572
569
|
account.email = user.email
|
|
573
|
-
|
|
570
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
574
571
|
|
|
575
572
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
576
573
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as accounts from "../../../../sdk/accounts"
|
|
2
2
|
import { TestConfiguration, structures } from "../../../../tests"
|
|
3
3
|
import { v4 as uuid } from "uuid"
|
|
4
4
|
|
|
@@ -24,8 +24,8 @@ describe("accounts", () => {
|
|
|
24
24
|
|
|
25
25
|
const response = await config.api.accounts.saveMetadata(account)
|
|
26
26
|
|
|
27
|
-
const id =
|
|
28
|
-
const metadata = await
|
|
27
|
+
const id = accounts.metadata.formatAccountMetadataId(account.accountId)
|
|
28
|
+
const metadata = await accounts.metadata.getMetadata(id)
|
|
29
29
|
expect(response).toStrictEqual(metadata)
|
|
30
30
|
})
|
|
31
31
|
})
|
|
@@ -37,7 +37,7 @@ describe("accounts", () => {
|
|
|
37
37
|
|
|
38
38
|
await config.api.accounts.destroyMetadata(account.accountId)
|
|
39
39
|
|
|
40
|
-
const deleted = await
|
|
40
|
+
const deleted = await accounts.metadata.getMetadata(account.accountId)
|
|
41
41
|
expect(deleted).toBe(undefined)
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -30,7 +30,7 @@ describe("/api/system/migrations", () => {
|
|
|
30
30
|
headers: {},
|
|
31
31
|
status: 403,
|
|
32
32
|
})
|
|
33
|
-
expect(res.
|
|
33
|
+
expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
|
|
34
34
|
expect(migrateFn).toBeCalledTimes(0)
|
|
35
35
|
})
|
|
36
36
|
|
|
@@ -47,7 +47,7 @@ describe("/api/system/migrations", () => {
|
|
|
47
47
|
headers: {},
|
|
48
48
|
status: 403,
|
|
49
49
|
})
|
|
50
|
-
expect(res.
|
|
50
|
+
expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
it("returns definitions", async () => {
|
|
@@ -25,12 +25,12 @@ describe("/api/system/restore", () => {
|
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it("restores in self host", async () => {
|
|
28
|
-
config.
|
|
28
|
+
config.selfHosted()
|
|
29
29
|
const res = await config.api.restore.restored()
|
|
30
30
|
expect(res.body).toEqual({
|
|
31
31
|
message: "System prepared after restore.",
|
|
32
32
|
})
|
|
33
|
-
config.
|
|
33
|
+
config.cloudHosted()
|
|
34
34
|
})
|
|
35
35
|
})
|
|
36
36
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TestConfiguration } from "../../../../tests"
|
|
2
|
-
import { accounts } from "@budibase/backend-core"
|
|
3
|
-
|
|
2
|
+
import { accounts as _accounts } from "@budibase/backend-core"
|
|
3
|
+
const accounts = jest.mocked(_accounts)
|
|
4
4
|
|
|
5
5
|
describe("/api/system/status", () => {
|
|
6
6
|
const config = new TestConfiguration()
|
|
@@ -19,7 +19,7 @@ describe("/api/system/status", () => {
|
|
|
19
19
|
|
|
20
20
|
describe("GET /api/system/status", () => {
|
|
21
21
|
it("returns status in self host", async () => {
|
|
22
|
-
config.
|
|
22
|
+
config.selfHosted()
|
|
23
23
|
const res = await config.api.status.getStatus()
|
|
24
24
|
expect(res.body).toEqual({
|
|
25
25
|
health: {
|
|
@@ -27,7 +27,7 @@ describe("/api/system/status", () => {
|
|
|
27
27
|
},
|
|
28
28
|
})
|
|
29
29
|
expect(accounts.getStatus).toBeCalledTimes(0)
|
|
30
|
-
config.
|
|
30
|
+
config.cloudHosted()
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it("returns status in cloud", async () => {
|
|
@@ -37,7 +37,7 @@ describe("/api/system/status", () => {
|
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
accounts.getStatus.mockReturnValueOnce(Promise.resolve(value))
|
|
41
41
|
|
|
42
42
|
const res = await config.api.status.getStatus()
|
|
43
43
|
|
package/src/ddApm.ts
ADDED
package/src/environment.ts
CHANGED
|
@@ -26,6 +26,8 @@ function parseIntSafe(number: any) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const selfHosted = !!parseInt(process.env.SELF_HOSTED || "")
|
|
30
|
+
|
|
29
31
|
const environment = {
|
|
30
32
|
// auth
|
|
31
33
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
@@ -49,7 +51,7 @@ const environment = {
|
|
|
49
51
|
CLUSTER_PORT: process.env.CLUSTER_PORT,
|
|
50
52
|
// flags
|
|
51
53
|
NODE_ENV: process.env.NODE_ENV,
|
|
52
|
-
SELF_HOSTED:
|
|
54
|
+
SELF_HOSTED: selfHosted,
|
|
53
55
|
LOG_LEVEL: process.env.LOG_LEVEL,
|
|
54
56
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
55
57
|
DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
|
|
@@ -65,6 +67,18 @@ const environment = {
|
|
|
65
67
|
CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
|
|
66
68
|
SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
|
|
67
69
|
ENCRYPTED_TEST_PUBLIC_API_KEY: process.env.ENCRYPTED_TEST_PUBLIC_API_KEY,
|
|
70
|
+
/**
|
|
71
|
+
* Mock the email service in use - links to ethereal hosted emails are logged instead.
|
|
72
|
+
*/
|
|
73
|
+
ENABLE_EMAIL_TEST_MODE: process.env.ENABLE_EMAIL_TEST_MODE,
|
|
74
|
+
/**
|
|
75
|
+
* Enable to allow an admin user to login using a password.
|
|
76
|
+
* This can be useful to prevent lockout when configuring SSO.
|
|
77
|
+
* However, this should be turned OFF by default for security purposes.
|
|
78
|
+
*/
|
|
79
|
+
ENABLE_SSO_MAINTENANCE_MODE: selfHosted
|
|
80
|
+
? process.env.ENABLE_SSO_MAINTENANCE_MODE
|
|
81
|
+
: false,
|
|
68
82
|
_set(key: any, value: any) {
|
|
69
83
|
process.env[key] = value
|
|
70
84
|
// @ts-ignore
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
if (process.env.DD_APM_ENABLED) {
|
|
2
|
+
require("./ddApm")
|
|
3
|
+
}
|
|
3
4
|
|
|
4
|
-
// enable APM if configured
|
|
5
5
|
if (process.env.ELASTIC_APM_ENABLED) {
|
|
6
|
-
|
|
7
|
-
serviceName: process.env.SERVICE,
|
|
8
|
-
environment: process.env.BUDIBASE_ENVIRONMENT,
|
|
9
|
-
})
|
|
6
|
+
require("./elasticApm")
|
|
10
7
|
}
|
|
11
8
|
|
|
9
|
+
// need to load environment first
|
|
10
|
+
import env from "./environment"
|
|
12
11
|
import { Scope } from "@sentry/node"
|
|
13
12
|
import { Event } from "@sentry/types/dist/event"
|
|
14
13
|
import Application from "koa"
|
|
@@ -26,6 +25,12 @@ const koaSession = require("koa-session")
|
|
|
26
25
|
const logger = require("koa-pino-logger")
|
|
27
26
|
import destroyable from "server-destroy"
|
|
28
27
|
|
|
28
|
+
if (env.ENABLE_SSO_MAINTENANCE_MODE) {
|
|
29
|
+
console.warn(
|
|
30
|
+
"Warning: ENABLE_SSO_MAINTENANCE_MODE is set. It is recommended this flag is disabled if maintenance is not in progress"
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
// this will setup http and https proxies form env variables
|
|
30
35
|
bootstrap()
|
|
31
36
|
|
|
@@ -24,7 +24,7 @@ describe("tenancy middleware", () => {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
it("should get tenant id from header", async () => {
|
|
27
|
-
const tenantId = structures.
|
|
27
|
+
const tenantId = structures.tenant.id()
|
|
28
28
|
const headers = {
|
|
29
29
|
[constants.Header.TENANT_ID]: tenantId,
|
|
30
30
|
}
|
|
@@ -35,7 +35,7 @@ describe("tenancy middleware", () => {
|
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
it("should get tenant id from query param", async () => {
|
|
38
|
-
const tenantId = structures.
|
|
38
|
+
const tenantId = structures.tenant.id()
|
|
39
39
|
const res = await config.request.get(
|
|
40
40
|
`/api/global/configs/checklist?tenantId=${tenantId}`
|
|
41
41
|
)
|
|
@@ -43,7 +43,7 @@ describe("tenancy middleware", () => {
|
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
it("should get tenant id from subdomain", async () => {
|
|
46
|
-
const tenantId = structures.
|
|
46
|
+
const tenantId = structures.tenant.id()
|
|
47
47
|
const headers = {
|
|
48
48
|
host: `${tenantId}.localhost:10000`,
|
|
49
49
|
}
|
|
@@ -67,7 +67,7 @@ describe("tenancy middleware", () => {
|
|
|
67
67
|
it("should throw when no tenant id is found", async () => {
|
|
68
68
|
const res = await config.request.get(`/api/global/configs/checklist`)
|
|
69
69
|
expect(res.status).toBe(403)
|
|
70
|
-
expect(res.
|
|
70
|
+
expect(res.body).toEqual({ message: "Tenant id not set", status: 403 })
|
|
71
71
|
expect(res.headers[constants.Header.TENANT_ID]).toBe(undefined)
|
|
72
72
|
})
|
|
73
73
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { User } from "@budibase/types"
|
|
2
|
-
import
|
|
2
|
+
import * as usersSdk from "../../sdk/users"
|
|
3
|
+
import { platform } from "@budibase/backend-core"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Date:
|
|
@@ -9,11 +10,11 @@ import sdk from "../../sdk"
|
|
|
9
10
|
* Re-sync the global-db users to the global-info db users
|
|
10
11
|
*/
|
|
11
12
|
export const run = async (globalDb: any) => {
|
|
12
|
-
const users = (await
|
|
13
|
+
const users = (await usersSdk.allUsers()) as User[]
|
|
13
14
|
const promises = []
|
|
14
15
|
for (let user of users) {
|
|
15
16
|
promises.push(
|
|
16
|
-
|
|
17
|
+
platform.users.addUser(user.tenantId, user._id as string, user.email)
|
|
17
18
|
)
|
|
18
19
|
}
|
|
19
20
|
await Promise.all(promises)
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * as metadata from "./metadata"
|
|
2
|
+
export { accounts as api } from "@budibase/backend-core"
|