@budibase/worker 2.3.18-alpha.8 → 2.3.18
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 +17 -13
- package/package.json +8 -11
- package/scripts/dev/manage.js +0 -1
- package/src/api/controllers/global/auth.ts +70 -77
- package/src/api/controllers/global/self.ts +44 -28
- package/src/api/controllers/global/users.ts +25 -65
- package/src/api/controllers/system/accounts.ts +5 -7
- package/src/api/controllers/system/tenants.ts +8 -4
- package/src/api/index.ts +20 -4
- package/src/api/routes/global/auth.ts +7 -10
- package/src/api/routes/global/tests/auth.spec.ts +17 -226
- package/src/api/routes/global/tests/configs.spec.ts +5 -5
- package/src/api/routes/global/tests/roles.spec.ts +14 -20
- package/src/api/routes/global/tests/self.spec.ts +4 -3
- package/src/api/routes/global/tests/users.spec.ts +27 -24
- 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/environment.ts +1 -15
- package/src/index.ts +7 -12
- package/src/middleware/tests/tenancy.spec.ts +4 -4
- package/src/migrations/functions/globalInfoSyncUsers.ts +3 -4
- package/src/sdk/accounts/{metadata.ts → accounts.ts} +1 -0
- package/src/sdk/accounts/index.ts +1 -2
- package/src/sdk/users/events.ts +0 -4
- package/src/sdk/users/index.ts +0 -1
- package/src/sdk/users/users.ts +46 -53
- package/src/tests/TestConfiguration.ts +62 -41
- package/src/tests/api/auth.ts +14 -42
- package/src/tests/api/base.ts +1 -2
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/restore.ts +0 -1
- package/src/tests/api/users.ts +2 -2
- package/src/tests/jestEnv.ts +1 -2
- package/src/tests/jestSetup.ts +6 -10
- package/src/tests/structures/index.ts +4 -0
- package/src/tests/structures/users.ts +37 -0
- package/src/utilities/email.ts +3 -3
- package/src/utilities/redis.ts +0 -2
- package/__mocks__/node-fetch.ts +0 -23
- package/jest-testcontainers-config.js +0 -8
- package/scripts/test.sh +0 -12
- package/src/ddApm.ts +0 -7
- package/src/elasticApm.ts +0 -10
- package/src/sdk/auth/auth.ts +0 -86
- package/src/sdk/auth/index.ts +0 -1
- package/src/sdk/tenants/index.ts +0 -1
- package/src/sdk/tenants/tenants.ts +0 -76
- package/src/sdk/users/tests/users.spec.ts +0 -52
- package/src/tests/logging.ts +0 -34
|
@@ -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
|
+
beforeAll(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.modeSelf()
|
|
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.modeCloud()
|
|
238
238
|
})
|
|
239
239
|
})
|
|
240
240
|
|
|
241
241
|
describe("update", () => {
|
|
242
242
|
it("should update settings config", async () => {
|
|
243
|
-
config.
|
|
243
|
+
config.modeSelf()
|
|
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.modeCloud()
|
|
260
260
|
})
|
|
261
261
|
})
|
|
262
262
|
})
|
|
@@ -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",
|
|
@@ -32,7 +32,6 @@ async function addAppMetadata() {
|
|
|
32
32
|
|
|
33
33
|
describe("/api/global/roles", () => {
|
|
34
34
|
const config = new TestConfiguration()
|
|
35
|
-
|
|
36
35
|
const role = new roles.Role(
|
|
37
36
|
db.generateRoleID("newRole"),
|
|
38
37
|
roles.BUILTIN_ROLE_IDS.BASIC,
|
|
@@ -40,17 +39,10 @@ describe("/api/global/roles", () => {
|
|
|
40
39
|
)
|
|
41
40
|
|
|
42
41
|
beforeAll(async () => {
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
42
|
+
console.debug(role)
|
|
43
|
+
appDb.put(role)
|
|
52
44
|
await addAppMetadata()
|
|
53
|
-
await
|
|
45
|
+
await config.beforeAll()
|
|
54
46
|
})
|
|
55
47
|
|
|
56
48
|
afterAll(async () => {
|
|
@@ -65,14 +57,16 @@ describe("/api/global/roles", () => {
|
|
|
65
57
|
it("retrieves roles", async () => {
|
|
66
58
|
const res = await config.api.roles.get()
|
|
67
59
|
expect(res.body).toBeDefined()
|
|
68
|
-
expect(res.body[
|
|
69
|
-
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
|
+
)
|
|
70
64
|
})
|
|
71
65
|
})
|
|
72
66
|
|
|
73
67
|
describe("GET api/global/roles/:appId", () => {
|
|
74
68
|
it("finds a role by appId", async () => {
|
|
75
|
-
const res = await config.api.roles.find(
|
|
69
|
+
const res = await config.api.roles.find("app_test")
|
|
76
70
|
expect(res.body).toBeDefined()
|
|
77
71
|
expect(res.body.name).toEqual("New App")
|
|
78
72
|
})
|
|
@@ -85,9 +79,9 @@ describe("/api/global/roles", () => {
|
|
|
85
79
|
app_test: "role1",
|
|
86
80
|
}
|
|
87
81
|
const userResponse = await config.createUser(user)
|
|
88
|
-
const res = await config.api.roles.remove(
|
|
82
|
+
const res = await config.api.roles.remove("app_test")
|
|
89
83
|
const updatedUser = await config.api.users.getUser(userResponse._id!)
|
|
90
|
-
expect(updatedUser.body.roles).not.toHaveProperty(
|
|
84
|
+
expect(updatedUser.body.roles).not.toHaveProperty("app_test")
|
|
91
85
|
expect(res.body.message).toEqual("App role removed from all users")
|
|
92
86
|
})
|
|
93
87
|
})
|
|
@@ -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(user)
|
|
34
34
|
expect(events.user.passwordUpdated).not.toBeCalled()
|
|
35
35
|
})
|
|
36
36
|
|
|
@@ -44,11 +44,12 @@ 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
|
|
47
48
|
expect(res.body._id).toBe(user._id)
|
|
48
49
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
49
|
-
expect(events.user.updated).toBeCalledWith(
|
|
50
|
+
expect(events.user.updated).toBeCalledWith(user)
|
|
50
51
|
expect(events.user.passwordUpdated).toBeCalledTimes(1)
|
|
51
|
-
expect(events.user.passwordUpdated).toBeCalledWith(
|
|
52
|
+
expect(events.user.passwordUpdated).toBeCalledWith(user)
|
|
52
53
|
})
|
|
53
54
|
})
|
|
54
55
|
})
|
|
@@ -1,11 +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 { events, tenancy
|
|
7
|
-
|
|
8
|
-
const accounts = jest.mocked(_accounts)
|
|
11
|
+
import { events, tenancy } from "@budibase/backend-core"
|
|
9
12
|
|
|
10
13
|
describe("/api/global/users", () => {
|
|
11
14
|
const config = new TestConfiguration()
|
|
@@ -22,7 +25,7 @@ describe("/api/global/users", () => {
|
|
|
22
25
|
jest.clearAllMocks()
|
|
23
26
|
})
|
|
24
27
|
|
|
25
|
-
describe("
|
|
28
|
+
describe("invite", () => {
|
|
26
29
|
it("should be able to generate an invitation", async () => {
|
|
27
30
|
const email = structures.users.newEmail()
|
|
28
31
|
const { code, res } = await config.api.users.sendUserInvite(
|
|
@@ -39,7 +42,7 @@ describe("/api/global/users", () => {
|
|
|
39
42
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
40
43
|
const { code, res } = await config.api.users.sendUserInvite(
|
|
41
44
|
sendMailMock,
|
|
42
|
-
config.
|
|
45
|
+
config.defaultUser!.email,
|
|
43
46
|
400
|
|
44
47
|
)
|
|
45
48
|
|
|
@@ -67,7 +70,7 @@ describe("/api/global/users", () => {
|
|
|
67
70
|
})
|
|
68
71
|
})
|
|
69
72
|
|
|
70
|
-
describe("
|
|
73
|
+
describe("inviteMultiple", () => {
|
|
71
74
|
it("should be able to generate an invitation", async () => {
|
|
72
75
|
const newUserInvite = () => ({
|
|
73
76
|
email: structures.users.newEmail(),
|
|
@@ -85,7 +88,7 @@ describe("/api/global/users", () => {
|
|
|
85
88
|
})
|
|
86
89
|
|
|
87
90
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
88
|
-
const request = [{ email: config.
|
|
91
|
+
const request = [{ email: config.defaultUser!.email, userInfo: {} }]
|
|
89
92
|
|
|
90
93
|
const res = await config.api.users.sendMultiUserInvite(request)
|
|
91
94
|
|
|
@@ -98,7 +101,7 @@ describe("/api/global/users", () => {
|
|
|
98
101
|
})
|
|
99
102
|
})
|
|
100
103
|
|
|
101
|
-
describe("
|
|
104
|
+
describe("bulk (create)", () => {
|
|
102
105
|
it("should ignore users existing in the same tenant", async () => {
|
|
103
106
|
const user = await config.createUser()
|
|
104
107
|
jest.clearAllMocks()
|
|
@@ -115,7 +118,7 @@ describe("/api/global/users", () => {
|
|
|
115
118
|
const user = await config.createUser()
|
|
116
119
|
jest.clearAllMocks()
|
|
117
120
|
|
|
118
|
-
await tenancy.doInTenant(
|
|
121
|
+
await tenancy.doInTenant(TENANT_1, async () => {
|
|
119
122
|
const response = await config.api.users.bulkCreateUsers([user])
|
|
120
123
|
|
|
121
124
|
expect(response.created?.successful.length).toBe(0)
|
|
@@ -161,7 +164,7 @@ describe("/api/global/users", () => {
|
|
|
161
164
|
})
|
|
162
165
|
})
|
|
163
166
|
|
|
164
|
-
describe("
|
|
167
|
+
describe("create", () => {
|
|
165
168
|
it("should be able to create a basic user", async () => {
|
|
166
169
|
const user = structures.users.user()
|
|
167
170
|
|
|
@@ -228,7 +231,7 @@ describe("/api/global/users", () => {
|
|
|
228
231
|
const user = await config.createUser()
|
|
229
232
|
jest.clearAllMocks()
|
|
230
233
|
|
|
231
|
-
await tenancy.doInTenant(
|
|
234
|
+
await tenancy.doInTenant(TENANT_1, async () => {
|
|
232
235
|
delete user._id
|
|
233
236
|
const response = await config.api.users.saveUser(user, 400)
|
|
234
237
|
|
|
@@ -240,7 +243,7 @@ describe("/api/global/users", () => {
|
|
|
240
243
|
it("should not be able to create user with the same email as an account", async () => {
|
|
241
244
|
const user = structures.users.user()
|
|
242
245
|
const account = structures.accounts.cloudAccount()
|
|
243
|
-
accounts.getAccount.mockReturnValueOnce(
|
|
246
|
+
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
244
247
|
|
|
245
248
|
const response = await config.api.users.saveUser(user, 400)
|
|
246
249
|
|
|
@@ -281,7 +284,7 @@ describe("/api/global/users", () => {
|
|
|
281
284
|
})
|
|
282
285
|
})
|
|
283
286
|
|
|
284
|
-
describe("
|
|
287
|
+
describe("update", () => {
|
|
285
288
|
it("should be able to update a basic user", async () => {
|
|
286
289
|
const user = await config.createUser()
|
|
287
290
|
jest.clearAllMocks()
|
|
@@ -296,7 +299,7 @@ describe("/api/global/users", () => {
|
|
|
296
299
|
})
|
|
297
300
|
|
|
298
301
|
it("should not allow a user to update their own admin/builder status", async () => {
|
|
299
|
-
const user = (await config.api.users.getUser(config.
|
|
302
|
+
const user = (await config.api.users.getUser(config.defaultUser?._id!))
|
|
300
303
|
.body as User
|
|
301
304
|
await config.api.users.saveUser({
|
|
302
305
|
...user,
|
|
@@ -441,7 +444,7 @@ describe("/api/global/users", () => {
|
|
|
441
444
|
})
|
|
442
445
|
|
|
443
446
|
it("should not be able to update email address", async () => {
|
|
444
|
-
const email =
|
|
447
|
+
const email = "email@test.com"
|
|
445
448
|
const user = await config.createUser(structures.users.user({ email }))
|
|
446
449
|
user.email = "new@test.com"
|
|
447
450
|
|
|
@@ -466,9 +469,9 @@ describe("/api/global/users", () => {
|
|
|
466
469
|
})
|
|
467
470
|
})
|
|
468
471
|
|
|
469
|
-
describe("
|
|
472
|
+
describe("bulk (delete)", () => {
|
|
470
473
|
it("should not be able to bulk delete current user", async () => {
|
|
471
|
-
const user = await config.
|
|
474
|
+
const user = await config.defaultUser!
|
|
472
475
|
|
|
473
476
|
const response = await config.api.users.bulkDeleteUsers([user._id!], 400)
|
|
474
477
|
|
|
@@ -480,7 +483,7 @@ describe("/api/global/users", () => {
|
|
|
480
483
|
const user = await config.createUser()
|
|
481
484
|
const account = structures.accounts.cloudAccount()
|
|
482
485
|
account.budibaseUserId = user._id!
|
|
483
|
-
accounts.getAccountByTenantId.mockReturnValue(
|
|
486
|
+
mocks.accounts.getAccountByTenantId.mockReturnValue(account)
|
|
484
487
|
|
|
485
488
|
const response = await config.api.users.bulkDeleteUsers([user._id!])
|
|
486
489
|
|
|
@@ -495,7 +498,7 @@ describe("/api/global/users", () => {
|
|
|
495
498
|
|
|
496
499
|
it("should be able to bulk delete users", async () => {
|
|
497
500
|
const account = structures.accounts.cloudAccount()
|
|
498
|
-
accounts.getAccountByTenantId.mockReturnValue(
|
|
501
|
+
mocks.accounts.getAccountByTenantId.mockReturnValue(account)
|
|
499
502
|
|
|
500
503
|
const builder = structures.users.builderUser()
|
|
501
504
|
const admin = structures.users.adminUser()
|
|
@@ -519,7 +522,7 @@ describe("/api/global/users", () => {
|
|
|
519
522
|
})
|
|
520
523
|
})
|
|
521
524
|
|
|
522
|
-
describe("
|
|
525
|
+
describe("destroy", () => {
|
|
523
526
|
it("should be able to destroy a basic user", async () => {
|
|
524
527
|
const user = await config.createUser()
|
|
525
528
|
jest.clearAllMocks()
|
|
@@ -556,7 +559,7 @@ describe("/api/global/users", () => {
|
|
|
556
559
|
it("should not be able to destroy account owner", async () => {
|
|
557
560
|
const user = await config.createUser()
|
|
558
561
|
const account = structures.accounts.cloudAccount()
|
|
559
|
-
accounts.getAccount.mockReturnValueOnce(
|
|
562
|
+
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
560
563
|
|
|
561
564
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
562
565
|
|
|
@@ -564,10 +567,10 @@ describe("/api/global/users", () => {
|
|
|
564
567
|
})
|
|
565
568
|
|
|
566
569
|
it("should not be able to destroy account owner as account owner", async () => {
|
|
567
|
-
const user = await config.
|
|
570
|
+
const user = await config.defaultUser!
|
|
568
571
|
const account = structures.accounts.cloudAccount()
|
|
569
572
|
account.email = user.email
|
|
570
|
-
accounts.getAccount.mockReturnValueOnce(
|
|
573
|
+
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
571
574
|
|
|
572
575
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
573
576
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import sdk from "../../../../sdk"
|
|
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 = accounts.
|
|
28
|
-
const metadata = await accounts.
|
|
27
|
+
const id = sdk.accounts.formatAccountMetadataId(account.accountId)
|
|
28
|
+
const metadata = await sdk.accounts.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 accounts.
|
|
40
|
+
const deleted = await sdk.accounts.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.text).toBe("Unauthorized - no public worker access")
|
|
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.text).toBe("Unauthorized - no public worker access")
|
|
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.modeSelf()
|
|
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.modeCloud()
|
|
34
34
|
})
|
|
35
35
|
})
|
|
36
36
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TestConfiguration } from "../../../../tests"
|
|
2
|
-
import { accounts
|
|
3
|
-
|
|
2
|
+
import { accounts } from "@budibase/backend-core"
|
|
3
|
+
import { mocks } from "@budibase/backend-core/tests"
|
|
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.modeSelf()
|
|
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.modeCloud()
|
|
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
|
-
accounts.getStatus.mockReturnValueOnce(
|
|
40
|
+
mocks.accounts.getStatus.mockReturnValueOnce(value)
|
|
41
41
|
|
|
42
42
|
const res = await config.api.status.getStatus()
|
|
43
43
|
|
package/src/environment.ts
CHANGED
|
@@ -26,8 +26,6 @@ function parseIntSafe(number: any) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const selfHosted = !!parseInt(process.env.SELF_HOSTED || "")
|
|
30
|
-
|
|
31
29
|
const environment = {
|
|
32
30
|
// auth
|
|
33
31
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
@@ -51,7 +49,7 @@ const environment = {
|
|
|
51
49
|
CLUSTER_PORT: process.env.CLUSTER_PORT,
|
|
52
50
|
// flags
|
|
53
51
|
NODE_ENV: process.env.NODE_ENV,
|
|
54
|
-
SELF_HOSTED:
|
|
52
|
+
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED || ""),
|
|
55
53
|
LOG_LEVEL: process.env.LOG_LEVEL,
|
|
56
54
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
57
55
|
DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
|
|
@@ -67,18 +65,6 @@ const environment = {
|
|
|
67
65
|
CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
|
|
68
66
|
SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
|
|
69
67
|
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,
|
|
82
68
|
_set(key: any, value: any) {
|
|
83
69
|
process.env[key] = value
|
|
84
70
|
// @ts-ignore
|
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"
|
|
@@ -25,12 +26,6 @@ const koaSession = require("koa-session")
|
|
|
25
26
|
const logger = require("koa-pino-logger")
|
|
26
27
|
import destroyable from "server-destroy"
|
|
27
28
|
|
|
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
|
-
|
|
34
29
|
// this will setup http and https proxies form env variables
|
|
35
30
|
bootstrap()
|
|
36
31
|
|
|
@@ -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.uuid()
|
|
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.uuid()
|
|
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.uuid()
|
|
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.text).toBe("Tenant id not set")
|
|
71
71
|
expect(res.headers[constants.Header.TENANT_ID]).toBe(undefined)
|
|
72
72
|
})
|
|
73
73
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { User } from "@budibase/types"
|
|
2
|
-
import
|
|
3
|
-
import { platform } from "@budibase/backend-core"
|
|
2
|
+
import sdk from "../../sdk"
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Date:
|
|
@@ -10,11 +9,11 @@ import { platform } from "@budibase/backend-core"
|
|
|
10
9
|
* Re-sync the global-db users to the global-info db users
|
|
11
10
|
*/
|
|
12
11
|
export const run = async (globalDb: any) => {
|
|
13
|
-
const users = (await
|
|
12
|
+
const users = (await sdk.users.allUsers()) as User[]
|
|
14
13
|
const promises = []
|
|
15
14
|
for (let user of users) {
|
|
16
15
|
promises.push(
|
|
17
|
-
|
|
16
|
+
sdk.users.addTenant(user.tenantId, user._id as string, user.email)
|
|
18
17
|
)
|
|
19
18
|
}
|
|
20
19
|
await Promise.all(promises)
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export *
|
|
2
|
-
export { accounts as api } from "@budibase/backend-core"
|
|
1
|
+
export * from "./accounts"
|
package/src/sdk/users/events.ts
CHANGED
package/src/sdk/users/index.ts
CHANGED