@budibase/server 2.4.42 → 2.4.44-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 +6 -1
- package/builder/assets/{index.3d64bc07.js → index.6846a382.js} +385 -384
- package/builder/assets/index.7f9a008b.css +6 -0
- package/builder/index.html +7 -7
- package/dist/api/controllers/application.js +28 -24
- package/dist/api/controllers/public/metrics.js +113 -0
- package/dist/api/controllers/row/external.js +15 -0
- package/dist/api/controllers/row/utils.js +4 -3
- package/dist/api/controllers/static/index.js +84 -24
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +34 -11
- package/dist/api/controllers/table/utils.js +2 -4
- package/dist/api/routes/public/index.js +8 -0
- package/dist/api/routes/public/metrics.js +30 -0
- package/dist/app.js +1 -0
- package/dist/integrations/googlesheets.js +4 -0
- package/dist/integrations/redis.js +1 -1
- package/dist/middleware/currentapp.js +1 -27
- package/dist/package.json +12 -11
- package/dist/sdk/users/utils.js +11 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/app.js +1 -10
- package/dist/utilities/fileSystem/filesystem.js +0 -4
- package/dist/utilities/global.js +17 -7
- package/jest.config.ts +2 -0
- package/package.json +13 -12
- package/scripts/test.sh +6 -4
- package/specs/openapi.json +39 -0
- package/specs/openapi.yaml +169 -0
- package/specs/resources/application.ts +11 -0
- package/specs/resources/index.ts +2 -0
- package/specs/resources/metrics.ts +81 -0
- package/src/api/controllers/application.ts +20 -21
- package/src/api/controllers/component.ts +2 -2
- package/src/api/controllers/public/metrics.ts +251 -0
- package/src/api/controllers/row/external.ts +14 -0
- package/src/api/controllers/row/utils.ts +4 -3
- package/src/api/controllers/static/index.ts +69 -26
- package/src/api/controllers/static/templates/BudibaseApp.svelte +34 -11
- package/src/api/controllers/table/tests/utils.spec.ts +97 -0
- package/src/api/controllers/table/utils.ts +20 -12
- package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
- package/src/api/routes/public/index.ts +10 -1
- package/src/api/routes/public/metrics.ts +28 -0
- package/src/api/routes/public/tests/metrics.spec.js +34 -0
- package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
- package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
- package/src/api/routes/tests/appSync.spec.ts +31 -0
- package/src/api/routes/tests/internalSearch.spec.js +8 -7
- package/src/app.ts +2 -1
- package/src/automations/automationUtils.ts +1 -1
- package/src/automations/tests/automation.spec.ts +99 -0
- package/src/db/defaultData/datasource_bb_default.ts +1 -1
- package/src/definitions/openapi.ts +15 -0
- package/src/integration-test/postgres.spec.ts +46 -52
- package/src/integrations/googlesheets.ts +4 -0
- package/src/integrations/redis.ts +1 -1
- package/src/integrations/tests/googlesheets.spec.ts +13 -13
- package/src/integrations/tests/redis.spec.ts +9 -5
- package/src/middleware/currentapp.ts +3 -32
- package/src/middleware/tests/currentapp.spec.js +6 -42
- package/src/sdk/users/tests/utils.spec.ts +159 -0
- package/src/sdk/users/utils.ts +18 -7
- package/src/tests/jestEnv.ts +1 -0
- package/src/tests/jestSetup.ts +5 -1
- package/src/tests/utilities/TestConfiguration.ts +18 -19
- package/src/tests/utilities/structures.ts +13 -1
- package/src/utilities/fileSystem/app.ts +2 -9
- package/src/utilities/fileSystem/filesystem.ts +0 -4
- package/src/utilities/global.ts +21 -9
- package/src/utilities/rowProcessor/index.ts +1 -1
- package/builder/assets/favicon.e7fc7733.png +0 -0
- package/builder/assets/index.b0e3aca6.css +0 -6
- package/src/automations/tests/automation.spec.js +0 -84
|
@@ -23,7 +23,7 @@ import { LoopStep, LoopStepType, LoopInput } from "../definitions/automations"
|
|
|
23
23
|
* @returns {object} The inputs object which has had all the various types supported by this function converted to their
|
|
24
24
|
* primitive types.
|
|
25
25
|
*/
|
|
26
|
-
export function cleanInputValues(inputs: Record<string, any>, schema
|
|
26
|
+
export function cleanInputValues(inputs: Record<string, any>, schema?: any) {
|
|
27
27
|
if (schema == null) {
|
|
28
28
|
return inputs
|
|
29
29
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
jest.mock("../../threads/automation")
|
|
2
|
+
jest.mock("../../utilities/redis", () => ({
|
|
3
|
+
init: jest.fn(),
|
|
4
|
+
checkTestFlag: () => {
|
|
5
|
+
return false
|
|
6
|
+
},
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
jest.spyOn(global.console, "error")
|
|
10
|
+
|
|
11
|
+
import "../../environment"
|
|
12
|
+
import * as automation from "../index"
|
|
13
|
+
import * as thread from "../../threads/automation"
|
|
14
|
+
import * as triggers from "../triggers"
|
|
15
|
+
import { basicAutomation } from "../../tests/utilities/structures"
|
|
16
|
+
import { wait } from "../../utilities"
|
|
17
|
+
import { makePartial } from "../../tests/utilities"
|
|
18
|
+
import { cleanInputValues } from "../automationUtils"
|
|
19
|
+
import * as setup from "./utilities"
|
|
20
|
+
import { Automation } from "@budibase/types"
|
|
21
|
+
|
|
22
|
+
describe("Run through some parts of the automations system", () => {
|
|
23
|
+
let config = setup.getConfig()
|
|
24
|
+
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
await automation.init()
|
|
27
|
+
await config.init()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
afterAll(async () => {
|
|
31
|
+
await automation.shutdown()
|
|
32
|
+
setup.afterAll()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it("should be able to init in builder", async () => {
|
|
36
|
+
const automation: Automation = {
|
|
37
|
+
...basicAutomation(),
|
|
38
|
+
appId: config.appId,
|
|
39
|
+
}
|
|
40
|
+
const fields: any = { a: 1, appId: config.appId }
|
|
41
|
+
await triggers.externalTrigger(automation, fields)
|
|
42
|
+
await wait(100)
|
|
43
|
+
expect(thread.execute).toHaveBeenCalled()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("should check coercion", async () => {
|
|
47
|
+
const table = await config.createTable()
|
|
48
|
+
const automation: any = basicAutomation()
|
|
49
|
+
automation.definition.trigger.inputs.tableId = table._id
|
|
50
|
+
automation.definition.trigger.stepId = "APP"
|
|
51
|
+
automation.definition.trigger.inputs.fields = { a: "number" }
|
|
52
|
+
const fields: any = {
|
|
53
|
+
appId: config.getAppId(),
|
|
54
|
+
fields: {
|
|
55
|
+
a: "1",
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
await triggers.externalTrigger(automation, fields)
|
|
59
|
+
await wait(100)
|
|
60
|
+
expect(thread.execute).toHaveBeenCalledWith(
|
|
61
|
+
makePartial({
|
|
62
|
+
data: {
|
|
63
|
+
event: {
|
|
64
|
+
fields: {
|
|
65
|
+
a: 1,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
expect.any(Function)
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("should be able to clean inputs with the utilities", () => {
|
|
75
|
+
// can't clean without a schema
|
|
76
|
+
let output = cleanInputValues({ a: "1" })
|
|
77
|
+
expect(output.a).toBe("1")
|
|
78
|
+
output = cleanInputValues(
|
|
79
|
+
{ a: "1", b: "true", c: "false", d: 1, e: "help" },
|
|
80
|
+
{
|
|
81
|
+
properties: {
|
|
82
|
+
a: {
|
|
83
|
+
type: "number",
|
|
84
|
+
},
|
|
85
|
+
b: {
|
|
86
|
+
type: "boolean",
|
|
87
|
+
},
|
|
88
|
+
c: {
|
|
89
|
+
type: "boolean",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
expect(output.a).toBe(1)
|
|
95
|
+
expect(output.b).toBe(true)
|
|
96
|
+
expect(output.c).toBe(false)
|
|
97
|
+
expect(output.d).toBe(1)
|
|
98
|
+
})
|
|
99
|
+
})
|
|
@@ -34,7 +34,7 @@ function syncLastIds(table: Table, rowCount: number) {
|
|
|
34
34
|
})
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function tableImport(table: Table, data: Row) {
|
|
37
|
+
function tableImport(table: Table, data: Row[]) {
|
|
38
38
|
const cloneTable = cloneDeep(table)
|
|
39
39
|
const rowDocs = importToRows(data, cloneTable)
|
|
40
40
|
syncLastIds(cloneTable, rowDocs.length)
|
|
@@ -22,6 +22,10 @@ export interface paths {
|
|
|
22
22
|
/** Based on application properties (currently only name) search for applications. */
|
|
23
23
|
post: operations["appSearch"];
|
|
24
24
|
};
|
|
25
|
+
"/metrics": {
|
|
26
|
+
/** Output metrics in OpenMetrics format compatible with Prometheus */
|
|
27
|
+
get: operations["metricsGet"];
|
|
28
|
+
};
|
|
25
29
|
"/queries/{queryId}": {
|
|
26
30
|
/** Queries which have been created within a Budibase app can be executed using this, */
|
|
27
31
|
post: operations["queryExecute"];
|
|
@@ -844,6 +848,17 @@ export interface operations {
|
|
|
844
848
|
};
|
|
845
849
|
};
|
|
846
850
|
};
|
|
851
|
+
/** Output metrics in OpenMetrics format compatible with Prometheus */
|
|
852
|
+
metricsGet: {
|
|
853
|
+
responses: {
|
|
854
|
+
/** Returns tenant metrics. */
|
|
855
|
+
200: {
|
|
856
|
+
content: {
|
|
857
|
+
"text/plain": string;
|
|
858
|
+
};
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
};
|
|
847
862
|
/** Queries which have been created within a Budibase app can be executed using this, */
|
|
848
863
|
queryExecute: {
|
|
849
864
|
parameters: {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import fetch from "node-fetch"
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
fetch.mockSearch()
|
|
1
4
|
import {
|
|
2
5
|
generateMakeRequest,
|
|
3
6
|
MakeRequestResponse,
|
|
@@ -16,6 +19,7 @@ import _ from "lodash"
|
|
|
16
19
|
import { generator } from "@budibase/backend-core/tests"
|
|
17
20
|
import { utils } from "@budibase/backend-core"
|
|
18
21
|
import { GenericContainer } from "testcontainers"
|
|
22
|
+
import { generateRowIdField } from "../integrations/utils"
|
|
19
23
|
|
|
20
24
|
const config = setup.getConfig()!
|
|
21
25
|
|
|
@@ -80,16 +84,10 @@ describe("row api - postgres", () => {
|
|
|
80
84
|
name: "id",
|
|
81
85
|
type: FieldType.AUTO,
|
|
82
86
|
autocolumn: true,
|
|
83
|
-
constraints: {
|
|
84
|
-
presence: true,
|
|
85
|
-
},
|
|
86
87
|
},
|
|
87
88
|
title: {
|
|
88
89
|
name: "title",
|
|
89
90
|
type: FieldType.STRING,
|
|
90
|
-
constraints: {
|
|
91
|
-
presence: true,
|
|
92
|
-
},
|
|
93
91
|
},
|
|
94
92
|
},
|
|
95
93
|
sourceId: postgresDatasource._id,
|
|
@@ -121,16 +119,10 @@ describe("row api - postgres", () => {
|
|
|
121
119
|
name: "id",
|
|
122
120
|
type: FieldType.AUTO,
|
|
123
121
|
autocolumn: true,
|
|
124
|
-
constraints: {
|
|
125
|
-
presence: true,
|
|
126
|
-
},
|
|
127
122
|
},
|
|
128
123
|
name: {
|
|
129
124
|
name: "name",
|
|
130
125
|
type: FieldType.STRING,
|
|
131
|
-
constraints: {
|
|
132
|
-
presence: true,
|
|
133
|
-
},
|
|
134
126
|
},
|
|
135
127
|
description: {
|
|
136
128
|
name: "description",
|
|
@@ -144,7 +136,6 @@ describe("row api - postgres", () => {
|
|
|
144
136
|
type: FieldType.LINK,
|
|
145
137
|
constraints: {
|
|
146
138
|
type: "array",
|
|
147
|
-
presence: false,
|
|
148
139
|
},
|
|
149
140
|
fieldName: oneToManyRelationshipInfo.fieldName,
|
|
150
141
|
name: "oneToManyRelation",
|
|
@@ -156,7 +147,6 @@ describe("row api - postgres", () => {
|
|
|
156
147
|
type: FieldType.LINK,
|
|
157
148
|
constraints: {
|
|
158
149
|
type: "array",
|
|
159
|
-
presence: false,
|
|
160
150
|
},
|
|
161
151
|
fieldName: manyToOneRelationshipInfo.fieldName,
|
|
162
152
|
name: "manyToOneRelation",
|
|
@@ -168,7 +158,6 @@ describe("row api - postgres", () => {
|
|
|
168
158
|
type: FieldType.LINK,
|
|
169
159
|
constraints: {
|
|
170
160
|
type: "array",
|
|
171
|
-
presence: false,
|
|
172
161
|
},
|
|
173
162
|
fieldName: manyToManyRelationshipInfo.fieldName,
|
|
174
163
|
name: "manyToManyRelation",
|
|
@@ -309,9 +298,6 @@ describe("row api - postgres", () => {
|
|
|
309
298
|
id: {
|
|
310
299
|
name: "id",
|
|
311
300
|
type: FieldType.AUTO,
|
|
312
|
-
constraints: {
|
|
313
|
-
presence: true,
|
|
314
|
-
},
|
|
315
301
|
},
|
|
316
302
|
},
|
|
317
303
|
sourceId: postgresDatasource._id,
|
|
@@ -921,47 +907,55 @@ describe("row api - postgres", () => {
|
|
|
921
907
|
foreignRows,
|
|
922
908
|
x => x.relationshipType
|
|
923
909
|
)
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
],
|
|
935
|
-
[
|
|
936
|
-
{
|
|
937
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
|
|
938
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
939
|
-
row.id,
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
|
|
943
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
944
|
-
row.id,
|
|
945
|
-
},
|
|
910
|
+
const m2mFieldName = manyToManyRelationshipInfo.fieldName,
|
|
911
|
+
o2mFieldName = oneToManyRelationshipInfo.fieldName,
|
|
912
|
+
m2oFieldName = manyToOneRelationshipInfo.fieldName
|
|
913
|
+
const m2mRow1 = res.body[m2mFieldName].find(
|
|
914
|
+
(row: Row) => row.id === 1
|
|
915
|
+
)
|
|
916
|
+
const m2mRow2 = res.body[m2mFieldName].find(
|
|
917
|
+
(row: Row) => row.id === 2
|
|
918
|
+
)
|
|
919
|
+
expect(m2mRow1).toEqual({
|
|
920
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
|
|
921
|
+
[m2mFieldName]: [
|
|
946
922
|
{
|
|
947
|
-
|
|
948
|
-
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
949
|
-
row.id,
|
|
923
|
+
_id: row._id,
|
|
950
924
|
},
|
|
951
925
|
],
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
926
|
+
})
|
|
927
|
+
expect(m2mRow2).toEqual({
|
|
928
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
|
|
929
|
+
[m2mFieldName]: [
|
|
956
930
|
{
|
|
957
|
-
|
|
931
|
+
_id: row._id,
|
|
958
932
|
},
|
|
959
933
|
],
|
|
960
|
-
id: row.id,
|
|
961
|
-
tableId: row.tableId,
|
|
962
|
-
_id: expect.any(String),
|
|
963
|
-
_rev: expect.any(String),
|
|
964
934
|
})
|
|
935
|
+
expect(res.body[m2oFieldName]).toEqual([
|
|
936
|
+
{
|
|
937
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
|
|
938
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
939
|
+
row.id,
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
|
|
943
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
944
|
+
row.id,
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
|
|
948
|
+
[`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
|
|
949
|
+
row.id,
|
|
950
|
+
},
|
|
951
|
+
])
|
|
952
|
+
expect(res.body[o2mFieldName]).toEqual([
|
|
953
|
+
{
|
|
954
|
+
...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
|
|
955
|
+
_id: expect.any(String),
|
|
956
|
+
_rev: expect.any(String),
|
|
957
|
+
},
|
|
958
|
+
])
|
|
965
959
|
})
|
|
966
960
|
})
|
|
967
961
|
})
|
|
@@ -245,6 +245,10 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
248
|
+
// not fully configured yet
|
|
249
|
+
if (!this.config.auth) {
|
|
250
|
+
return
|
|
251
|
+
}
|
|
248
252
|
await this.connect()
|
|
249
253
|
const sheets = this.client.sheetsByIndex
|
|
250
254
|
const tables: Record<string, Table> = {}
|
|
@@ -39,6 +39,10 @@ describe("Google Sheets Integration", () => {
|
|
|
39
39
|
config.setGoogleAuth("test")
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
+
afterAll(async () => {
|
|
43
|
+
await config.end()
|
|
44
|
+
})
|
|
45
|
+
|
|
42
46
|
beforeEach(async () => {
|
|
43
47
|
integration = new GoogleSheetsIntegration.integration({
|
|
44
48
|
spreadsheetId: "randomId",
|
|
@@ -99,8 +103,8 @@ describe("Google Sheets Integration", () => {
|
|
|
99
103
|
})
|
|
100
104
|
})
|
|
101
105
|
|
|
102
|
-
test("removing an existing field will
|
|
103
|
-
await config.doInContext(structures.uuid(), async () => {
|
|
106
|
+
test("removing an existing field will remove the header from the google sheet", async () => {
|
|
107
|
+
const sheet = await config.doInContext(structures.uuid(), async () => {
|
|
104
108
|
const tableColumns = ["name"]
|
|
105
109
|
const table = createBasicTable(structures.uuid(), tableColumns)
|
|
106
110
|
|
|
@@ -109,18 +113,14 @@ describe("Google Sheets Integration", () => {
|
|
|
109
113
|
})
|
|
110
114
|
sheetsByTitle[table.name] = sheet
|
|
111
115
|
await integration.updateTable(table)
|
|
112
|
-
|
|
113
|
-
expect(sheet.loadHeaderRow).toBeCalledTimes(1)
|
|
114
|
-
expect(sheet.setHeaderRow).toBeCalledTimes(1)
|
|
115
|
-
expect(sheet.setHeaderRow).toBeCalledWith([
|
|
116
|
-
"name",
|
|
117
|
-
"description",
|
|
118
|
-
"location",
|
|
119
|
-
])
|
|
120
|
-
|
|
121
|
-
// No undefineds are sent
|
|
122
|
-
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(3)
|
|
116
|
+
return sheet
|
|
123
117
|
})
|
|
118
|
+
expect(sheet.loadHeaderRow).toBeCalledTimes(1)
|
|
119
|
+
expect(sheet.setHeaderRow).toBeCalledTimes(1)
|
|
120
|
+
expect(sheet.setHeaderRow).toBeCalledWith(["name"])
|
|
121
|
+
|
|
122
|
+
// No undefined are sent
|
|
123
|
+
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
})
|
|
@@ -3,17 +3,17 @@ import { default as RedisIntegration } from "../redis"
|
|
|
3
3
|
|
|
4
4
|
class TestConfiguration {
|
|
5
5
|
integration: any
|
|
6
|
-
redis: any
|
|
7
6
|
|
|
8
7
|
constructor(config: any = {}) {
|
|
9
8
|
this.integration = new RedisIntegration.integration(config)
|
|
10
|
-
|
|
9
|
+
// have to kill the basic integration before replacing it
|
|
10
|
+
this.integration.client.quit()
|
|
11
|
+
this.integration.client = new Redis({
|
|
11
12
|
data: {
|
|
12
13
|
test: "test",
|
|
13
14
|
result: "1",
|
|
14
15
|
},
|
|
15
16
|
})
|
|
16
|
-
this.integration.client = this.redis
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -24,13 +24,17 @@ describe("Redis Integration", () => {
|
|
|
24
24
|
config = new TestConfiguration()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
config.integration.disconnect()
|
|
29
|
+
})
|
|
30
|
+
|
|
27
31
|
it("calls the create method with the correct params", async () => {
|
|
28
32
|
const body = {
|
|
29
33
|
key: "key",
|
|
30
34
|
value: "value",
|
|
31
35
|
}
|
|
32
36
|
await config.integration.create(body)
|
|
33
|
-
expect(await config.
|
|
37
|
+
expect(await config.integration.client.get("key")).toEqual("value")
|
|
34
38
|
})
|
|
35
39
|
|
|
36
40
|
it("calls the read method with the correct params", async () => {
|
|
@@ -46,7 +50,7 @@ describe("Redis Integration", () => {
|
|
|
46
50
|
key: "test",
|
|
47
51
|
}
|
|
48
52
|
await config.integration.delete(body)
|
|
49
|
-
expect(await config.
|
|
53
|
+
expect(await config.integration.client.get(body.key)).toEqual(null)
|
|
50
54
|
})
|
|
51
55
|
|
|
52
56
|
it("calls the pipeline method with the correct params", async () => {
|
|
@@ -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"
|
|
@@ -10,34 +9,15 @@ import { generateUserMetadataID, isDevAppID } from "../db/utils"
|
|
|
10
9
|
import { getCachedSelf } from "../utilities/global"
|
|
11
10
|
import env from "../environment"
|
|
12
11
|
import { isWebhookEndpoint } from "./utils"
|
|
13
|
-
import {
|
|
12
|
+
import { UserCtx } from "@budibase/types"
|
|
14
13
|
|
|
15
|
-
export default async (ctx:
|
|
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: BBContext, 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: BBContext, 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
|
})
|