@budibase/worker 1.0.200-alpha.3 → 1.0.200
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/Dockerfile +0 -3
- package/nodemon.json +1 -1
- package/package.json +46 -56
- package/scripts/dev/manage.js +0 -2
- package/scripts/jestSetup.js +0 -9
- package/scripts/load/users.js +4 -4
- package/src/api/controllers/global/auth.ts +14 -21
- package/src/api/controllers/global/configs.js +2 -126
- package/src/api/controllers/global/roles.js +3 -3
- package/src/api/controllers/global/self.js +3 -12
- package/src/api/controllers/global/users.ts +88 -48
- package/src/api/routes/global/self.js +2 -2
- package/src/api/routes/global/users.js +3 -3
- package/src/api/routes/tests/auth.spec.js +16 -38
- package/src/api/routes/tests/configs.spec.js +7 -223
- package/src/api/routes/tests/email.spec.js +7 -8
- package/src/api/routes/tests/realEmail.spec.js +5 -5
- package/src/api/routes/tests/users.spec.js +13 -299
- package/src/{tests → api/routes/tests/utilities}/TestConfiguration.js +111 -68
- package/src/api/routes/tests/utilities/controllers.js +7 -0
- package/src/api/routes/tests/utilities/index.js +41 -0
- package/src/api/routes/tests/utilities/structures.js +2 -0
- package/src/api/utilities/index.js +33 -0
- package/src/api/{routes/validation/users.ts → utilities/validation.js} +4 -4
- package/src/index.ts +0 -2
- package/tsconfig.json +15 -21
- package/src/api/routes/tests/self.spec.js +0 -58
- package/src/api/routes/validation/index.ts +0 -1
- package/src/sdk/index.ts +0 -1
- package/src/sdk/users/events.ts +0 -161
- package/src/sdk/users/index.ts +0 -1
- package/src/sdk/users/users.ts +0 -201
- package/src/tests/controllers.js +0 -7
- package/src/tests/index.js +0 -12
- package/src/tests/mocks/email.js +0 -10
- package/src/tests/mocks/index.js +0 -5
- package/src/tests/structures/configs.js +0 -76
- package/src/tests/structures/index.js +0 -12
- package/src/tests/structures/users.ts +0 -28
- package/tsconfig.build.json +0 -25
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
const
|
|
3
|
-
const sendMailMock =
|
|
4
|
-
const { events } = require("@budibase/backend-core")
|
|
2
|
+
const setup = require("./utilities")
|
|
3
|
+
const sendMailMock = setup.emailMock()
|
|
5
4
|
|
|
6
5
|
describe("/api/global/users", () => {
|
|
6
|
+
let request = setup.getRequest()
|
|
7
|
+
let config = setup.getConfig()
|
|
8
|
+
let code
|
|
7
9
|
|
|
8
10
|
beforeAll(async () => {
|
|
9
|
-
await config.
|
|
11
|
+
await config.init()
|
|
10
12
|
})
|
|
11
13
|
|
|
12
|
-
afterAll(
|
|
13
|
-
await config.afterAll()
|
|
14
|
-
})
|
|
14
|
+
afterAll(setup.afterAll)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
it("should be able to generate an invitation", async () => {
|
|
17
|
+
// initially configure settings
|
|
17
18
|
await config.saveSmtpConfig()
|
|
18
19
|
await config.saveSettingsConfig()
|
|
19
20
|
const res = await request
|
|
@@ -24,26 +25,16 @@ describe("/api/global/users", () => {
|
|
|
24
25
|
.set(config.defaultHeaders())
|
|
25
26
|
.expect("Content-Type", /json/)
|
|
26
27
|
.expect(200)
|
|
27
|
-
|
|
28
|
-
const emailCall = sendMailMock.mock.calls[0][0]
|
|
29
|
-
// after this URL there should be a code
|
|
30
|
-
const parts = emailCall.html.split("http://localhost:10000/builder/invite?code=")
|
|
31
|
-
const code = parts[1].split("\"")[0].split("&")[0]
|
|
32
|
-
return { code, res }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
it("should be able to generate an invitation", async () => {
|
|
36
|
-
const { code, res } = await sendUserInvite()
|
|
37
|
-
|
|
38
28
|
expect(res.body).toEqual({ message: "Invitation has been sent." })
|
|
39
29
|
expect(sendMailMock).toHaveBeenCalled()
|
|
30
|
+
const emailCall = sendMailMock.mock.calls[0][0]
|
|
31
|
+
// after this URL there should be a code
|
|
32
|
+
const parts = emailCall.html.split("http://localhost:10000/builder/invite?code=")
|
|
33
|
+
code = parts[1].split("\"")[0].split("&")[0]
|
|
40
34
|
expect(code).toBeDefined()
|
|
41
|
-
expect(events.user.invited).toBeCalledTimes(1)
|
|
42
35
|
})
|
|
43
36
|
|
|
44
37
|
it("should be able to create new user from invite", async () => {
|
|
45
|
-
const { code } = await sendUserInvite()
|
|
46
|
-
|
|
47
38
|
const res = await request
|
|
48
39
|
.post(`/api/global/users/invite/accept`)
|
|
49
40
|
.send({
|
|
@@ -56,282 +47,5 @@ describe("/api/global/users", () => {
|
|
|
56
47
|
const user = await config.getUser("invite@test.com")
|
|
57
48
|
expect(user).toBeDefined()
|
|
58
49
|
expect(user._id).toEqual(res.body._id)
|
|
59
|
-
expect(events.user.inviteAccepted).toBeCalledTimes(1)
|
|
60
|
-
expect(events.user.inviteAccepted).toBeCalledWith(user)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const createUser = async (user) => {
|
|
64
|
-
const existing = await config.getUser(user.email)
|
|
65
|
-
if (existing) {
|
|
66
|
-
await deleteUser(existing._id)
|
|
67
|
-
}
|
|
68
|
-
return saveUser(user)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const updateUser = async (user) => {
|
|
72
|
-
const existing = await config.getUser(user.email)
|
|
73
|
-
user._id = existing._id
|
|
74
|
-
return saveUser(user)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const saveUser = async (user) => {
|
|
78
|
-
const res = await request
|
|
79
|
-
.post(`/api/global/users`)
|
|
80
|
-
.send(user)
|
|
81
|
-
.set(config.defaultHeaders())
|
|
82
|
-
.expect("Content-Type", /json/)
|
|
83
|
-
.expect(200)
|
|
84
|
-
return res.body
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const deleteUser = async (email) => {
|
|
88
|
-
const user = await config.getUser(email)
|
|
89
|
-
if (user) {
|
|
90
|
-
await request
|
|
91
|
-
.delete(`/api/global/users/${user._id}`)
|
|
92
|
-
.set(config.defaultHeaders())
|
|
93
|
-
.expect("Content-Type", /json/)
|
|
94
|
-
.expect(200)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
describe("create", () => {
|
|
99
|
-
it("should be able to create a basic user", async () => {
|
|
100
|
-
jest.clearAllMocks()
|
|
101
|
-
const user = structures.users.user({ email: "basic@test.com" })
|
|
102
|
-
await createUser(user)
|
|
103
|
-
|
|
104
|
-
expect(events.user.created).toBeCalledTimes(1)
|
|
105
|
-
expect(events.user.updated).not.toBeCalled()
|
|
106
|
-
expect(events.user.permissionBuilderAssigned).not.toBeCalled()
|
|
107
|
-
expect(events.user.permissionAdminAssigned).not.toBeCalled()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it("should be able to create an admin user", async () => {
|
|
111
|
-
jest.clearAllMocks()
|
|
112
|
-
const user = structures.users.adminUser({ email: "admin@test.com" })
|
|
113
|
-
await createUser(user)
|
|
114
|
-
|
|
115
|
-
expect(events.user.created).toBeCalledTimes(1)
|
|
116
|
-
expect(events.user.updated).not.toBeCalled()
|
|
117
|
-
expect(events.user.permissionBuilderAssigned).not.toBeCalled()
|
|
118
|
-
expect(events.user.permissionAdminAssigned).toBeCalledTimes(1)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it("should be able to create a builder user", async () => {
|
|
122
|
-
jest.clearAllMocks()
|
|
123
|
-
const user = structures.users.builderUser({ email: "builder@test.com" })
|
|
124
|
-
await createUser(user)
|
|
125
|
-
|
|
126
|
-
expect(events.user.created).toBeCalledTimes(1)
|
|
127
|
-
expect(events.user.updated).not.toBeCalled()
|
|
128
|
-
expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1)
|
|
129
|
-
expect(events.user.permissionAdminAssigned).not.toBeCalled()
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it("should be able to assign app roles", async () => {
|
|
133
|
-
jest.clearAllMocks()
|
|
134
|
-
const user = structures.users.user({ email: "assign-roles@test.com" })
|
|
135
|
-
user.roles = {
|
|
136
|
-
"app_123": "role1",
|
|
137
|
-
"app_456": "role2",
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
await createUser(user)
|
|
141
|
-
const savedUser = await config.getUser(user.email)
|
|
142
|
-
|
|
143
|
-
expect(events.user.created).toBeCalledTimes(1)
|
|
144
|
-
expect(events.user.updated).not.toBeCalled()
|
|
145
|
-
expect(events.role.assigned).toBeCalledTimes(2)
|
|
146
|
-
expect(events.role.assigned).toBeCalledWith(savedUser, "role1")
|
|
147
|
-
expect(events.role.assigned).toBeCalledWith(savedUser, "role2")
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
describe("update", () => {
|
|
152
|
-
it("should be able to update a basic user", async () => {
|
|
153
|
-
let user = structures.users.user({ email: "basic-update@test.com" })
|
|
154
|
-
await createUser(user)
|
|
155
|
-
jest.clearAllMocks()
|
|
156
|
-
|
|
157
|
-
await updateUser(user)
|
|
158
|
-
|
|
159
|
-
expect(events.user.created).not.toBeCalled()
|
|
160
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
161
|
-
expect(events.user.permissionBuilderAssigned).not.toBeCalled()
|
|
162
|
-
expect(events.user.permissionAdminAssigned).not.toBeCalled()
|
|
163
|
-
expect(events.user.passwordForceReset).not.toBeCalled()
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
it("should be able to force reset password", async () => {
|
|
167
|
-
let user = structures.users.user({ email: "basic-password-update@test.com" })
|
|
168
|
-
await createUser(user)
|
|
169
|
-
jest.clearAllMocks()
|
|
170
|
-
|
|
171
|
-
user.forceResetPassword = true
|
|
172
|
-
user.password = "tempPassword"
|
|
173
|
-
await updateUser(user)
|
|
174
|
-
|
|
175
|
-
expect(events.user.created).not.toBeCalled()
|
|
176
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
177
|
-
expect(events.user.permissionBuilderAssigned).not.toBeCalled()
|
|
178
|
-
expect(events.user.permissionAdminAssigned).not.toBeCalled()
|
|
179
|
-
expect(events.user.passwordForceReset).toBeCalledTimes(1)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it("should be able to update a basic user to an admin user", async () => {
|
|
183
|
-
let user = structures.users.user({ email: "basic-update-admin@test.com" })
|
|
184
|
-
await createUser(user)
|
|
185
|
-
jest.clearAllMocks()
|
|
186
|
-
|
|
187
|
-
await updateUser(structures.users.adminUser(user))
|
|
188
|
-
|
|
189
|
-
expect(events.user.created).not.toBeCalled()
|
|
190
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
191
|
-
expect(events.user.permissionBuilderAssigned).not.toBeCalled()
|
|
192
|
-
expect(events.user.permissionAdminAssigned).toBeCalledTimes(1)
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
it("should be able to update a basic user to a builder user", async () => {
|
|
196
|
-
let user = structures.users.user({ email: "basic-update-builder@test.com" })
|
|
197
|
-
await createUser(user)
|
|
198
|
-
jest.clearAllMocks()
|
|
199
|
-
|
|
200
|
-
await updateUser(structures.users.builderUser(user))
|
|
201
|
-
|
|
202
|
-
expect(events.user.created).not.toBeCalled()
|
|
203
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
204
|
-
expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1)
|
|
205
|
-
expect(events.user.permissionAdminAssigned).not.toBeCalled()
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it("should be able to update an admin user to a basic user", async () => {
|
|
209
|
-
let user = structures.users.adminUser({ email: "admin-update-basic@test.com" })
|
|
210
|
-
await createUser(user)
|
|
211
|
-
jest.clearAllMocks()
|
|
212
|
-
|
|
213
|
-
user.admin.global = false
|
|
214
|
-
await updateUser(user)
|
|
215
|
-
|
|
216
|
-
expect(events.user.created).not.toBeCalled()
|
|
217
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
218
|
-
expect(events.user.permissionAdminRemoved).toBeCalledTimes(1)
|
|
219
|
-
expect(events.user.permissionBuilderRemoved).not.toBeCalled()
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
it("should be able to update an builder user to a basic user", async () => {
|
|
223
|
-
let user = structures.users.builderUser({ email: "builder-update-basic@test.com" })
|
|
224
|
-
await createUser(user)
|
|
225
|
-
jest.clearAllMocks()
|
|
226
|
-
|
|
227
|
-
user.builder.global = false
|
|
228
|
-
await updateUser(user)
|
|
229
|
-
|
|
230
|
-
expect(events.user.created).not.toBeCalled()
|
|
231
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
232
|
-
expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1)
|
|
233
|
-
expect(events.user.permissionAdminRemoved).not.toBeCalled()
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it("should be able to assign app roles", async () => {
|
|
237
|
-
const user = structures.users.user({ email: "assign-roles-update@test.com" })
|
|
238
|
-
await createUser(user)
|
|
239
|
-
jest.clearAllMocks()
|
|
240
|
-
|
|
241
|
-
user.roles = {
|
|
242
|
-
"app_123": "role1",
|
|
243
|
-
"app_456": "role2",
|
|
244
|
-
}
|
|
245
|
-
await updateUser(user)
|
|
246
|
-
const savedUser = await config.getUser(user.email)
|
|
247
|
-
|
|
248
|
-
expect(events.user.created).not.toBeCalled()
|
|
249
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
250
|
-
expect(events.role.assigned).toBeCalledTimes(2)
|
|
251
|
-
expect(events.role.assigned).toBeCalledWith(savedUser, "role1")
|
|
252
|
-
expect(events.role.assigned).toBeCalledWith(savedUser, "role2")
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
it("should be able to unassign app roles", async () => {
|
|
256
|
-
const user = structures.users.user({ email: "unassign-roles@test.com" })
|
|
257
|
-
user.roles = {
|
|
258
|
-
"app_123": "role1",
|
|
259
|
-
"app_456": "role2",
|
|
260
|
-
}
|
|
261
|
-
await createUser(user)
|
|
262
|
-
jest.clearAllMocks()
|
|
263
|
-
|
|
264
|
-
user.roles = {}
|
|
265
|
-
await updateUser(user)
|
|
266
|
-
const savedUser = await config.getUser(user.email)
|
|
267
|
-
|
|
268
|
-
expect(events.user.created).not.toBeCalled()
|
|
269
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
270
|
-
expect(events.role.unassigned).toBeCalledTimes(2)
|
|
271
|
-
expect(events.role.unassigned).toBeCalledWith(savedUser, "role1")
|
|
272
|
-
expect(events.role.unassigned).toBeCalledWith(savedUser, "role2")
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
it("should be able to update existing app roles", async () => {
|
|
276
|
-
const user = structures.users.user({ email: "update-roles@test.com" })
|
|
277
|
-
user.roles = {
|
|
278
|
-
"app_123": "role1",
|
|
279
|
-
"app_456": "role2",
|
|
280
|
-
}
|
|
281
|
-
await createUser(user)
|
|
282
|
-
jest.clearAllMocks()
|
|
283
|
-
|
|
284
|
-
user.roles = {
|
|
285
|
-
"app_123": "role1",
|
|
286
|
-
"app_456": "role2-edit",
|
|
287
|
-
}
|
|
288
|
-
await updateUser(user)
|
|
289
|
-
const savedUser = await config.getUser(user.email)
|
|
290
|
-
|
|
291
|
-
expect(events.user.created).not.toBeCalled()
|
|
292
|
-
expect(events.user.updated).toBeCalledTimes(1)
|
|
293
|
-
expect(events.role.unassigned).toBeCalledTimes(1)
|
|
294
|
-
expect(events.role.unassigned).toBeCalledWith(savedUser, "role2")
|
|
295
|
-
expect(events.role.assigned).toBeCalledTimes(1)
|
|
296
|
-
expect(events.role.assigned).toBeCalledWith(savedUser, "role2-edit")
|
|
297
|
-
})
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
describe("destroy", () => {
|
|
301
|
-
it("should be able to destroy a basic user", async () => {
|
|
302
|
-
let user = structures.users.user({ email: "destroy@test.com" })
|
|
303
|
-
await createUser(user)
|
|
304
|
-
jest.clearAllMocks()
|
|
305
|
-
|
|
306
|
-
await deleteUser(user.email)
|
|
307
|
-
|
|
308
|
-
expect(events.user.deleted).toBeCalledTimes(1)
|
|
309
|
-
expect(events.user.permissionBuilderRemoved).not.toBeCalled()
|
|
310
|
-
expect(events.user.permissionAdminRemoved).not.toBeCalled()
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
it("should be able to destroy an admin user", async () => {
|
|
314
|
-
let user = structures.users.adminUser({ email: "destroy-admin@test.com" })
|
|
315
|
-
await createUser(user)
|
|
316
|
-
jest.clearAllMocks()
|
|
317
|
-
|
|
318
|
-
await deleteUser(user.email)
|
|
319
|
-
|
|
320
|
-
expect(events.user.deleted).toBeCalledTimes(1)
|
|
321
|
-
expect(events.user.permissionBuilderRemoved).not.toBeCalled()
|
|
322
|
-
expect(events.user.permissionAdminRemoved).toBeCalledTimes(1)
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
it("should be able to destroy a builder user", async () => {
|
|
326
|
-
let user = structures.users.builderUser({ email: "destroy-admin@test.com" })
|
|
327
|
-
await createUser(user)
|
|
328
|
-
jest.clearAllMocks()
|
|
329
|
-
|
|
330
|
-
await deleteUser(user.email)
|
|
331
|
-
|
|
332
|
-
expect(events.user.deleted).toBeCalledTimes(1)
|
|
333
|
-
expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1)
|
|
334
|
-
expect(events.user.permissionAdminRemoved).not.toBeCalled()
|
|
335
|
-
})
|
|
336
50
|
})
|
|
337
51
|
})
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
require("
|
|
2
|
-
require("
|
|
3
|
-
const env = require("../environment")
|
|
1
|
+
require("../../../../db").init()
|
|
2
|
+
const env = require("../../../../environment")
|
|
4
3
|
const controllers = require("./controllers")
|
|
5
4
|
const supertest = require("supertest")
|
|
6
5
|
const { jwt } = require("@budibase/backend-core/auth")
|
|
7
6
|
const { Cookies, Headers } = require("@budibase/backend-core/constants")
|
|
8
|
-
const { Configs } = require("
|
|
9
|
-
const {
|
|
7
|
+
const { Configs, LOGO_URL } = require("../../../../constants")
|
|
8
|
+
const { getGlobalUserByEmail } = require("@budibase/backend-core/utils")
|
|
10
9
|
const { createASession } = require("@budibase/backend-core/sessions")
|
|
10
|
+
const { newid } = require("@budibase/backend-core/src/hashing")
|
|
11
11
|
const { TENANT_ID, CSRF_TOKEN } = require("./structures")
|
|
12
|
-
const structures = require("./structures")
|
|
13
12
|
const { doInTenant } = require("@budibase/backend-core/tenancy")
|
|
14
13
|
|
|
15
14
|
class TestConfiguration {
|
|
16
15
|
constructor(openServer = true) {
|
|
17
16
|
if (openServer) {
|
|
18
|
-
env.PORT =
|
|
19
|
-
this.server = require("
|
|
17
|
+
env.PORT = 4012
|
|
18
|
+
this.server = require("../../../../index")
|
|
20
19
|
// we need the request for logging in, involves cookies, hard to fake
|
|
21
20
|
this.request = supertest(this.server)
|
|
22
21
|
}
|
|
@@ -26,8 +25,6 @@ class TestConfiguration {
|
|
|
26
25
|
return this.request
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// UTILS
|
|
30
|
-
|
|
31
28
|
async _req(config, params, controlFunc) {
|
|
32
29
|
const request = {}
|
|
33
30
|
// fake cookies, we don't need them
|
|
@@ -51,37 +48,25 @@ class TestConfiguration {
|
|
|
51
48
|
return request.body
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
async login() {
|
|
69
|
-
// create a test user
|
|
70
|
-
await this._req(
|
|
71
|
-
{
|
|
72
|
-
email: "test@test.com",
|
|
73
|
-
password: "test",
|
|
74
|
-
_id: "us_uuid1",
|
|
75
|
-
builder: {
|
|
76
|
-
global: true,
|
|
77
|
-
},
|
|
78
|
-
admin: {
|
|
79
|
-
global: true,
|
|
51
|
+
async init(createUser = true) {
|
|
52
|
+
if (createUser) {
|
|
53
|
+
// create a test user
|
|
54
|
+
await this._req(
|
|
55
|
+
{
|
|
56
|
+
email: "test@test.com",
|
|
57
|
+
password: "test",
|
|
58
|
+
_id: "us_uuid1",
|
|
59
|
+
builder: {
|
|
60
|
+
global: true,
|
|
61
|
+
},
|
|
62
|
+
admin: {
|
|
63
|
+
global: true,
|
|
64
|
+
},
|
|
80
65
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
null,
|
|
67
|
+
controllers.users.save
|
|
68
|
+
)
|
|
69
|
+
}
|
|
85
70
|
await createASession("us_uuid1", {
|
|
86
71
|
sessionId: "sessionid",
|
|
87
72
|
tenantId: TENANT_ID,
|
|
@@ -89,6 +74,12 @@ class TestConfiguration {
|
|
|
89
74
|
})
|
|
90
75
|
}
|
|
91
76
|
|
|
77
|
+
async end() {
|
|
78
|
+
if (this.server) {
|
|
79
|
+
await this.server.close()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
92
83
|
cookieHeader(cookies) {
|
|
93
84
|
return {
|
|
94
85
|
Cookie: [cookies],
|
|
@@ -112,32 +103,25 @@ class TestConfiguration {
|
|
|
112
103
|
|
|
113
104
|
async getUser(email) {
|
|
114
105
|
return doInTenant(TENANT_ID, () => {
|
|
115
|
-
return
|
|
106
|
+
return getGlobalUserByEmail(email)
|
|
116
107
|
})
|
|
117
108
|
}
|
|
118
109
|
|
|
119
|
-
async createUser(email, password) {
|
|
120
|
-
const user = await this.getUser(
|
|
110
|
+
async createUser(email = "test@test.com", password = "test") {
|
|
111
|
+
const user = await this.getUser(email)
|
|
121
112
|
if (user) {
|
|
122
113
|
return user
|
|
123
114
|
}
|
|
124
115
|
await this._req(
|
|
125
|
-
|
|
116
|
+
{
|
|
117
|
+
email,
|
|
118
|
+
password,
|
|
119
|
+
},
|
|
126
120
|
null,
|
|
127
121
|
controllers.users.save
|
|
128
122
|
)
|
|
129
123
|
}
|
|
130
124
|
|
|
131
|
-
async saveAdminUser() {
|
|
132
|
-
await this._req(
|
|
133
|
-
structures.users.user({ tenantId: TENANT_ID }),
|
|
134
|
-
null,
|
|
135
|
-
controllers.users.adminUser
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// CONFIGS
|
|
140
|
-
|
|
141
125
|
async deleteConfig(type) {
|
|
142
126
|
try {
|
|
143
127
|
const cfg = await this._req(
|
|
@@ -162,26 +146,37 @@ class TestConfiguration {
|
|
|
162
146
|
}
|
|
163
147
|
}
|
|
164
148
|
|
|
165
|
-
// CONFIGS - SETTINGS
|
|
166
|
-
|
|
167
149
|
async saveSettingsConfig() {
|
|
168
150
|
await this.deleteConfig(Configs.SETTINGS)
|
|
169
151
|
await this._req(
|
|
170
|
-
|
|
152
|
+
{
|
|
153
|
+
type: Configs.SETTINGS,
|
|
154
|
+
config: {
|
|
155
|
+
platformUrl: "http://localhost:10000",
|
|
156
|
+
logoUrl: LOGO_URL,
|
|
157
|
+
company: "Budibase",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
171
160
|
null,
|
|
172
161
|
controllers.config.save
|
|
173
162
|
)
|
|
174
163
|
}
|
|
175
164
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
async saveGoogleConfig() {
|
|
165
|
+
async saveOAuthConfig() {
|
|
179
166
|
await this.deleteConfig(Configs.GOOGLE)
|
|
180
|
-
await this._req(
|
|
167
|
+
await this._req(
|
|
168
|
+
{
|
|
169
|
+
type: Configs.GOOGLE,
|
|
170
|
+
config: {
|
|
171
|
+
clientID: "clientId",
|
|
172
|
+
clientSecret: "clientSecret",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
null,
|
|
176
|
+
controllers.config.save
|
|
177
|
+
)
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
// CONFIGS - OIDC
|
|
184
|
-
|
|
185
180
|
getOIDConfigCookie(configId) {
|
|
186
181
|
const token = jwt.sign(configId, env.JWT_SECRET)
|
|
187
182
|
return this.cookieHeader([[`${Cookies.OIDC_CONFIG}=${token}`]])
|
|
@@ -189,27 +184,75 @@ class TestConfiguration {
|
|
|
189
184
|
|
|
190
185
|
async saveOIDCConfig() {
|
|
191
186
|
await this.deleteConfig(Configs.OIDC)
|
|
192
|
-
const config =
|
|
187
|
+
const config = {
|
|
188
|
+
type: Configs.OIDC,
|
|
189
|
+
config: {
|
|
190
|
+
configs: [
|
|
191
|
+
{
|
|
192
|
+
configUrl: "http://someconfigurl",
|
|
193
|
+
clientID: "clientId",
|
|
194
|
+
clientSecret: "clientSecret",
|
|
195
|
+
logo: "Microsoft",
|
|
196
|
+
name: "Active Directory",
|
|
197
|
+
uuid: newid(),
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
}
|
|
193
202
|
|
|
194
203
|
await this._req(config, null, controllers.config.save)
|
|
195
204
|
return config
|
|
196
205
|
}
|
|
197
206
|
|
|
198
|
-
// CONFIGS - SMTP
|
|
199
|
-
|
|
200
207
|
async saveSmtpConfig() {
|
|
201
208
|
await this.deleteConfig(Configs.SMTP)
|
|
202
|
-
await this._req(
|
|
209
|
+
await this._req(
|
|
210
|
+
{
|
|
211
|
+
type: Configs.SMTP,
|
|
212
|
+
config: {
|
|
213
|
+
port: 12345,
|
|
214
|
+
host: "smtptesthost.com",
|
|
215
|
+
from: "testfrom@test.com",
|
|
216
|
+
subject: "Hello!",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
null,
|
|
220
|
+
controllers.config.save
|
|
221
|
+
)
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
async saveEtherealSmtpConfig() {
|
|
206
225
|
await this.deleteConfig(Configs.SMTP)
|
|
207
226
|
await this._req(
|
|
208
|
-
|
|
227
|
+
{
|
|
228
|
+
type: Configs.SMTP,
|
|
229
|
+
config: {
|
|
230
|
+
port: 587,
|
|
231
|
+
host: "smtp.ethereal.email",
|
|
232
|
+
secure: false,
|
|
233
|
+
auth: {
|
|
234
|
+
user: "don.bahringer@ethereal.email",
|
|
235
|
+
pass: "yCKSH8rWyUPbnhGYk9",
|
|
236
|
+
},
|
|
237
|
+
connectionTimeout: 1000, // must be less than the jest default of 5000
|
|
238
|
+
},
|
|
239
|
+
},
|
|
209
240
|
null,
|
|
210
241
|
controllers.config.save
|
|
211
242
|
)
|
|
212
243
|
}
|
|
244
|
+
|
|
245
|
+
async saveAdminUser() {
|
|
246
|
+
await this._req(
|
|
247
|
+
{
|
|
248
|
+
email: "testuser@test.com",
|
|
249
|
+
password: "test@test.com",
|
|
250
|
+
tenantId: TENANT_ID,
|
|
251
|
+
},
|
|
252
|
+
null,
|
|
253
|
+
controllers.users.adminUser
|
|
254
|
+
)
|
|
255
|
+
}
|
|
213
256
|
}
|
|
214
257
|
|
|
215
258
|
module.exports = TestConfiguration
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
email: require("../../../controllers/global/email"),
|
|
3
|
+
workspaces: require("../../../controllers/global/workspaces"),
|
|
4
|
+
config: require("../../../controllers/global/configs"),
|
|
5
|
+
templates: require("../../../controllers/global/templates"),
|
|
6
|
+
users: require("../../../controllers/global/users"),
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const TestConfig = require("./TestConfiguration")
|
|
2
|
+
|
|
3
|
+
let request, config
|
|
4
|
+
|
|
5
|
+
exports.beforeAll = () => {
|
|
6
|
+
config = new TestConfig()
|
|
7
|
+
request = config.getRequest()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.afterAll = async () => {
|
|
11
|
+
if (config) {
|
|
12
|
+
await config.end()
|
|
13
|
+
}
|
|
14
|
+
request = null
|
|
15
|
+
config = null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.getRequest = () => {
|
|
19
|
+
if (!request) {
|
|
20
|
+
exports.beforeAll()
|
|
21
|
+
}
|
|
22
|
+
return request
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.getConfig = () => {
|
|
26
|
+
if (!config) {
|
|
27
|
+
exports.beforeAll()
|
|
28
|
+
}
|
|
29
|
+
return config
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.emailMock = () => {
|
|
33
|
+
// mock the email system
|
|
34
|
+
const sendMailMock = jest.fn()
|
|
35
|
+
const nodemailer = require("nodemailer")
|
|
36
|
+
nodemailer.createTransport.mockReturnValue({
|
|
37
|
+
sendMail: sendMailMock,
|
|
38
|
+
verify: jest.fn(),
|
|
39
|
+
})
|
|
40
|
+
return sendMailMock
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
+
const { getGlobalUserParams } = require("@budibase/backend-core/db")
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves all users from the current tenancy.
|
|
6
|
+
*/
|
|
7
|
+
exports.allUsers = async () => {
|
|
8
|
+
const db = getGlobalDB()
|
|
9
|
+
const response = await db.allDocs(
|
|
10
|
+
getGlobalUserParams(null, {
|
|
11
|
+
include_docs: true,
|
|
12
|
+
})
|
|
13
|
+
)
|
|
14
|
+
return response.rows.map(row => row.doc)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets a user by ID from the global database, based on the current tenancy.
|
|
19
|
+
*/
|
|
20
|
+
exports.getUser = async userId => {
|
|
21
|
+
const db = getGlobalDB()
|
|
22
|
+
let user
|
|
23
|
+
try {
|
|
24
|
+
user = await db.get(userId)
|
|
25
|
+
} catch (err) {
|
|
26
|
+
// no user found, just return nothing
|
|
27
|
+
user = {}
|
|
28
|
+
}
|
|
29
|
+
if (user) {
|
|
30
|
+
delete user.password
|
|
31
|
+
}
|
|
32
|
+
return user
|
|
33
|
+
}
|