@budibase/server 2.4.42-alpha.4 → 2.4.42-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/builder/assets/{index.3e01f4fd.js → index.0d64dce3.js} +237 -237
- package/builder/index.html +1 -1
- package/dist/middleware/currentapp.js +1 -27
- package/dist/package.json +7 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/middleware/currentapp.ts +1 -30
- package/src/middleware/tests/currentapp.spec.js +6 -42
- package/src/tests/utilities/TestConfiguration.ts +3 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.4.42-alpha.
|
|
4
|
+
"version": "2.4.42-alpha.5",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"license": "GPL-3.0",
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
47
|
-
"@budibase/backend-core": "2.4.42-alpha.
|
|
48
|
-
"@budibase/client": "2.4.42-alpha.
|
|
49
|
-
"@budibase/pro": "2.4.42-alpha.
|
|
50
|
-
"@budibase/shared-core": "2.4.42-alpha.
|
|
51
|
-
"@budibase/string-templates": "2.4.42-alpha.
|
|
52
|
-
"@budibase/types": "2.4.42-alpha.
|
|
47
|
+
"@budibase/backend-core": "2.4.42-alpha.5",
|
|
48
|
+
"@budibase/client": "2.4.42-alpha.5",
|
|
49
|
+
"@budibase/pro": "2.4.42-alpha.4",
|
|
50
|
+
"@budibase/shared-core": "2.4.42-alpha.5",
|
|
51
|
+
"@budibase/string-templates": "2.4.42-alpha.5",
|
|
52
|
+
"@budibase/types": "2.4.42-alpha.5",
|
|
53
53
|
"@bull-board/api": "3.7.0",
|
|
54
54
|
"@bull-board/koa": "3.9.4",
|
|
55
55
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"optionalDependencies": {
|
|
177
177
|
"oracledb": "5.3.0"
|
|
178
178
|
},
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "9d4cf0848f406553056f1ec1eba0a38c72551c14"
|
|
180
180
|
}
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
utils,
|
|
3
3
|
constants,
|
|
4
4
|
roles,
|
|
5
|
-
db as dbCore,
|
|
6
5
|
tenancy,
|
|
7
6
|
context,
|
|
8
7
|
} from "@budibase/backend-core"
|
|
@@ -15,29 +14,10 @@ import { UserCtx } from "@budibase/types"
|
|
|
15
14
|
export default async (ctx: UserCtx, next: any) => {
|
|
16
15
|
// try to get the appID from the request
|
|
17
16
|
let requestAppId = await utils.getAppIdFromCtx(ctx)
|
|
18
|
-
|
|
19
|
-
let appCookie: { appId?: string } | undefined
|
|
20
|
-
try {
|
|
21
|
-
appCookie = utils.getCookie(ctx, constants.Cookie.CurrentApp)
|
|
22
|
-
} catch (err) {
|
|
23
|
-
utils.clearCookie(ctx, constants.Cookie.CurrentApp)
|
|
24
|
-
}
|
|
25
|
-
if (!appCookie && !requestAppId) {
|
|
17
|
+
if (!requestAppId) {
|
|
26
18
|
return next()
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
// check the app exists referenced in cookie
|
|
30
|
-
if (appCookie) {
|
|
31
|
-
const appId = appCookie.appId
|
|
32
|
-
const exists = await dbCore.dbExists(appId)
|
|
33
|
-
if (!exists) {
|
|
34
|
-
utils.clearCookie(ctx, constants.Cookie.CurrentApp)
|
|
35
|
-
return next()
|
|
36
|
-
}
|
|
37
|
-
// if the request app ID wasn't set, update it with the cookie
|
|
38
|
-
requestAppId = requestAppId || appId
|
|
39
|
-
}
|
|
40
|
-
|
|
41
21
|
// deny access to application preview
|
|
42
22
|
if (!env.isTest()) {
|
|
43
23
|
if (
|
|
@@ -45,7 +25,6 @@ export default async (ctx: UserCtx, next: any) => {
|
|
|
45
25
|
!isWebhookEndpoint(ctx) &&
|
|
46
26
|
(!ctx.user || !ctx.user.builder || !ctx.user.builder.global)
|
|
47
27
|
) {
|
|
48
|
-
utils.clearCookie(ctx, constants.Cookie.CurrentApp)
|
|
49
28
|
return ctx.redirect("/")
|
|
50
29
|
}
|
|
51
30
|
}
|
|
@@ -127,14 +106,6 @@ export default async (ctx: UserCtx, next: any) => {
|
|
|
127
106
|
role: await roles.getRole(roleId),
|
|
128
107
|
}
|
|
129
108
|
}
|
|
130
|
-
if (
|
|
131
|
-
(requestAppId !== appId ||
|
|
132
|
-
appCookie == null ||
|
|
133
|
-
appCookie.appId !== requestAppId) &&
|
|
134
|
-
!skipCookie
|
|
135
|
-
) {
|
|
136
|
-
utils.setCookie(ctx, { appId }, constants.Cookie.CurrentApp)
|
|
137
|
-
}
|
|
138
109
|
|
|
139
110
|
return next()
|
|
140
111
|
})
|
|
@@ -158,27 +158,22 @@ describe("Current app middleware", () => {
|
|
|
158
158
|
})
|
|
159
159
|
|
|
160
160
|
describe("check functionality when logged in", () => {
|
|
161
|
-
async function checkExpected(
|
|
161
|
+
async function checkExpected() {
|
|
162
162
|
config.setUser()
|
|
163
163
|
await config.executeMiddleware()
|
|
164
|
-
|
|
165
|
-
if (setCookie) {
|
|
166
|
-
expect(utils.setCookie).toHaveBeenCalled()
|
|
167
|
-
} else {
|
|
168
|
-
expect(utils.setCookie).not.toHaveBeenCalled()
|
|
169
|
-
}
|
|
164
|
+
|
|
170
165
|
expect(config.ctx.roleId).toEqual("PUBLIC")
|
|
171
166
|
expect(config.ctx.user.role._id).toEqual("PUBLIC")
|
|
172
167
|
expect(config.ctx.appId).toEqual("app_test")
|
|
173
168
|
expect(config.next).toHaveBeenCalled()
|
|
174
169
|
}
|
|
175
170
|
|
|
176
|
-
it("should be able to setup an app token
|
|
171
|
+
it("should be able to setup an app token on a first call", async () => {
|
|
177
172
|
mockAuthWithCookie()
|
|
178
|
-
await checkExpected(
|
|
173
|
+
await checkExpected()
|
|
179
174
|
})
|
|
180
175
|
|
|
181
|
-
it("should perform correct
|
|
176
|
+
it("should perform correct on a first call", async () => {
|
|
182
177
|
mockReset()
|
|
183
178
|
jest.mock("@budibase/backend-core", () => {
|
|
184
179
|
const core = jest.requireActual("@budibase/backend-core")
|
|
@@ -206,38 +201,7 @@ describe("Current app middleware", () => {
|
|
|
206
201
|
},
|
|
207
202
|
}
|
|
208
203
|
})
|
|
209
|
-
await checkExpected(
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it("lastly check what occurs when cookie doesn't need updated", async () => {
|
|
213
|
-
mockReset()
|
|
214
|
-
jest.mock("@budibase/backend-core", () => {
|
|
215
|
-
const core = jest.requireActual("@budibase/backend-core")
|
|
216
|
-
return {
|
|
217
|
-
...core,
|
|
218
|
-
db: {
|
|
219
|
-
...core.db,
|
|
220
|
-
dbExists: () => true,
|
|
221
|
-
},
|
|
222
|
-
utils: {
|
|
223
|
-
getAppIdFromCtx: () => {
|
|
224
|
-
return "app_test"
|
|
225
|
-
},
|
|
226
|
-
setCookie: jest.fn(),
|
|
227
|
-
getCookie: () => ({ appId: "app_test", roleId: "PUBLIC" }),
|
|
228
|
-
},
|
|
229
|
-
cache: {
|
|
230
|
-
user: {
|
|
231
|
-
getUser: async id => {
|
|
232
|
-
return {
|
|
233
|
-
_id: "us_uuid1",
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
await checkExpected(false)
|
|
204
|
+
await checkExpected()
|
|
241
205
|
})
|
|
242
206
|
})
|
|
243
207
|
})
|
|
@@ -330,21 +330,13 @@ class TestConfiguration {
|
|
|
330
330
|
sessionId: "sessionid",
|
|
331
331
|
tenantId: this.getTenantId(),
|
|
332
332
|
}
|
|
333
|
-
const app = {
|
|
334
|
-
roleId: roleId,
|
|
335
|
-
appId,
|
|
336
|
-
}
|
|
337
333
|
const authToken = auth.jwt.sign(authObj, coreEnv.JWT_SECRET)
|
|
338
|
-
const appToken = auth.jwt.sign(app, coreEnv.JWT_SECRET)
|
|
339
334
|
|
|
340
335
|
// returning necessary request headers
|
|
341
336
|
await cache.user.invalidateUser(userId)
|
|
342
337
|
return {
|
|
343
338
|
Accept: "application/json",
|
|
344
|
-
Cookie: [
|
|
345
|
-
`${constants.Cookie.Auth}=${authToken}`,
|
|
346
|
-
`${constants.Cookie.CurrentApp}=${appToken}`,
|
|
347
|
-
],
|
|
339
|
+
Cookie: [`${constants.Cookie.Auth}=${authToken}`],
|
|
348
340
|
[constants.Header.APP_ID]: appId,
|
|
349
341
|
}
|
|
350
342
|
})
|
|
@@ -359,18 +351,11 @@ class TestConfiguration {
|
|
|
359
351
|
sessionId: "sessionid",
|
|
360
352
|
tenantId,
|
|
361
353
|
}
|
|
362
|
-
const app = {
|
|
363
|
-
roleId: roles.BUILTIN_ROLE_IDS.ADMIN,
|
|
364
|
-
appId: this.appId,
|
|
365
|
-
}
|
|
366
354
|
const authToken = auth.jwt.sign(authObj, coreEnv.JWT_SECRET)
|
|
367
|
-
|
|
355
|
+
|
|
368
356
|
const headers: any = {
|
|
369
357
|
Accept: "application/json",
|
|
370
|
-
Cookie: [
|
|
371
|
-
`${constants.Cookie.Auth}=${authToken}`,
|
|
372
|
-
`${constants.Cookie.CurrentApp}=${appToken}`,
|
|
373
|
-
],
|
|
358
|
+
Cookie: [`${constants.Cookie.Auth}=${authToken}`],
|
|
374
359
|
[constants.Header.CSRF_TOKEN]: this.defaultUserValues.csrfToken,
|
|
375
360
|
Host: this.tenantHost(),
|
|
376
361
|
...extras,
|