@budibase/server 0.9.173-alpha.1 → 0.9.173-alpha.2
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.d3613b17.js → index.8a8f7849.js} +1 -1
- package/builder/index.html +1 -1
- package/coverage/clover.xml +189 -185
- package/coverage/coverage-final.json +13 -13
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +72 -72
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +15 -15
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +9 -9
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +19 -19
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/thread.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +28 -28
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +17 -17
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +49 -49
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +51 -24
- package/coverage/lcov-report/middleware/index.html +15 -15
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +27 -27
- package/coverage/lcov-report/utilities/index.html +15 -15
- package/coverage/lcov-report/utilities/index.js.html +4 -4
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +29 -8
- package/coverage/lcov-report/utilities/queue/index.html +15 -15
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +19 -19
- package/coverage/lcov.info +317 -305
- package/dist/api/routes/tests/utilities/TestFunctions.js +7 -9
- package/dist/middleware/currentapp.js +7 -1
- package/dist/package.json +4 -4
- package/dist/tests/utilities/TestConfiguration.js +34 -19
- package/dist/tests/utilities/controllers.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/queue/inMemoryQueue.js +6 -0
- package/package.json +5 -5
- package/scripts/jestSetup.js +2 -0
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/api/routes/tests/permissions.spec.js +3 -0
- package/src/api/routes/tests/query.spec.js +2 -2
- package/src/api/routes/tests/routing.spec.js +24 -8
- package/src/api/routes/tests/user.spec.js +1 -1
- package/src/api/routes/tests/utilities/TestFunctions.js +7 -9
- package/src/api/routes/tests/webhook.spec.js +4 -1
- package/src/middleware/currentapp.js +10 -1
- package/src/tests/utilities/TestConfiguration.js +47 -19
- package/src/tests/utilities/controllers.js +1 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "0.9.173-alpha.
|
|
4
|
+
"version": "0.9.173-alpha.2",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"author": "Budibase",
|
|
69
69
|
"license": "AGPL-3.0-or-later",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@budibase/auth": "^0.9.173-alpha.
|
|
72
|
-
"@budibase/client": "^0.9.173-alpha.
|
|
73
|
-
"@budibase/string-templates": "^0.9.173-alpha.
|
|
71
|
+
"@budibase/auth": "^0.9.173-alpha.2",
|
|
72
|
+
"@budibase/client": "^0.9.173-alpha.2",
|
|
73
|
+
"@budibase/string-templates": "^0.9.173-alpha.2",
|
|
74
74
|
"@elastic/elasticsearch": "7.10.0",
|
|
75
75
|
"@koa/router": "8.0.0",
|
|
76
76
|
"@sendgrid/mail": "7.1.1",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"typescript": "^4.3.5",
|
|
150
150
|
"update-dotenv": "^1.1.1"
|
|
151
151
|
},
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "4aaffe23c00d8166d63067d6e46f9204701542b3"
|
|
153
153
|
}
|
package/scripts/jestSetup.js
CHANGED
|
@@ -13,8 +13,7 @@ describe("/authenticate", () => {
|
|
|
13
13
|
|
|
14
14
|
describe("fetch self", () => {
|
|
15
15
|
it("should be able to fetch self", async () => {
|
|
16
|
-
await config.
|
|
17
|
-
const headers = await config.login("test@test.com", "p4ssw0rd", { userId: "us_uuid1" })
|
|
16
|
+
const headers = await config.login()
|
|
18
17
|
const res = await request
|
|
19
18
|
.get(`/api/self`)
|
|
20
19
|
.set(headers)
|
|
@@ -89,6 +89,9 @@ describe("/permission", () => {
|
|
|
89
89
|
|
|
90
90
|
describe("check public user allowed", () => {
|
|
91
91
|
it("should be able to read the row", async () => {
|
|
92
|
+
// replicate changes before checking permissions
|
|
93
|
+
await config.deploy()
|
|
94
|
+
|
|
92
95
|
const res = await request
|
|
93
96
|
.get(`/api/${table._id}/rows`)
|
|
94
97
|
.set(config.publicHeaders())
|
|
@@ -94,9 +94,9 @@ describe("/queries", () => {
|
|
|
94
94
|
const query = await config.createQuery()
|
|
95
95
|
const res = await request
|
|
96
96
|
.get(`/api/queries/${query._id}`)
|
|
97
|
-
.set(await config.
|
|
98
|
-
.expect("Content-Type", /json/)
|
|
97
|
+
.set(await config.defaultHeaders())
|
|
99
98
|
.expect(200)
|
|
99
|
+
.expect("Content-Type", /json/)
|
|
100
100
|
expect(res.body.fields).toBeUndefined()
|
|
101
101
|
expect(res.body.parameters).toBeUndefined()
|
|
102
102
|
expect(res.body.schema).toBeUndefined()
|
|
@@ -21,16 +21,31 @@ describe("/routing", () => {
|
|
|
21
21
|
screen2.routing.roleId = BUILTIN_ROLE_IDS.POWER
|
|
22
22
|
screen2.routing.route = route
|
|
23
23
|
screen2 = await config.createScreen(screen2)
|
|
24
|
+
await config.deploy()
|
|
24
25
|
})
|
|
25
26
|
|
|
26
27
|
describe("fetch", () => {
|
|
28
|
+
it("prevents a public user from accessing development app", async () => {
|
|
29
|
+
await request
|
|
30
|
+
.get(`/api/routing/client`)
|
|
31
|
+
.set(config.publicHeaders({ prodApp: false }))
|
|
32
|
+
.expect(302)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it("prevents a non builder from accessing development app", async () => {
|
|
36
|
+
await request
|
|
37
|
+
.get(`/api/routing/client`)
|
|
38
|
+
.set(await config.roleHeaders({
|
|
39
|
+
roleId: BUILTIN_ROLE_IDS.BASIC,
|
|
40
|
+
prodApp: false
|
|
41
|
+
}))
|
|
42
|
+
.expect(302)
|
|
43
|
+
})
|
|
27
44
|
it("returns the correct routing for basic user", async () => {
|
|
28
45
|
const res = await request
|
|
29
46
|
.get(`/api/routing/client`)
|
|
30
47
|
.set(await config.roleHeaders({
|
|
31
|
-
|
|
32
|
-
roleId: BUILTIN_ROLE_IDS.BASIC,
|
|
33
|
-
builder: false
|
|
48
|
+
roleId: BUILTIN_ROLE_IDS.BASIC
|
|
34
49
|
}))
|
|
35
50
|
.expect("Content-Type", /json/)
|
|
36
51
|
.expect(200)
|
|
@@ -49,9 +64,7 @@ describe("/routing", () => {
|
|
|
49
64
|
const res = await request
|
|
50
65
|
.get(`/api/routing/client`)
|
|
51
66
|
.set(await config.roleHeaders({
|
|
52
|
-
|
|
53
|
-
roleId: BUILTIN_ROLE_IDS.POWER,
|
|
54
|
-
builder: false,
|
|
67
|
+
roleId: BUILTIN_ROLE_IDS.POWER
|
|
55
68
|
}))
|
|
56
69
|
.expect("Content-Type", /json/)
|
|
57
70
|
.expect(200)
|
|
@@ -71,9 +84,12 @@ describe("/routing", () => {
|
|
|
71
84
|
it("should fetch all routes for builder", async () => {
|
|
72
85
|
const res = await request
|
|
73
86
|
.get(`/api/routing`)
|
|
74
|
-
.set(config.
|
|
75
|
-
|
|
87
|
+
.set(await config.roleHeaders({
|
|
88
|
+
roleId: BUILTIN_ROLE_IDS.POWER,
|
|
89
|
+
builder: true,
|
|
90
|
+
}))
|
|
76
91
|
.expect(200)
|
|
92
|
+
.expect("Content-Type", /json/)
|
|
77
93
|
expect(res.body.routes).toBeDefined()
|
|
78
94
|
expect(res.body.routes[route].subpaths[route]).toBeDefined()
|
|
79
95
|
const subpath = res.body.routes[route].subpaths[route]
|
|
@@ -50,9 +50,10 @@ exports.createRequest = (request, method, url, body) => {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
exports.checkBuilderEndpoint = async ({ config, method, url, body }) => {
|
|
53
|
-
const headers = await config.login(
|
|
53
|
+
const headers = await config.login({
|
|
54
54
|
userId: "us_fail",
|
|
55
55
|
builder: false,
|
|
56
|
+
prodApp: true,
|
|
56
57
|
})
|
|
57
58
|
await exports
|
|
58
59
|
.createRequest(config.request, method, url, body)
|
|
@@ -68,11 +69,9 @@ exports.checkPermissionsEndpoint = async ({
|
|
|
68
69
|
passRole,
|
|
69
70
|
failRole,
|
|
70
71
|
}) => {
|
|
71
|
-
const
|
|
72
|
-
let user = await config.createUser("pass@budibase.com", password, passRole)
|
|
73
|
-
const passHeader = await config.login("pass@budibase.com", password, {
|
|
72
|
+
const passHeader = await config.login({
|
|
74
73
|
roleId: passRole,
|
|
75
|
-
|
|
74
|
+
prodApp: true,
|
|
76
75
|
})
|
|
77
76
|
|
|
78
77
|
await exports
|
|
@@ -82,13 +81,12 @@ exports.checkPermissionsEndpoint = async ({
|
|
|
82
81
|
|
|
83
82
|
let failHeader
|
|
84
83
|
if (failRole === BUILTIN_ROLE_IDS.PUBLIC) {
|
|
85
|
-
failHeader = config.publicHeaders()
|
|
84
|
+
failHeader = config.publicHeaders({ prodApp: true })
|
|
86
85
|
} else {
|
|
87
|
-
|
|
88
|
-
failHeader = await config.login("fail@budibase.com", password, {
|
|
86
|
+
failHeader = await config.login({
|
|
89
87
|
roleId: failRole,
|
|
90
|
-
userId: user.globalId,
|
|
91
88
|
builder: false,
|
|
89
|
+
prodApp: true,
|
|
92
90
|
})
|
|
93
91
|
}
|
|
94
92
|
|
|
@@ -112,8 +112,11 @@ describe("/webhooks", () => {
|
|
|
112
112
|
|
|
113
113
|
describe("trigger", () => {
|
|
114
114
|
it("should allow triggering from public", async () => {
|
|
115
|
+
// replicate changes before checking webhook
|
|
116
|
+
await config.deploy()
|
|
117
|
+
|
|
115
118
|
const res = await request
|
|
116
|
-
.post(`/api/webhooks/trigger/${config.
|
|
119
|
+
.post(`/api/webhooks/trigger/${config.prodAppId}/${webhook._id}`)
|
|
117
120
|
.expect("Content-Type", /json/)
|
|
118
121
|
.expect(200)
|
|
119
122
|
expect(res.body.message).toBeDefined()
|
|
@@ -3,7 +3,7 @@ const { getAppId, setCookie, getCookie, clearCookie } =
|
|
|
3
3
|
const { Cookies } = require("@budibase/auth").constants
|
|
4
4
|
const { getRole } = require("@budibase/auth/roles")
|
|
5
5
|
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
|
|
6
|
-
const { generateUserMetadataID } = require("../db/utils")
|
|
6
|
+
const { generateUserMetadataID, isDevAppID } = require("../db/utils")
|
|
7
7
|
const { dbExists } = require("@budibase/auth/db")
|
|
8
8
|
const { isUserInAppTenant } = require("@budibase/auth/tenancy")
|
|
9
9
|
const { getCachedSelf } = require("../utilities/global")
|
|
@@ -35,6 +35,15 @@ module.exports = async (ctx, next) => {
|
|
|
35
35
|
requestAppId = requestAppId || appId
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// deny access to application preview
|
|
39
|
+
if (
|
|
40
|
+
isDevAppID(requestAppId) &&
|
|
41
|
+
(!ctx.user || !ctx.user.builder || !ctx.user.builder.global)
|
|
42
|
+
) {
|
|
43
|
+
clearCookie(ctx, Cookies.CurrentApp)
|
|
44
|
+
return ctx.redirect("/")
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
let appId,
|
|
39
48
|
roleId = BUILTIN_ROLE_IDS.PUBLIC
|
|
40
49
|
if (!ctx.user) {
|
|
@@ -26,7 +26,6 @@ auth.init(CouchDB)
|
|
|
26
26
|
|
|
27
27
|
const GLOBAL_USER_ID = "us_uuid1"
|
|
28
28
|
const EMAIL = "babs@babs.com"
|
|
29
|
-
const PASSWORD = "babs_password"
|
|
30
29
|
|
|
31
30
|
class TestConfiguration {
|
|
32
31
|
constructor(openServer = true) {
|
|
@@ -67,13 +66,18 @@ class TestConfiguration {
|
|
|
67
66
|
return request.body
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
async globalUser(
|
|
69
|
+
async globalUser({
|
|
70
|
+
id = GLOBAL_USER_ID,
|
|
71
|
+
builder = true,
|
|
72
|
+
email = EMAIL,
|
|
73
|
+
roles,
|
|
74
|
+
} = {}) {
|
|
71
75
|
const db = getGlobalDB(TENANT_ID)
|
|
72
76
|
let existing
|
|
73
77
|
try {
|
|
74
78
|
existing = await db.get(id)
|
|
75
79
|
} catch (err) {
|
|
76
|
-
existing = {}
|
|
80
|
+
existing = { email }
|
|
77
81
|
}
|
|
78
82
|
const user = {
|
|
79
83
|
_id: id,
|
|
@@ -84,6 +88,8 @@ class TestConfiguration {
|
|
|
84
88
|
await createASession(id, { sessionId: "sessionid", tenantId: TENANT_ID })
|
|
85
89
|
if (builder) {
|
|
86
90
|
user.builder = { global: true }
|
|
91
|
+
} else {
|
|
92
|
+
user.builder = { global: false }
|
|
87
93
|
}
|
|
88
94
|
const resp = await db.put(user)
|
|
89
95
|
return {
|
|
@@ -132,12 +138,14 @@ class TestConfiguration {
|
|
|
132
138
|
return headers
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
publicHeaders() {
|
|
141
|
+
publicHeaders({ prodApp = true } = {}) {
|
|
142
|
+
const appId = prodApp ? this.prodAppId : this.appId
|
|
143
|
+
|
|
136
144
|
const headers = {
|
|
137
145
|
Accept: "application/json",
|
|
138
146
|
}
|
|
139
|
-
if (
|
|
140
|
-
headers[Headers.APP_ID] =
|
|
147
|
+
if (appId) {
|
|
148
|
+
headers[Headers.APP_ID] = appId
|
|
141
149
|
}
|
|
142
150
|
return headers
|
|
143
151
|
}
|
|
@@ -146,17 +154,37 @@ class TestConfiguration {
|
|
|
146
154
|
email = EMAIL,
|
|
147
155
|
roleId = BUILTIN_ROLE_IDS.ADMIN,
|
|
148
156
|
builder = false,
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
prodApp = true,
|
|
158
|
+
} = {}) {
|
|
159
|
+
return this.login({ email, roleId, builder, prodApp })
|
|
151
160
|
}
|
|
152
161
|
|
|
153
162
|
async createApp(appName) {
|
|
163
|
+
// create dev app
|
|
154
164
|
this.app = await this._req({ name: appName }, null, controllers.app.create)
|
|
155
165
|
this.appId = this.app.appId
|
|
166
|
+
|
|
167
|
+
// create production app
|
|
168
|
+
this.prodApp = await this.deploy()
|
|
169
|
+
this.prodAppId = this.prodApp.appId
|
|
170
|
+
|
|
171
|
+
this.allApps.push(this.prodApp)
|
|
156
172
|
this.allApps.push(this.app)
|
|
173
|
+
|
|
157
174
|
return this.app
|
|
158
175
|
}
|
|
159
176
|
|
|
177
|
+
async deploy() {
|
|
178
|
+
const deployment = await this._req(null, null, controllers.deploy.deployApp)
|
|
179
|
+
const prodAppId = deployment.appId.replace("_dev", "")
|
|
180
|
+
const appPackage = await this._req(
|
|
181
|
+
null,
|
|
182
|
+
{ appId: prodAppId },
|
|
183
|
+
controllers.app.fetchAppPackage
|
|
184
|
+
)
|
|
185
|
+
return appPackage.application
|
|
186
|
+
}
|
|
187
|
+
|
|
160
188
|
async updateTable(config = null) {
|
|
161
189
|
config = config || basicTable()
|
|
162
190
|
this.table = await this._req(config, null, controllers.table.save)
|
|
@@ -313,9 +341,9 @@ class TestConfiguration {
|
|
|
313
341
|
return await this._req(config, null, controllers.layout.save)
|
|
314
342
|
}
|
|
315
343
|
|
|
316
|
-
async createUser(id = null) {
|
|
344
|
+
async createUser(id = null, email = EMAIL) {
|
|
317
345
|
const globalId = !id ? `us_${Math.random()}` : `us_${id}`
|
|
318
|
-
const resp = await this.globalUser(globalId)
|
|
346
|
+
const resp = await this.globalUser({ id: globalId, email })
|
|
319
347
|
await userCache.invalidateUser(globalId)
|
|
320
348
|
return {
|
|
321
349
|
...resp,
|
|
@@ -323,21 +351,21 @@ class TestConfiguration {
|
|
|
323
351
|
}
|
|
324
352
|
}
|
|
325
353
|
|
|
326
|
-
async login(
|
|
354
|
+
async login({ roleId, userId, builder, prodApp = false } = {}) {
|
|
355
|
+
const appId = prodApp ? this.prodAppId : this.appId
|
|
356
|
+
|
|
327
357
|
userId = !userId ? `us_uuid1` : userId
|
|
328
358
|
if (!this.request) {
|
|
329
359
|
throw "Server has not been opened, cannot login."
|
|
330
360
|
}
|
|
331
361
|
// make sure the user exists in the global DB
|
|
332
362
|
if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
363
|
+
await this.globalUser({
|
|
364
|
+
userId,
|
|
365
|
+
builder,
|
|
366
|
+
roles: { [this.prodAppId]: roleId },
|
|
336
367
|
})
|
|
337
368
|
}
|
|
338
|
-
if (!email || !password) {
|
|
339
|
-
await this.createUser()
|
|
340
|
-
}
|
|
341
369
|
await createASession(userId, {
|
|
342
370
|
sessionId: "sessionid",
|
|
343
371
|
tenantId: TENANT_ID,
|
|
@@ -350,7 +378,7 @@ class TestConfiguration {
|
|
|
350
378
|
}
|
|
351
379
|
const app = {
|
|
352
380
|
roleId: roleId,
|
|
353
|
-
appId
|
|
381
|
+
appId,
|
|
354
382
|
}
|
|
355
383
|
const authToken = jwt.sign(auth, env.JWT_SECRET)
|
|
356
384
|
const appToken = jwt.sign(app, env.JWT_SECRET)
|
|
@@ -363,7 +391,7 @@ class TestConfiguration {
|
|
|
363
391
|
`${Cookies.Auth}=${authToken}`,
|
|
364
392
|
`${Cookies.CurrentApp}=${appToken}`,
|
|
365
393
|
],
|
|
366
|
-
[Headers.APP_ID]:
|
|
394
|
+
[Headers.APP_ID]: appId,
|
|
367
395
|
}
|
|
368
396
|
}
|
|
369
397
|
}
|