@budibase/worker 2.3.17-alpha.4 → 2.3.17-alpha.5
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/package.json +8 -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 +234 -33
- package/src/api/routes/global/tests/configs.spec.ts +93 -113
- package/src/api/routes/global/tests/roles.spec.ts +3 -2
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/users.spec.ts +44 -46
- 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 +15 -1
- package/src/index.ts +6 -0
- 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 +38 -89
- package/src/tests/api/auth.ts +42 -18
- package/src/tests/api/base.ts +2 -1
- package/src/tests/api/restore.ts +1 -0
- package/src/tests/jestEnv.ts +2 -1
- package/src/tests/jestSetup.ts +2 -5
- package/src/tests/logging.ts +34 -0
- package/src/tests/structures/index.ts +0 -2
- package/src/utilities/email.ts +3 -3
- package/src/tests/structures/users.ts +0 -37
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
3
|
import { TestConfiguration, structures, mocks } from "../../../../tests"
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
import { Config,
|
|
5
|
+
import { Config, events } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
describe("configs", () => {
|
|
8
8
|
const config = new TestConfiguration()
|
|
@@ -113,64 +113,56 @@ describe("configs", () => {
|
|
|
113
113
|
|
|
114
114
|
describe("create", () => {
|
|
115
115
|
it("should create activated OIDC config", async () => {
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await config.deleteConfig(Config.OIDC)
|
|
124
|
-
})
|
|
116
|
+
await saveOIDCConfig()
|
|
117
|
+
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
118
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
119
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
120
|
+
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
121
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
122
|
+
await config.deleteConfig(Config.OIDC)
|
|
125
123
|
})
|
|
126
124
|
|
|
127
125
|
it("should create deactivated OIDC config", async () => {
|
|
128
|
-
await
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await config.deleteConfig(Config.OIDC)
|
|
135
|
-
})
|
|
126
|
+
await saveOIDCConfig({ activated: false })
|
|
127
|
+
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
128
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
129
|
+
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
130
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
131
|
+
await config.deleteConfig(Config.OIDC)
|
|
136
132
|
})
|
|
137
133
|
})
|
|
138
134
|
|
|
139
135
|
describe("update", () => {
|
|
140
136
|
it("should update OIDC config to deactivated", async () => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
await config.deleteConfig(Config.OIDC)
|
|
155
|
-
})
|
|
137
|
+
const oidcConf = await saveOIDCConfig()
|
|
138
|
+
jest.clearAllMocks()
|
|
139
|
+
await saveOIDCConfig(
|
|
140
|
+
{ ...oidcConf.config.configs[0], activated: false },
|
|
141
|
+
oidcConf._id,
|
|
142
|
+
oidcConf._rev
|
|
143
|
+
)
|
|
144
|
+
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
145
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
146
|
+
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
147
|
+
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
148
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
|
|
149
|
+
await config.deleteConfig(Config.OIDC)
|
|
156
150
|
})
|
|
157
151
|
|
|
158
152
|
it("should update OIDC config to activated", async () => {
|
|
159
|
-
await
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
await config.deleteConfig(Config.OIDC)
|
|
173
|
-
})
|
|
153
|
+
const oidcConf = await saveOIDCConfig({ activated: false })
|
|
154
|
+
jest.clearAllMocks()
|
|
155
|
+
await saveOIDCConfig(
|
|
156
|
+
{ ...oidcConf.config.configs[0], activated: true },
|
|
157
|
+
oidcConf._id,
|
|
158
|
+
oidcConf._rev
|
|
159
|
+
)
|
|
160
|
+
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
161
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
162
|
+
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
163
|
+
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
164
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
165
|
+
await config.deleteConfig(Config.OIDC)
|
|
174
166
|
})
|
|
175
167
|
})
|
|
176
168
|
})
|
|
@@ -187,26 +179,22 @@ describe("configs", () => {
|
|
|
187
179
|
|
|
188
180
|
describe("create", () => {
|
|
189
181
|
it("should create SMTP config", async () => {
|
|
190
|
-
await
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
await config.deleteConfig(Config.SMTP)
|
|
196
|
-
})
|
|
182
|
+
await config.deleteConfig(Config.SMTP)
|
|
183
|
+
await saveSMTPConfig()
|
|
184
|
+
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
185
|
+
expect(events.email.SMTPCreated).toBeCalledTimes(1)
|
|
186
|
+
await config.deleteConfig(Config.SMTP)
|
|
197
187
|
})
|
|
198
188
|
})
|
|
199
189
|
|
|
200
190
|
describe("update", () => {
|
|
201
191
|
it("should update SMTP config", async () => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
await config.deleteConfig(Config.SMTP)
|
|
209
|
-
})
|
|
192
|
+
const smtpConf = await saveSMTPConfig()
|
|
193
|
+
jest.clearAllMocks()
|
|
194
|
+
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
195
|
+
expect(events.email.SMTPCreated).not.toBeCalled()
|
|
196
|
+
expect(events.email.SMTPUpdated).toBeCalledTimes(1)
|
|
197
|
+
await config.deleteConfig(Config.SMTP)
|
|
210
198
|
})
|
|
211
199
|
})
|
|
212
200
|
})
|
|
@@ -223,73 +211,65 @@ describe("configs", () => {
|
|
|
223
211
|
|
|
224
212
|
describe("create", () => {
|
|
225
213
|
it("should create settings config with default settings", async () => {
|
|
226
|
-
await
|
|
227
|
-
await config.deleteConfig(Config.SETTINGS)
|
|
214
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
228
215
|
|
|
229
|
-
|
|
216
|
+
await saveSettingsConfig()
|
|
230
217
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
})
|
|
218
|
+
expect(events.org.nameUpdated).not.toBeCalled()
|
|
219
|
+
expect(events.org.logoUpdated).not.toBeCalled()
|
|
220
|
+
expect(events.org.platformURLUpdated).not.toBeCalled()
|
|
235
221
|
})
|
|
236
222
|
|
|
237
223
|
it("should create settings config with non-default settings", async () => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
config.modeCloud()
|
|
253
|
-
})
|
|
224
|
+
config.selfHosted()
|
|
225
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
226
|
+
const conf = {
|
|
227
|
+
company: "acme",
|
|
228
|
+
logoUrl: "http://example.com",
|
|
229
|
+
platformUrl: "http://example.com",
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
await saveSettingsConfig(conf)
|
|
233
|
+
|
|
234
|
+
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
235
|
+
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
236
|
+
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
237
|
+
config.cloudHosted()
|
|
254
238
|
})
|
|
255
239
|
})
|
|
256
240
|
|
|
257
241
|
describe("update", () => {
|
|
258
242
|
it("should update settings config", async () => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
config.modeCloud()
|
|
277
|
-
})
|
|
243
|
+
config.selfHosted()
|
|
244
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
245
|
+
const settingsConfig = await saveSettingsConfig()
|
|
246
|
+
settingsConfig.config.company = "acme"
|
|
247
|
+
settingsConfig.config.logoUrl = "http://example.com"
|
|
248
|
+
settingsConfig.config.platformUrl = "http://example.com"
|
|
249
|
+
|
|
250
|
+
await saveSettingsConfig(
|
|
251
|
+
settingsConfig.config,
|
|
252
|
+
settingsConfig._id,
|
|
253
|
+
settingsConfig._rev
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
257
|
+
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
258
|
+
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
259
|
+
config.cloudHosted()
|
|
278
260
|
})
|
|
279
261
|
})
|
|
280
262
|
})
|
|
281
263
|
})
|
|
282
264
|
|
|
283
265
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
|
284
|
-
await
|
|
285
|
-
await config.saveSmtpConfig()
|
|
266
|
+
await config.saveSmtpConfig()
|
|
286
267
|
|
|
287
|
-
|
|
288
|
-
|
|
268
|
+
const res = await config.api.configs.getConfigChecklist()
|
|
269
|
+
const checklist = res.body
|
|
289
270
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
})
|
|
271
|
+
expect(checklist.apps.checked).toBeFalsy()
|
|
272
|
+
expect(checklist.smtp.checked).toBeTruthy()
|
|
273
|
+
expect(checklist.adminUser.checked).toBeTruthy()
|
|
294
274
|
})
|
|
295
275
|
})
|
|
@@ -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,
|
|
@@ -43,13 +44,13 @@ describe("/api/global/roles", () => {
|
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
beforeEach(async () => {
|
|
46
|
-
appId = db.generateAppID()
|
|
47
|
+
appId = db.generateAppID(config.tenantId)
|
|
47
48
|
appDb = db.getDB(appId)
|
|
48
49
|
const mockAppDB = context.getAppDB as Mock
|
|
49
50
|
mockAppDB.mockReturnValue(appDb)
|
|
50
51
|
|
|
51
52
|
await addAppMetadata()
|
|
52
|
-
appDb.put(role)
|
|
53
|
+
await appDb.put(role)
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
afterAll(async () => {
|
|
@@ -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
|
})
|
|
@@ -3,7 +3,9 @@ import { InviteUsersResponse, User } from "@budibase/types"
|
|
|
3
3
|
jest.mock("nodemailer")
|
|
4
4
|
import { TestConfiguration, mocks, structures } from "../../../../tests"
|
|
5
5
|
const sendMailMock = mocks.email.mock()
|
|
6
|
-
import {
|
|
6
|
+
import { events, tenancy, accounts as _accounts } from "@budibase/backend-core"
|
|
7
|
+
|
|
8
|
+
const accounts = jest.mocked(_accounts)
|
|
7
9
|
|
|
8
10
|
describe("/api/global/users", () => {
|
|
9
11
|
const config = new TestConfiguration()
|
|
@@ -20,26 +22,24 @@ describe("/api/global/users", () => {
|
|
|
20
22
|
jest.clearAllMocks()
|
|
21
23
|
})
|
|
22
24
|
|
|
23
|
-
describe("invite", () => {
|
|
25
|
+
describe("POST /api/global/users/invite", () => {
|
|
24
26
|
it("should be able to generate an invitation", async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(events.user.invited).toBeCalledTimes(1)
|
|
36
|
-
})
|
|
27
|
+
const email = structures.users.newEmail()
|
|
28
|
+
const { code, res } = await config.api.users.sendUserInvite(
|
|
29
|
+
sendMailMock,
|
|
30
|
+
email
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
expect(res.body).toEqual({ message: "Invitation has been sent." })
|
|
34
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
35
|
+
expect(code).toBeDefined()
|
|
36
|
+
expect(events.user.invited).toBeCalledTimes(1)
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
40
40
|
const { code, res } = await config.api.users.sendUserInvite(
|
|
41
41
|
sendMailMock,
|
|
42
|
-
config.
|
|
42
|
+
config.user!.email,
|
|
43
43
|
400
|
|
44
44
|
)
|
|
45
45
|
|
|
@@ -50,26 +50,24 @@ describe("/api/global/users", () => {
|
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it("should be able to create new user from invite", async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(events.user.inviteAccepted).toBeCalledWith(user)
|
|
68
|
-
})
|
|
53
|
+
const email = structures.users.newEmail()
|
|
54
|
+
const { code } = await config.api.users.sendUserInvite(
|
|
55
|
+
sendMailMock,
|
|
56
|
+
email
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const res = await config.api.users.acceptInvite(code)
|
|
60
|
+
|
|
61
|
+
expect(res.body._id).toBeDefined()
|
|
62
|
+
const user = await config.getUser(email)
|
|
63
|
+
expect(user).toBeDefined()
|
|
64
|
+
expect(user._id).toEqual(res.body._id)
|
|
65
|
+
expect(events.user.inviteAccepted).toBeCalledTimes(1)
|
|
66
|
+
expect(events.user.inviteAccepted).toBeCalledWith(user)
|
|
69
67
|
})
|
|
70
68
|
})
|
|
71
69
|
|
|
72
|
-
describe("
|
|
70
|
+
describe("POST /api/global/users/multi/invite", () => {
|
|
73
71
|
it("should be able to generate an invitation", async () => {
|
|
74
72
|
const newUserInvite = () => ({
|
|
75
73
|
email: structures.users.newEmail(),
|
|
@@ -87,7 +85,7 @@ describe("/api/global/users", () => {
|
|
|
87
85
|
})
|
|
88
86
|
|
|
89
87
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
90
|
-
const request = [{ email: config.
|
|
88
|
+
const request = [{ email: config.user!.email, userInfo: {} }]
|
|
91
89
|
|
|
92
90
|
const res = await config.api.users.sendMultiUserInvite(request)
|
|
93
91
|
|
|
@@ -100,7 +98,7 @@ describe("/api/global/users", () => {
|
|
|
100
98
|
})
|
|
101
99
|
})
|
|
102
100
|
|
|
103
|
-
describe("bulk
|
|
101
|
+
describe("POST /api/global/users/bulk", () => {
|
|
104
102
|
it("should ignore users existing in the same tenant", async () => {
|
|
105
103
|
const user = await config.createUser()
|
|
106
104
|
jest.clearAllMocks()
|
|
@@ -163,7 +161,7 @@ describe("/api/global/users", () => {
|
|
|
163
161
|
})
|
|
164
162
|
})
|
|
165
163
|
|
|
166
|
-
describe("
|
|
164
|
+
describe("POST /api/global/users", () => {
|
|
167
165
|
it("should be able to create a basic user", async () => {
|
|
168
166
|
const user = structures.users.user()
|
|
169
167
|
|
|
@@ -242,7 +240,7 @@ describe("/api/global/users", () => {
|
|
|
242
240
|
it("should not be able to create user with the same email as an account", async () => {
|
|
243
241
|
const user = structures.users.user()
|
|
244
242
|
const account = structures.accounts.cloudAccount()
|
|
245
|
-
|
|
243
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
246
244
|
|
|
247
245
|
const response = await config.api.users.saveUser(user, 400)
|
|
248
246
|
|
|
@@ -283,7 +281,7 @@ describe("/api/global/users", () => {
|
|
|
283
281
|
})
|
|
284
282
|
})
|
|
285
283
|
|
|
286
|
-
describe("update", () => {
|
|
284
|
+
describe("POST /api/global/users (update)", () => {
|
|
287
285
|
it("should be able to update a basic user", async () => {
|
|
288
286
|
const user = await config.createUser()
|
|
289
287
|
jest.clearAllMocks()
|
|
@@ -298,7 +296,7 @@ describe("/api/global/users", () => {
|
|
|
298
296
|
})
|
|
299
297
|
|
|
300
298
|
it("should not allow a user to update their own admin/builder status", async () => {
|
|
301
|
-
const user = (await config.api.users.getUser(config.
|
|
299
|
+
const user = (await config.api.users.getUser(config.user?._id!))
|
|
302
300
|
.body as User
|
|
303
301
|
await config.api.users.saveUser({
|
|
304
302
|
...user,
|
|
@@ -468,9 +466,9 @@ describe("/api/global/users", () => {
|
|
|
468
466
|
})
|
|
469
467
|
})
|
|
470
468
|
|
|
471
|
-
describe("bulk (delete)", () => {
|
|
469
|
+
describe("POST /api/global/users/bulk (delete)", () => {
|
|
472
470
|
it("should not be able to bulk delete current user", async () => {
|
|
473
|
-
const user = await config.
|
|
471
|
+
const user = await config.user!
|
|
474
472
|
|
|
475
473
|
const response = await config.api.users.bulkDeleteUsers([user._id!], 400)
|
|
476
474
|
|
|
@@ -482,7 +480,7 @@ describe("/api/global/users", () => {
|
|
|
482
480
|
const user = await config.createUser()
|
|
483
481
|
const account = structures.accounts.cloudAccount()
|
|
484
482
|
account.budibaseUserId = user._id!
|
|
485
|
-
|
|
483
|
+
accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
|
|
486
484
|
|
|
487
485
|
const response = await config.api.users.bulkDeleteUsers([user._id!])
|
|
488
486
|
|
|
@@ -497,7 +495,7 @@ describe("/api/global/users", () => {
|
|
|
497
495
|
|
|
498
496
|
it("should be able to bulk delete users", async () => {
|
|
499
497
|
const account = structures.accounts.cloudAccount()
|
|
500
|
-
|
|
498
|
+
accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
|
|
501
499
|
|
|
502
500
|
const builder = structures.users.builderUser()
|
|
503
501
|
const admin = structures.users.adminUser()
|
|
@@ -521,7 +519,7 @@ describe("/api/global/users", () => {
|
|
|
521
519
|
})
|
|
522
520
|
})
|
|
523
521
|
|
|
524
|
-
describe("
|
|
522
|
+
describe("DELETE /api/global/users/:userId", () => {
|
|
525
523
|
it("should be able to destroy a basic user", async () => {
|
|
526
524
|
const user = await config.createUser()
|
|
527
525
|
jest.clearAllMocks()
|
|
@@ -558,7 +556,7 @@ describe("/api/global/users", () => {
|
|
|
558
556
|
it("should not be able to destroy account owner", async () => {
|
|
559
557
|
const user = await config.createUser()
|
|
560
558
|
const account = structures.accounts.cloudAccount()
|
|
561
|
-
|
|
559
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
562
560
|
|
|
563
561
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
564
562
|
|
|
@@ -566,10 +564,10 @@ describe("/api/global/users", () => {
|
|
|
566
564
|
})
|
|
567
565
|
|
|
568
566
|
it("should not be able to destroy account owner as account owner", async () => {
|
|
569
|
-
const user = await config.
|
|
567
|
+
const user = await config.user!
|
|
570
568
|
const account = structures.accounts.cloudAccount()
|
|
571
569
|
account.email = user.email
|
|
572
|
-
|
|
570
|
+
accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
|
|
573
571
|
|
|
574
572
|
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
575
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
|
|