@budibase/worker 2.3.20 → 2.3.21-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 +14 -18
- package/package.json +12 -8
- package/scripts/dev/manage.js +1 -0
- package/scripts/test.sh +12 -0
- package/src/api/controllers/global/auth.ts +109 -111
- package/src/api/controllers/global/configs.ts +150 -142
- package/src/api/controllers/global/self.ts +28 -44
- package/src/api/controllers/global/users.ts +211 -32
- 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/configs.ts +6 -12
- package/src/api/routes/global/tests/auditLogs.spec.ts +111 -0
- package/src/api/routes/global/tests/auth.spec.ts +217 -18
- package/src/api/routes/global/tests/configs.spec.ts +93 -65
- package/src/api/routes/global/tests/realEmail.spec.ts +1 -0
- 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 +29 -28
- package/src/api/routes/global/users.ts +19 -14
- package/src/api/routes/index.ts +3 -0
- 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/db/index.ts +8 -2
- package/src/ddApm.ts +7 -0
- package/src/elasticApm.ts +10 -0
- package/src/environment.ts +4 -0
- package/src/index.ts +29 -8
- 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 +76 -0
- package/src/sdk/users/users.ts +86 -53
- package/src/tests/TestConfiguration.ts +41 -62
- package/src/tests/api/auditLogs.ts +26 -0
- package/src/tests/api/auth.ts +44 -14
- package/src/tests/api/base.ts +2 -1
- package/src/tests/api/configs.ts +9 -1
- package/src/tests/api/email.ts +1 -0
- package/src/tests/api/index.ts +3 -0
- 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/configs.ts +20 -13
- package/src/tests/structures/index.ts +0 -4
- package/src/utilities/email.ts +22 -68
- package/src/utilities/redis.ts +42 -2
- package/src/utilities/templates.ts +4 -9
- 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
|
@@ -15,39 +15,29 @@ const supertest = require("supertest")
|
|
|
15
15
|
import { Config } from "../constants"
|
|
16
16
|
import {
|
|
17
17
|
users,
|
|
18
|
-
|
|
18
|
+
context,
|
|
19
19
|
sessions,
|
|
20
20
|
auth,
|
|
21
21
|
constants,
|
|
22
22
|
env as coreEnv,
|
|
23
23
|
} from "@budibase/backend-core"
|
|
24
|
-
import structures, {
|
|
25
|
-
import {
|
|
24
|
+
import structures, { CSRF_TOKEN } from "./structures"
|
|
25
|
+
import { SaveUserResponse, User, AuthToken } from "@budibase/types"
|
|
26
26
|
import API from "./api"
|
|
27
27
|
|
|
28
|
-
enum Mode {
|
|
29
|
-
CLOUD = "cloud",
|
|
30
|
-
SELF = "self",
|
|
31
|
-
}
|
|
32
|
-
|
|
33
28
|
class TestConfiguration {
|
|
34
29
|
server: any
|
|
35
30
|
request: any
|
|
36
31
|
api: API
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
tenantId: string
|
|
33
|
+
user?: User
|
|
34
|
+
userPassword = "test"
|
|
39
35
|
|
|
40
|
-
constructor(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
) {
|
|
46
|
-
if (opts.mode === Mode.CLOUD) {
|
|
47
|
-
this.modeCloud()
|
|
48
|
-
} else if (opts.mode === Mode.SELF) {
|
|
49
|
-
this.modeSelf()
|
|
50
|
-
}
|
|
36
|
+
constructor(opts: { openServer: boolean } = { openServer: true }) {
|
|
37
|
+
// default to cloud hosting
|
|
38
|
+
this.cloudHosted()
|
|
39
|
+
|
|
40
|
+
this.tenantId = structures.tenant.id()
|
|
51
41
|
|
|
52
42
|
if (opts.openServer) {
|
|
53
43
|
env.PORT = "0" // random port
|
|
@@ -63,26 +53,19 @@ class TestConfiguration {
|
|
|
63
53
|
return this.request
|
|
64
54
|
}
|
|
65
55
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
setMultiTenancy = (value: boolean) => {
|
|
69
|
-
env._set("MULTI_TENANCY", value)
|
|
70
|
-
coreEnv._set("MULTI_TENANCY", value)
|
|
71
|
-
}
|
|
56
|
+
// HOSTING
|
|
72
57
|
|
|
73
58
|
setSelfHosted = (value: boolean) => {
|
|
74
59
|
env._set("SELF_HOSTED", value)
|
|
75
60
|
coreEnv._set("SELF_HOSTED", value)
|
|
76
61
|
}
|
|
77
62
|
|
|
78
|
-
|
|
63
|
+
cloudHosted = () => {
|
|
79
64
|
this.setSelfHosted(false)
|
|
80
|
-
this.setMultiTenancy(true)
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
|
|
67
|
+
selfHosted = () => {
|
|
84
68
|
this.setSelfHosted(true)
|
|
85
|
-
this.setMultiTenancy(false)
|
|
86
69
|
}
|
|
87
70
|
|
|
88
71
|
// UTILS
|
|
@@ -103,7 +86,7 @@ class TestConfiguration {
|
|
|
103
86
|
if (params) {
|
|
104
87
|
request.params = params
|
|
105
88
|
}
|
|
106
|
-
await
|
|
89
|
+
await context.doInTenant(this.getTenantId(), () => {
|
|
107
90
|
return controlFunc(request)
|
|
108
91
|
})
|
|
109
92
|
return request.body
|
|
@@ -112,13 +95,13 @@ class TestConfiguration {
|
|
|
112
95
|
// SETUP / TEARDOWN
|
|
113
96
|
|
|
114
97
|
async beforeAll() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
98
|
+
try {
|
|
99
|
+
await this.createDefaultUser()
|
|
100
|
+
await this.createSession(this.user!)
|
|
101
|
+
} catch (e: any) {
|
|
102
|
+
console.error(e)
|
|
103
|
+
throw new Error(e.message)
|
|
104
|
+
}
|
|
122
105
|
}
|
|
123
106
|
|
|
124
107
|
async afterAll() {
|
|
@@ -129,6 +112,12 @@ class TestConfiguration {
|
|
|
129
112
|
|
|
130
113
|
// TENANCY
|
|
131
114
|
|
|
115
|
+
doInTenant(task: any) {
|
|
116
|
+
return context.doInTenant(this.tenantId, () => {
|
|
117
|
+
return task()
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
132
121
|
createTenant = async (): Promise<User> => {
|
|
133
122
|
// create user / new tenant
|
|
134
123
|
const res = await this.api.users.createAdminUser()
|
|
@@ -150,9 +139,9 @@ class TestConfiguration {
|
|
|
150
139
|
|
|
151
140
|
getTenantId() {
|
|
152
141
|
try {
|
|
153
|
-
return
|
|
154
|
-
} catch (e
|
|
155
|
-
return
|
|
142
|
+
return context.getTenantId()
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return this.tenantId!
|
|
156
145
|
}
|
|
157
146
|
}
|
|
158
147
|
|
|
@@ -200,14 +189,11 @@ class TestConfiguration {
|
|
|
200
189
|
}
|
|
201
190
|
|
|
202
191
|
defaultHeaders() {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
} else {
|
|
209
|
-
throw new Error("could not determine auth headers to use")
|
|
210
|
-
}
|
|
192
|
+
return this.authHeaders(this.user!)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
tenantIdHeaders() {
|
|
196
|
+
return { [constants.Header.TENANT_ID]: this.tenantId }
|
|
211
197
|
}
|
|
212
198
|
|
|
213
199
|
internalAPIHeaders() {
|
|
@@ -222,22 +208,15 @@ class TestConfiguration {
|
|
|
222
208
|
|
|
223
209
|
async createDefaultUser() {
|
|
224
210
|
const user = structures.users.adminUser({
|
|
225
|
-
|
|
226
|
-
password: "test",
|
|
211
|
+
password: this.userPassword,
|
|
227
212
|
})
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
async createTenant1User() {
|
|
232
|
-
const user = structures.users.adminUser({
|
|
233
|
-
email: "tenant1@test.com",
|
|
234
|
-
password: "test",
|
|
213
|
+
await context.doInTenant(this.tenantId!, async () => {
|
|
214
|
+
this.user = await this.createUser(user)
|
|
235
215
|
})
|
|
236
|
-
this.tenant1User = await this.createUser(user)
|
|
237
216
|
}
|
|
238
217
|
|
|
239
218
|
async getUser(email: string): Promise<User> {
|
|
240
|
-
return
|
|
219
|
+
return context.doInTenant(this.getTenantId(), () => {
|
|
241
220
|
return users.getGlobalUserByEmail(email)
|
|
242
221
|
})
|
|
243
222
|
}
|
|
@@ -247,7 +226,7 @@ class TestConfiguration {
|
|
|
247
226
|
user = structures.users.user()
|
|
248
227
|
}
|
|
249
228
|
const response = await this._req(user, null, controllers.users.save)
|
|
250
|
-
const body = response as
|
|
229
|
+
const body = response as SaveUserResponse
|
|
251
230
|
return this.getUser(body.email)
|
|
252
231
|
}
|
|
253
232
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AuditLogSearchParams, SearchAuditLogsResponse } from "@budibase/types"
|
|
2
|
+
import TestConfiguration from "../TestConfiguration"
|
|
3
|
+
import { TestAPI } from "./base"
|
|
4
|
+
|
|
5
|
+
export class AuditLogAPI extends TestAPI {
|
|
6
|
+
constructor(config: TestConfiguration) {
|
|
7
|
+
super(config)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
search = async (search: AuditLogSearchParams) => {
|
|
11
|
+
const res = await this.request
|
|
12
|
+
.post("/api/global/auditlogs/search")
|
|
13
|
+
.send(search)
|
|
14
|
+
.set(this.config.defaultHeaders())
|
|
15
|
+
.expect("Content-Type", /json/)
|
|
16
|
+
.expect(200)
|
|
17
|
+
return res.body as SearchAuditLogsResponse
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
download = (search: AuditLogSearchParams) => {
|
|
21
|
+
const query = encodeURIComponent(JSON.stringify(search))
|
|
22
|
+
return this.request
|
|
23
|
+
.get(`/api/global/auditlogs/download?query=${query}`)
|
|
24
|
+
.set(this.config.defaultHeaders())
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/tests/api/auth.ts
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
import TestConfiguration from "../TestConfiguration"
|
|
2
|
-
import { TestAPI } from "./base"
|
|
2
|
+
import { TestAPI, TestAPIOpts } from "./base"
|
|
3
3
|
|
|
4
4
|
export class AuthAPI extends TestAPI {
|
|
5
5
|
constructor(config: TestConfiguration) {
|
|
6
6
|
super(config)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
updatePassword = (
|
|
9
|
+
updatePassword = (
|
|
10
|
+
resetCode: string,
|
|
11
|
+
password: string,
|
|
12
|
+
opts?: TestAPIOpts
|
|
13
|
+
) => {
|
|
10
14
|
return this.request
|
|
11
15
|
.post(`/api/global/auth/${this.config.getTenantId()}/reset/update`)
|
|
12
16
|
.send({
|
|
13
|
-
password
|
|
14
|
-
resetCode
|
|
17
|
+
password,
|
|
18
|
+
resetCode,
|
|
15
19
|
})
|
|
16
20
|
.expect("Content-Type", /json/)
|
|
17
|
-
.expect(200)
|
|
21
|
+
.expect(opts?.status ? opts.status : 200)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
login = (
|
|
25
|
+
tenantId: string,
|
|
26
|
+
email: string,
|
|
27
|
+
password: string,
|
|
28
|
+
opts?: TestAPIOpts
|
|
29
|
+
) => {
|
|
30
|
+
return this.request
|
|
31
|
+
.post(`/api/global/auth/${tenantId}/login`)
|
|
32
|
+
.send({
|
|
33
|
+
username: email,
|
|
34
|
+
password: password,
|
|
35
|
+
})
|
|
36
|
+
.expect(opts?.status ? opts.status : 200)
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
logout = () => {
|
|
@@ -24,22 +43,33 @@ export class AuthAPI extends TestAPI {
|
|
|
24
43
|
.expect(200)
|
|
25
44
|
}
|
|
26
45
|
|
|
27
|
-
requestPasswordReset = async (
|
|
46
|
+
requestPasswordReset = async (
|
|
47
|
+
sendMailMock: any,
|
|
48
|
+
email: string,
|
|
49
|
+
opts?: TestAPIOpts
|
|
50
|
+
) => {
|
|
28
51
|
await this.config.saveSmtpConfig()
|
|
29
52
|
await this.config.saveSettingsConfig()
|
|
30
|
-
|
|
53
|
+
|
|
31
54
|
const res = await this.request
|
|
32
55
|
.post(`/api/global/auth/${this.config.getTenantId()}/reset`)
|
|
33
56
|
.send({
|
|
34
|
-
email:
|
|
57
|
+
email: email,
|
|
35
58
|
})
|
|
36
59
|
.expect("Content-Type", /json/)
|
|
37
|
-
.expect(200)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
.expect(opts?.status ? opts.status : 200)
|
|
61
|
+
|
|
62
|
+
let code: string | undefined
|
|
63
|
+
if (res.status === 200) {
|
|
64
|
+
if (sendMailMock.mock.calls.length) {
|
|
65
|
+
const emailCall = sendMailMock.mock.calls[0][0]
|
|
66
|
+
const parts = emailCall.html.split(
|
|
67
|
+
`http://localhost:10000/builder/auth/reset?code=`
|
|
68
|
+
)
|
|
69
|
+
code = parts[1].split('"')[0].split("&")[0]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
43
73
|
return { code, res }
|
|
44
74
|
}
|
|
45
75
|
}
|
package/src/tests/api/base.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TestConfiguration from "../TestConfiguration"
|
|
2
|
+
import { SuperTest, Test } from "supertest"
|
|
2
3
|
|
|
3
4
|
export interface TestAPIOpts {
|
|
4
5
|
headers?: any
|
|
@@ -7,7 +8,7 @@ export interface TestAPIOpts {
|
|
|
7
8
|
|
|
8
9
|
export abstract class TestAPI {
|
|
9
10
|
config: TestConfiguration
|
|
10
|
-
request:
|
|
11
|
+
request: SuperTest<Test>
|
|
11
12
|
|
|
12
13
|
protected constructor(config: TestConfiguration) {
|
|
13
14
|
this.config = config
|
package/src/tests/api/configs.ts
CHANGED
|
@@ -10,8 +10,16 @@ export class ConfigAPI extends TestAPI {
|
|
|
10
10
|
return this.request
|
|
11
11
|
.get(`/api/global/configs/checklist`)
|
|
12
12
|
.set(this.config.defaultHeaders())
|
|
13
|
+
.expect(200)
|
|
13
14
|
.expect("Content-Type", /json/)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getPublicSettings = () => {
|
|
18
|
+
return this.request
|
|
19
|
+
.get(`/api/global/configs/public`)
|
|
20
|
+
.set(this.config.defaultHeaders())
|
|
14
21
|
.expect(200)
|
|
22
|
+
.expect("Content-Type", /json/)
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
saveConfig = (data: any) => {
|
|
@@ -19,8 +27,8 @@ export class ConfigAPI extends TestAPI {
|
|
|
19
27
|
.post(`/api/global/configs`)
|
|
20
28
|
.send(data)
|
|
21
29
|
.set(this.config.defaultHeaders())
|
|
22
|
-
.expect("Content-Type", /json/)
|
|
23
30
|
.expect(200)
|
|
31
|
+
.expect("Content-Type", /json/)
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
OIDCCallback = (configId: string, preAuthRes: any) => {
|
package/src/tests/api/email.ts
CHANGED
package/src/tests/api/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { GroupsAPI } from "./groups"
|
|
|
14
14
|
import { RolesAPI } from "./roles"
|
|
15
15
|
import { TemplatesAPI } from "./templates"
|
|
16
16
|
import { LicenseAPI } from "./license"
|
|
17
|
+
import { AuditLogAPI } from "./auditLogs"
|
|
17
18
|
export default class API {
|
|
18
19
|
accounts: AccountAPI
|
|
19
20
|
auth: AuthAPI
|
|
@@ -30,6 +31,7 @@ export default class API {
|
|
|
30
31
|
roles: RolesAPI
|
|
31
32
|
templates: TemplatesAPI
|
|
32
33
|
license: LicenseAPI
|
|
34
|
+
auditLogs: AuditLogAPI
|
|
33
35
|
|
|
34
36
|
constructor(config: TestConfiguration) {
|
|
35
37
|
this.accounts = new AccountAPI(config)
|
|
@@ -47,5 +49,6 @@ export default class API {
|
|
|
47
49
|
this.roles = new RolesAPI(config)
|
|
48
50
|
this.templates = new TemplatesAPI(config)
|
|
49
51
|
this.license = new LicenseAPI(config)
|
|
52
|
+
this.auditLogs = new AuditLogAPI(config)
|
|
50
53
|
}
|
|
51
54
|
}
|
package/src/tests/api/restore.ts
CHANGED
package/src/tests/api/users.ts
CHANGED
|
@@ -26,8 +26,8 @@ export class UserAPI extends TestAPI {
|
|
|
26
26
|
email,
|
|
27
27
|
})
|
|
28
28
|
.set(this.config.defaultHeaders())
|
|
29
|
-
.expect("Content-Type", /json/)
|
|
30
29
|
.expect(status)
|
|
30
|
+
.expect("Content-Type", /json/)
|
|
31
31
|
|
|
32
32
|
if (status !== 200) {
|
|
33
33
|
return { code: undefined, res }
|
|
@@ -100,7 +100,7 @@ export class UserAPI extends TestAPI {
|
|
|
100
100
|
request = {
|
|
101
101
|
email: structures.email(),
|
|
102
102
|
password: generator.string(),
|
|
103
|
-
tenantId: structures.
|
|
103
|
+
tenantId: structures.tenant.id(),
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
const res = await this.request
|
package/src/tests/jestEnv.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
process.env.SELF_HOSTED = "0"
|
|
2
2
|
process.env.NODE_ENV = "jest"
|
|
3
3
|
process.env.JWT_SECRET = "test-jwtsecret"
|
|
4
|
-
process.env.LOG_LEVEL = "
|
|
4
|
+
process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
|
|
5
|
+
process.env.ENABLE_4XX_HTTP_LOGGING = "0"
|
|
5
6
|
process.env.MULTI_TENANCY = "1"
|
|
6
7
|
process.env.MINIO_URL = "http://localhost"
|
|
7
8
|
process.env.MINIO_ACCESS_KEY = "test"
|
package/src/tests/jestSetup.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./logging"
|
|
2
|
+
|
|
3
|
+
import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
|
|
4
|
+
import env from "../environment"
|
|
5
|
+
import { env as coreEnv } from "@budibase/backend-core"
|
|
2
6
|
|
|
3
7
|
// must explicitly enable fetch mock
|
|
4
8
|
mocks.fetch.enable()
|
|
@@ -8,12 +12,12 @@ mocks.fetch.enable()
|
|
|
8
12
|
const tk = require("timekeeper")
|
|
9
13
|
tk.freeze(mocks.date.MOCK_DATE)
|
|
10
14
|
|
|
11
|
-
if (!process.env.DEBUG) {
|
|
12
|
-
global.console.log = jest.fn() // console.log are ignored in tests
|
|
13
|
-
}
|
|
14
|
-
|
|
15
15
|
if (!process.env.CI) {
|
|
16
16
|
// set a longer timeout in dev for debugging
|
|
17
17
|
// 100 seconds
|
|
18
|
-
jest.setTimeout(
|
|
18
|
+
jest.setTimeout(100 * 1000)
|
|
19
|
+
} else {
|
|
20
|
+
jest.setTimeout(10 * 1000)
|
|
19
21
|
}
|
|
22
|
+
|
|
23
|
+
testContainerUtils.setupEnv(env, coreEnv)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export enum LogLevel {
|
|
2
|
+
TRACE = "trace",
|
|
3
|
+
DEBUG = "debug",
|
|
4
|
+
INFO = "info",
|
|
5
|
+
WARN = "warn",
|
|
6
|
+
ERROR = "error",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const LOG_INDEX: { [key in LogLevel]: number } = {
|
|
10
|
+
[LogLevel.TRACE]: 1,
|
|
11
|
+
[LogLevel.DEBUG]: 2,
|
|
12
|
+
[LogLevel.INFO]: 3,
|
|
13
|
+
[LogLevel.WARN]: 4,
|
|
14
|
+
[LogLevel.ERROR]: 5,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const setIndex = LOG_INDEX[process.env.LOG_LEVEL as LogLevel]
|
|
18
|
+
|
|
19
|
+
if (setIndex > LOG_INDEX.trace) {
|
|
20
|
+
global.console.trace = jest.fn()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (setIndex > LOG_INDEX.debug) {
|
|
24
|
+
global.console.debug = jest.fn()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (setIndex > LOG_INDEX.info) {
|
|
28
|
+
global.console.info = jest.fn()
|
|
29
|
+
global.console.log = jest.fn()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (setIndex > LOG_INDEX.warn) {
|
|
33
|
+
global.console.warn = jest.fn()
|
|
34
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { Config } from "../../constants"
|
|
2
1
|
import { utils } from "@budibase/backend-core"
|
|
2
|
+
import {
|
|
3
|
+
SettingsConfig,
|
|
4
|
+
ConfigType,
|
|
5
|
+
SMTPConfig,
|
|
6
|
+
GoogleConfig,
|
|
7
|
+
OIDCConfig,
|
|
8
|
+
} from "@budibase/types"
|
|
3
9
|
|
|
4
|
-
export function oidc(conf?: any) {
|
|
10
|
+
export function oidc(conf?: any): OIDCConfig {
|
|
5
11
|
return {
|
|
6
|
-
type:
|
|
12
|
+
type: ConfigType.OIDC,
|
|
7
13
|
config: {
|
|
8
14
|
configs: [
|
|
9
15
|
{
|
|
@@ -21,9 +27,9 @@ export function oidc(conf?: any) {
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
export function google(conf?: any) {
|
|
30
|
+
export function google(conf?: any): GoogleConfig {
|
|
25
31
|
return {
|
|
26
|
-
type:
|
|
32
|
+
type: ConfigType.GOOGLE,
|
|
27
33
|
config: {
|
|
28
34
|
clientID: "clientId",
|
|
29
35
|
clientSecret: "clientSecret",
|
|
@@ -33,9 +39,9 @@ export function google(conf?: any) {
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
export function smtp(conf?: any) {
|
|
42
|
+
export function smtp(conf?: any): SMTPConfig {
|
|
37
43
|
return {
|
|
38
|
-
type:
|
|
44
|
+
type: ConfigType.SMTP,
|
|
39
45
|
config: {
|
|
40
46
|
port: 12345,
|
|
41
47
|
host: "smtptesthost.com",
|
|
@@ -47,25 +53,26 @@ export function smtp(conf?: any) {
|
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
export function smtpEthereal() {
|
|
56
|
+
export function smtpEthereal(): SMTPConfig {
|
|
51
57
|
return {
|
|
52
|
-
type:
|
|
58
|
+
type: ConfigType.SMTP,
|
|
53
59
|
config: {
|
|
54
60
|
port: 587,
|
|
55
61
|
host: "smtp.ethereal.email",
|
|
62
|
+
from: "testfrom@test.com",
|
|
56
63
|
secure: false,
|
|
57
64
|
auth: {
|
|
58
|
-
user: "
|
|
59
|
-
pass: "
|
|
65
|
+
user: "wyatt.zulauf29@ethereal.email",
|
|
66
|
+
pass: "tEwDtHBWWxusVWAPfa",
|
|
60
67
|
},
|
|
61
68
|
connectionTimeout: 1000, // must be less than the jest default of 5000
|
|
62
69
|
},
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
export function settings(conf?: any) {
|
|
73
|
+
export function settings(conf?: any): SettingsConfig {
|
|
67
74
|
return {
|
|
68
|
-
type:
|
|
75
|
+
type: ConfigType.SETTINGS,
|
|
69
76
|
config: {
|
|
70
77
|
platformUrl: "http://localhost:10000",
|
|
71
78
|
logoUrl: "",
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { structures } from "@budibase/backend-core/tests"
|
|
2
2
|
import * as configs from "./configs"
|
|
3
|
-
import * as users from "./users"
|
|
4
3
|
import * as groups from "./groups"
|
|
5
4
|
import { v4 as uuid } from "uuid"
|
|
6
5
|
|
|
7
6
|
export const TENANT_ID = "default"
|
|
8
|
-
export const TENANT_1 = "tenant1"
|
|
9
7
|
export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
|
|
10
8
|
|
|
11
9
|
const pkg = {
|
|
12
10
|
...structures,
|
|
13
11
|
uuid,
|
|
14
12
|
configs,
|
|
15
|
-
users,
|
|
16
13
|
TENANT_ID,
|
|
17
|
-
TENANT_1,
|
|
18
14
|
CSRF_TOKEN,
|
|
19
15
|
groups,
|
|
20
16
|
}
|