@budibase/worker 2.1.39 → 2.1.40-alpha.1
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__/aws-sdk.ts +15 -0
- package/__mocks__/oauth.ts +57 -0
- package/coverage/clover.xml +2153 -0
- package/coverage/coverage-final.json +78 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +431 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +925 -0
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1405 -0
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +236 -0
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +796 -0
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +583 -0
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +236 -0
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +409 -0
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/index.html +116 -0
- package/coverage/lcov-report/src/api/routes/index.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
- package/coverage/lcov-report/src/constants/index.html +116 -0
- package/coverage/lcov-report/src/constants/index.ts.html +613 -0
- package/coverage/lcov-report/src/constants/templates/index.html +116 -0
- package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
- package/coverage/lcov-report/src/db/index.html +116 -0
- package/coverage/lcov-report/src/db/index.ts.html +115 -0
- package/coverage/lcov-report/src/environment.ts.html +373 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/index.ts.html +394 -0
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
- package/coverage/lcov-report/src/middleware/index.html +116 -0
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
- package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
- package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/index.html +116 -0
- package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
- package/coverage/lcov-report/src/sdk/users/events.ts.html +577 -0
- package/coverage/lcov-report/src/sdk/users/index.html +146 -0
- package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1903 -0
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1051 -0
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
- package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
- package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
- package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
- package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
- package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/index.html +296 -0
- package/coverage/lcov-report/src/tests/api/index.ts.html +205 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
- package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/users.ts.html +511 -0
- package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
- package/coverage/lcov-report/src/tests/index.html +146 -0
- package/coverage/lcov-report/src/tests/index.ts.html +139 -0
- package/coverage/lcov-report/src/tests/mocks/email.js.html +115 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
- package/coverage/lcov-report/src/tests/structures/index.html +161 -0
- package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
- package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
- package/coverage/lcov-report/src/utilities/appService.ts.html +181 -0
- package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
- package/coverage/lcov-report/src/utilities/index.html +206 -0
- package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
- package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
- package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
- package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
- package/coverage/lcov.info +3958 -0
- package/jest.config.ts +29 -0
- package/package.json +14 -24
- package/scripts/localdomain.js +33 -7
- package/src/api/controllers/global/auth.ts +51 -43
- package/src/api/controllers/global/{configs.js → configs.ts} +119 -114
- package/src/api/controllers/global/{email.js → email.ts} +6 -5
- package/src/api/controllers/global/roles.ts +66 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +4 -2
- package/src/api/controllers/global/{workspaces.js → workspaces.ts} +15 -18
- package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.js → status.ts} +4 -3
- package/src/api/controllers/system/tenants.ts +8 -51
- package/src/api/index.ts +31 -8
- package/src/api/routes/global/{auth.js → auth.ts} +31 -48
- package/src/api/routes/global/{configs.js → configs.ts} +22 -23
- package/src/api/routes/global/{email.js → email.ts} +9 -10
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.ts +16 -0
- package/src/api/routes/global/self.ts +2 -2
- package/src/api/routes/global/templates.ts +4 -4
- package/src/api/routes/global/tests/auth.spec.ts +134 -64
- package/src/api/routes/global/tests/configs.spec.ts +34 -35
- package/src/api/routes/global/tests/email.spec.ts +4 -3
- package/src/api/routes/global/tests/license.spec.ts +31 -0
- package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
- package/src/api/routes/global/tests/roles.spec.ts +27 -0
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/templates.spec.ts +35 -0
- package/src/api/routes/global/tests/users.spec.ts +51 -43
- package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
- package/src/api/routes/global/{users.js → users.ts} +26 -24
- package/src/api/routes/global/{workspaces.js → workspaces.ts} +9 -10
- package/src/api/routes/index.ts +2 -1
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.ts +8 -0
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.ts +8 -0
- package/src/api/routes/system/tenants.ts +13 -0
- package/src/api/routes/system/tests/accounts.spec.ts +5 -6
- package/src/api/routes/system/tests/environment.spec.ts +29 -0
- package/src/api/routes/system/tests/migrations.spec.ts +63 -0
- package/src/api/routes/system/tests/restore.spec.ts +36 -0
- package/src/api/routes/system/tests/status.spec.ts +48 -0
- package/src/api/routes/system/tests/tenants.spec.ts +61 -0
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.js → index.ts} +57 -64
- package/src/constants/templates/{index.js → index.ts} +23 -19
- package/src/db/index.ts +10 -0
- package/src/environment.ts +8 -6
- package/src/index.ts +15 -16
- package/src/middleware/{cloudRestricted.js → cloudRestricted.ts} +5 -4
- package/src/middleware/tests/tenancy.spec.ts +73 -0
- package/src/tests/TestConfiguration.ts +99 -50
- package/src/tests/api/accounts.ts +5 -8
- package/src/tests/api/auth.ts +3 -6
- package/src/tests/api/base.ts +16 -0
- package/src/tests/api/configs.ts +15 -8
- package/src/tests/api/email.ts +3 -6
- package/src/tests/api/environment.ts +15 -0
- package/src/tests/api/index.ts +15 -0
- package/src/tests/api/migrations.ts +22 -0
- package/src/tests/api/restore.ts +14 -0
- package/src/tests/api/self.ts +11 -6
- package/src/tests/api/status.ts +12 -0
- package/src/tests/api/tenants.ts +15 -0
- package/src/tests/api/users.ts +38 -6
- package/src/tests/controllers.ts +5 -0
- package/src/tests/index.ts +5 -1
- package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
- package/src/tests/structures/{configs.js → configs.ts} +11 -11
- package/src/tests/structures/index.ts +5 -3
- package/src/tests/structures/users.ts +1 -0
- package/src/utilities/appService.ts +32 -0
- package/src/utilities/{email.js → email.ts} +78 -45
- package/src/utilities/fileSystem.ts +5 -0
- package/src/utilities/{index.js → index.ts} +1 -1
- package/src/utilities/{redis.js → redis.ts} +29 -24
- package/src/utilities/templates.ts +49 -0
- package/src/utilities/users.ts +16 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.json +3 -1
- package/src/api/controllers/global/roles.js +0 -68
- package/src/api/routes/global/roles.js +0 -12
- package/src/api/routes/system/environment.js +0 -8
- package/src/api/routes/system/status.js +0 -8
- package/src/api/routes/system/tenants.js +0 -12
- package/src/db/index.js +0 -11
- package/src/tests/controllers.js +0 -7
- package/src/tests/structures/accounts.ts +0 -24
- package/src/utilities/appService.js +0 -33
- package/src/utilities/fileSystem.js +0 -5
- package/src/utilities/templates.js +0 -49
- package/src/utilities/users.js +0 -17
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, mocks
|
|
2
|
+
import { TestConfiguration, mocks } from "../../../../tests"
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
4
|
import { events } from "@budibase/backend-core"
|
|
5
5
|
|
|
6
|
+
const expectSetAuthCookie = (res: any) => {
|
|
7
|
+
expect(
|
|
8
|
+
res.get("Set-Cookie").find((c: string) => c.startsWith("budibase:auth"))
|
|
9
|
+
).toBeDefined()
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
describe("/api/global/auth", () => {
|
|
7
13
|
const config = new TestConfiguration()
|
|
8
|
-
const api = new API(config)
|
|
9
14
|
|
|
10
15
|
beforeAll(async () => {
|
|
11
16
|
await config.beforeAll()
|
|
@@ -19,90 +24,155 @@ describe("/api/global/auth", () => {
|
|
|
19
24
|
jest.clearAllMocks()
|
|
20
25
|
})
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
describe("password", () => {
|
|
28
|
+
describe("POST /api/global/auth/:tenantId/login", () => {
|
|
29
|
+
it("should login", () => {})
|
|
30
|
+
})
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
describe("POST /api/global/auth/logout", () => {
|
|
33
|
+
it("should logout", async () => {
|
|
34
|
+
await config.api.auth.logout()
|
|
35
|
+
expect(events.auth.logout).toBeCalledTimes(1)
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
// TODO: Verify sessions deleted
|
|
38
|
+
})
|
|
33
39
|
})
|
|
34
|
-
expect(sendMailMock).toHaveBeenCalled()
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
describe("POST /api/global/auth/:tenantId/reset", () => {
|
|
42
|
+
it("should generate password reset email", async () => {
|
|
43
|
+
const { res, code } = await config.api.auth.requestPasswordReset(
|
|
44
|
+
sendMailMock
|
|
45
|
+
)
|
|
46
|
+
const user = await config.getUser("test@test.com")
|
|
47
|
+
|
|
48
|
+
expect(res.body).toEqual({
|
|
49
|
+
message: "Please check your email for a reset link.",
|
|
50
|
+
})
|
|
51
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
52
|
+
|
|
53
|
+
expect(code).toBeDefined()
|
|
54
|
+
expect(events.user.passwordResetRequested).toBeCalledTimes(1)
|
|
55
|
+
expect(events.user.passwordResetRequested).toBeCalledWith(user)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe("POST /api/global/auth/:tenantId/reset/update", () => {
|
|
60
|
+
it("should reset password", async () => {
|
|
61
|
+
const { code } = await config.api.auth.requestPasswordReset(
|
|
62
|
+
sendMailMock
|
|
63
|
+
)
|
|
64
|
+
const user = await config.getUser("test@test.com")
|
|
65
|
+
delete user.password
|
|
66
|
+
|
|
67
|
+
const res = await config.api.auth.updatePassword(code)
|
|
68
|
+
|
|
69
|
+
expect(res.body).toEqual({ message: "password reset successfully." })
|
|
70
|
+
expect(events.user.passwordReset).toBeCalledTimes(1)
|
|
71
|
+
expect(events.user.passwordReset).toBeCalledWith(user)
|
|
72
|
+
|
|
73
|
+
// TODO: Login using new password
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe("init", () => {
|
|
79
|
+
describe("POST /api/global/auth/init", () => {})
|
|
80
|
+
|
|
81
|
+
describe("GET /api/global/auth/init", () => {})
|
|
39
82
|
})
|
|
40
83
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
84
|
+
describe("datasource", () => {
|
|
85
|
+
// MULTI TENANT
|
|
86
|
+
|
|
87
|
+
describe("GET /api/global/auth/:tenantId/datasource/:provider", () => {})
|
|
88
|
+
|
|
89
|
+
describe("GET /api/global/auth/:tenantId/datasource/:provider/callback", () => {})
|
|
45
90
|
|
|
46
|
-
|
|
91
|
+
// SINGLE TENANT
|
|
47
92
|
|
|
48
|
-
|
|
49
|
-
expect(events.user.passwordReset).toBeCalledTimes(1)
|
|
50
|
-
expect(events.user.passwordReset).toBeCalledWith(user)
|
|
93
|
+
describe("GET /api/global/auth/datasource/:provider/callback", () => {})
|
|
51
94
|
})
|
|
52
95
|
|
|
53
|
-
describe("
|
|
54
|
-
|
|
96
|
+
describe("google", () => {
|
|
97
|
+
// MULTI TENANT
|
|
98
|
+
|
|
99
|
+
describe("GET /api/global/auth/:tenantId/google", () => {})
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
let oidcConf
|
|
58
|
-
let chosenConfig: any
|
|
59
|
-
let configId: string
|
|
101
|
+
describe("GET /api/global/auth/:tenantId/google/callback", () => {})
|
|
60
102
|
|
|
61
|
-
//
|
|
62
|
-
let strategyFactory = jest.fn()
|
|
63
|
-
let mockStrategyReturn = jest.fn()
|
|
64
|
-
let mockStrategyConfig = jest.fn()
|
|
65
|
-
auth.oidc.fetchStrategyConfig = mockStrategyConfig
|
|
103
|
+
// SINGLE TENANT
|
|
66
104
|
|
|
67
|
-
|
|
68
|
-
auth.oidc.strategyFactory = strategyFactory
|
|
105
|
+
describe("GET /api/global/auth/google/callback", () => {})
|
|
69
106
|
|
|
107
|
+
describe("GET /api/admin/auth/google/callback", () => {})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe("oidc", () => {
|
|
70
111
|
beforeEach(async () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
configId = chosenConfig.uuid
|
|
74
|
-
mockStrategyConfig.mockReturnValue(chosenConfig)
|
|
75
|
-
})
|
|
112
|
+
jest.clearAllMocks()
|
|
113
|
+
mockGetWellKnownConfig()
|
|
76
114
|
|
|
77
|
-
|
|
78
|
-
|
|
115
|
+
// see: __mocks__/oauth
|
|
116
|
+
// for associated mocking inside passport
|
|
79
117
|
})
|
|
80
118
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
119
|
+
const generateOidcConfig = async () => {
|
|
120
|
+
const oidcConf = await config.saveOIDCConfig()
|
|
121
|
+
const chosenConfig = oidcConf.config.configs[0]
|
|
122
|
+
return chosenConfig.uuid
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const mockGetWellKnownConfig = () => {
|
|
126
|
+
mocks.fetch.mockReturnValue({
|
|
127
|
+
ok: true,
|
|
128
|
+
json: () => ({
|
|
129
|
+
issuer: "test",
|
|
130
|
+
authorization_endpoint: "http://localhost/auth",
|
|
131
|
+
token_endpoint: "http://localhost/token",
|
|
132
|
+
userinfo_endpoint: "http://localhost/userinfo",
|
|
133
|
+
}),
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// MULTI TENANT
|
|
138
|
+
describe("GET /api/global/auth/:tenantId/oidc/configs/:configId", () => {
|
|
139
|
+
it("redirects to auth provider", async () => {
|
|
140
|
+
const configId = await generateOidcConfig()
|
|
141
|
+
|
|
142
|
+
const res = await config.api.configs.getOIDCConfig(configId)
|
|
143
|
+
|
|
144
|
+
expect(res.status).toBe(302)
|
|
145
|
+
const location: string = res.get("location")
|
|
146
|
+
expect(
|
|
147
|
+
location.startsWith(
|
|
148
|
+
"http://localhost/auth?response_type=code&client_id=clientId&redirect_uri=http%3A%2F%2Flocalhost%3A10000%2Fapi%2Fglobal%2Fauth%2Fdefault%2Foidc%2Fcallback&scope=openid%20profile%20email%20offline_access"
|
|
149
|
+
)
|
|
150
|
+
).toBe(true)
|
|
89
151
|
})
|
|
90
152
|
})
|
|
91
153
|
|
|
92
|
-
describe("oidc
|
|
93
|
-
it("
|
|
94
|
-
await
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
154
|
+
describe("GET /api/global/auth/:tenantId/oidc/callback", () => {
|
|
155
|
+
it("logs in", async () => {
|
|
156
|
+
const configId = await generateOidcConfig()
|
|
157
|
+
const preAuthRes = await config.api.configs.getOIDCConfig(configId)
|
|
158
|
+
|
|
159
|
+
const res = await config.api.configs.OIDCCallback(configId, preAuthRes)
|
|
160
|
+
|
|
161
|
+
expect(events.auth.login).toBeCalledWith("oidc")
|
|
162
|
+
expect(events.auth.login).toBeCalledTimes(1)
|
|
163
|
+
expect(res.status).toBe(302)
|
|
164
|
+
const location: string = res.get("location")
|
|
165
|
+
expect(location).toBe("/")
|
|
166
|
+
expectSetAuthCookie(res)
|
|
105
167
|
})
|
|
106
168
|
})
|
|
169
|
+
|
|
170
|
+
// SINGLE TENANT
|
|
171
|
+
|
|
172
|
+
describe("GET /api/global/auth/oidc/callback", () => {})
|
|
173
|
+
|
|
174
|
+
describe("GET /api/global/auth/oidc/callback", () => {})
|
|
175
|
+
|
|
176
|
+
describe("GET /api/admin/auth/oidc/callback", () => {})
|
|
107
177
|
})
|
|
108
178
|
})
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// mock the email system
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
|
-
import { TestConfiguration, structures, mocks
|
|
3
|
+
import { TestConfiguration, structures, mocks } from "../../../../tests"
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
import {
|
|
5
|
+
import { Config, events } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
describe("configs", () => {
|
|
8
8
|
const config = new TestConfiguration()
|
|
9
|
-
const api = new API(config)
|
|
10
9
|
|
|
11
10
|
beforeAll(async () => {
|
|
12
11
|
await config.beforeAll()
|
|
@@ -28,7 +27,7 @@ describe("configs", () => {
|
|
|
28
27
|
_rev,
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
const res = await api.configs.saveConfig(data)
|
|
30
|
+
const res = await config.api.configs.saveConfig(data)
|
|
32
31
|
|
|
33
32
|
return {
|
|
34
33
|
...data,
|
|
@@ -50,20 +49,20 @@ describe("configs", () => {
|
|
|
50
49
|
it("should create activated google config", async () => {
|
|
51
50
|
await saveGoogleConfig()
|
|
52
51
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
53
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
52
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
|
|
54
53
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
55
54
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
56
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
57
|
-
await config.deleteConfig(
|
|
55
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
|
|
56
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
58
57
|
})
|
|
59
58
|
|
|
60
59
|
it("should create deactivated google config", async () => {
|
|
61
60
|
await saveGoogleConfig({ activated: false })
|
|
62
61
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
63
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
62
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
|
|
64
63
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
65
64
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
66
|
-
await config.deleteConfig(
|
|
65
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
67
66
|
})
|
|
68
67
|
})
|
|
69
68
|
|
|
@@ -77,11 +76,11 @@ describe("configs", () => {
|
|
|
77
76
|
googleConf._rev
|
|
78
77
|
)
|
|
79
78
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
80
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
79
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
|
|
81
80
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
82
81
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
83
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
84
|
-
await config.deleteConfig(
|
|
82
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.GOOGLE)
|
|
83
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
85
84
|
})
|
|
86
85
|
|
|
87
86
|
it("should update google config to activated", async () => {
|
|
@@ -93,11 +92,11 @@ describe("configs", () => {
|
|
|
93
92
|
googleConf._rev
|
|
94
93
|
)
|
|
95
94
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
96
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
95
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
|
|
97
96
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
98
97
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
99
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
100
|
-
await config.deleteConfig(
|
|
98
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
|
|
99
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
101
100
|
})
|
|
102
101
|
})
|
|
103
102
|
})
|
|
@@ -116,20 +115,20 @@ describe("configs", () => {
|
|
|
116
115
|
it("should create activated OIDC config", async () => {
|
|
117
116
|
await saveOIDCConfig()
|
|
118
117
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
119
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
118
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
120
119
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
121
120
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
122
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
123
|
-
await config.deleteConfig(
|
|
121
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
122
|
+
await config.deleteConfig(Config.OIDC)
|
|
124
123
|
})
|
|
125
124
|
|
|
126
125
|
it("should create deactivated OIDC config", async () => {
|
|
127
126
|
await saveOIDCConfig({ activated: false })
|
|
128
127
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
129
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
128
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
130
129
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
131
130
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
132
|
-
await config.deleteConfig(
|
|
131
|
+
await config.deleteConfig(Config.OIDC)
|
|
133
132
|
})
|
|
134
133
|
})
|
|
135
134
|
|
|
@@ -143,11 +142,11 @@ describe("configs", () => {
|
|
|
143
142
|
oidcConf._rev
|
|
144
143
|
)
|
|
145
144
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
146
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
145
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
147
146
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
148
147
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
149
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
150
|
-
await config.deleteConfig(
|
|
148
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
|
|
149
|
+
await config.deleteConfig(Config.OIDC)
|
|
151
150
|
})
|
|
152
151
|
|
|
153
152
|
it("should update OIDC config to activated", async () => {
|
|
@@ -159,11 +158,11 @@ describe("configs", () => {
|
|
|
159
158
|
oidcConf._rev
|
|
160
159
|
)
|
|
161
160
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
162
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
161
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
163
162
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
164
163
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
165
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
166
|
-
await config.deleteConfig(
|
|
164
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
165
|
+
await config.deleteConfig(Config.OIDC)
|
|
167
166
|
})
|
|
168
167
|
})
|
|
169
168
|
})
|
|
@@ -180,11 +179,11 @@ describe("configs", () => {
|
|
|
180
179
|
|
|
181
180
|
describe("create", () => {
|
|
182
181
|
it("should create SMTP config", async () => {
|
|
183
|
-
await config.deleteConfig(
|
|
182
|
+
await config.deleteConfig(Config.SMTP)
|
|
184
183
|
await saveSMTPConfig()
|
|
185
184
|
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
186
185
|
expect(events.email.SMTPCreated).toBeCalledTimes(1)
|
|
187
|
-
await config.deleteConfig(
|
|
186
|
+
await config.deleteConfig(Config.SMTP)
|
|
188
187
|
})
|
|
189
188
|
})
|
|
190
189
|
|
|
@@ -195,7 +194,7 @@ describe("configs", () => {
|
|
|
195
194
|
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
196
195
|
expect(events.email.SMTPCreated).not.toBeCalled()
|
|
197
196
|
expect(events.email.SMTPUpdated).toBeCalledTimes(1)
|
|
198
|
-
await config.deleteConfig(
|
|
197
|
+
await config.deleteConfig(Config.SMTP)
|
|
199
198
|
})
|
|
200
199
|
})
|
|
201
200
|
})
|
|
@@ -212,7 +211,7 @@ describe("configs", () => {
|
|
|
212
211
|
|
|
213
212
|
describe("create", () => {
|
|
214
213
|
it("should create settings config with default settings", async () => {
|
|
215
|
-
await config.deleteConfig(
|
|
214
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
216
215
|
|
|
217
216
|
await saveSettingsConfig()
|
|
218
217
|
|
|
@@ -223,7 +222,7 @@ describe("configs", () => {
|
|
|
223
222
|
|
|
224
223
|
it("should create settings config with non-default settings", async () => {
|
|
225
224
|
config.modeSelf()
|
|
226
|
-
await config.deleteConfig(
|
|
225
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
227
226
|
const conf = {
|
|
228
227
|
company: "acme",
|
|
229
228
|
logoUrl: "http://example.com",
|
|
@@ -235,14 +234,14 @@ describe("configs", () => {
|
|
|
235
234
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
236
235
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
237
236
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
238
|
-
config.
|
|
237
|
+
config.modeCloud()
|
|
239
238
|
})
|
|
240
239
|
})
|
|
241
240
|
|
|
242
241
|
describe("update", () => {
|
|
243
242
|
it("should update settings config", async () => {
|
|
244
243
|
config.modeSelf()
|
|
245
|
-
await config.deleteConfig(
|
|
244
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
246
245
|
const settingsConfig = await saveSettingsConfig()
|
|
247
246
|
settingsConfig.config.company = "acme"
|
|
248
247
|
settingsConfig.config.logoUrl = "http://example.com"
|
|
@@ -257,7 +256,7 @@ describe("configs", () => {
|
|
|
257
256
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
258
257
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
259
258
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
260
|
-
config.
|
|
259
|
+
config.modeCloud()
|
|
261
260
|
})
|
|
262
261
|
})
|
|
263
262
|
})
|
|
@@ -266,7 +265,7 @@ describe("configs", () => {
|
|
|
266
265
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
|
267
266
|
await config.saveSmtpConfig()
|
|
268
267
|
|
|
269
|
-
const res = await api.configs.getConfigChecklist()
|
|
268
|
+
const res = await config.api.configs.getConfigChecklist()
|
|
270
269
|
const checklist = res.body
|
|
271
270
|
|
|
272
271
|
expect(checklist.apps.checked).toBeFalsy()
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, mocks
|
|
2
|
+
import { TestConfiguration, mocks } from "../../../../tests"
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
4
|
import { EmailTemplatePurpose } from "../../../../constants"
|
|
5
5
|
|
|
6
6
|
describe("/api/global/email", () => {
|
|
7
7
|
const config = new TestConfiguration()
|
|
8
|
-
const api = new API(config)
|
|
9
8
|
|
|
10
9
|
beforeAll(async () => {
|
|
11
10
|
await config.beforeAll()
|
|
@@ -20,7 +19,9 @@ describe("/api/global/email", () => {
|
|
|
20
19
|
await config.saveSmtpConfig()
|
|
21
20
|
await config.saveSettingsConfig()
|
|
22
21
|
|
|
23
|
-
const res = await api.emails.sendEmail(
|
|
22
|
+
const res = await config.api.emails.sendEmail(
|
|
23
|
+
EmailTemplatePurpose.INVITATION
|
|
24
|
+
)
|
|
24
25
|
|
|
25
26
|
expect(res.body.message).toBeDefined()
|
|
26
27
|
expect(sendMailMock).toHaveBeenCalled()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
2
|
+
|
|
3
|
+
// TODO
|
|
4
|
+
|
|
5
|
+
describe("/api/global/license", () => {
|
|
6
|
+
const config = new TestConfiguration()
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await config.beforeAll()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterAll(async () => {
|
|
13
|
+
await config.afterAll()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("POST /api/global/license/activate", () => {
|
|
21
|
+
it("activates license", () => {})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("POST /api/global/license/refresh", () => {})
|
|
25
|
+
|
|
26
|
+
describe("GET /api/global/license/info", () => {})
|
|
27
|
+
|
|
28
|
+
describe("DELETE /api/global/license/info", () => {})
|
|
29
|
+
|
|
30
|
+
describe("GET /api/global/license/usage", () => {})
|
|
31
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TestConfiguration
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
2
2
|
import { EmailTemplatePurpose } from "../../../../constants"
|
|
3
3
|
const nodemailer = require("nodemailer")
|
|
4
4
|
const fetch = require("node-fetch")
|
|
@@ -8,7 +8,6 @@ jest.setTimeout(30000)
|
|
|
8
8
|
|
|
9
9
|
describe("/api/global/email", () => {
|
|
10
10
|
const config = new TestConfiguration()
|
|
11
|
-
const api = new API(config)
|
|
12
11
|
|
|
13
12
|
beforeAll(async () => {
|
|
14
13
|
await config.beforeAll()
|
|
@@ -35,7 +34,7 @@ describe("/api/global/email", () => {
|
|
|
35
34
|
await Promise.race([config.saveEtherealSmtpConfig(), timeout()])
|
|
36
35
|
await Promise.race([config.saveSettingsConfig(), timeout()])
|
|
37
36
|
|
|
38
|
-
const res = await api.emails.sendEmail(purpose).timeout(20000)
|
|
37
|
+
const res = await config.api.emails.sendEmail(purpose).timeout(20000)
|
|
39
38
|
// ethereal hiccup, can't test right now
|
|
40
39
|
if (res.status >= 300) {
|
|
41
40
|
return
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
2
|
+
|
|
3
|
+
// TODO
|
|
4
|
+
|
|
5
|
+
describe("/api/global/roles", () => {
|
|
6
|
+
const config = new TestConfiguration()
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await config.beforeAll()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterAll(async () => {
|
|
13
|
+
await config.afterAll()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("GET /api/global/roles", () => {
|
|
21
|
+
it("retrieves roles", () => {})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("GET /api/global/roles/:appId", () => {})
|
|
25
|
+
|
|
26
|
+
describe("DELETE /api/global/roles/:appId", () => {})
|
|
27
|
+
})
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration,
|
|
2
|
+
import { TestConfiguration, mocks } from "../../../../tests"
|
|
3
3
|
import { events } from "@budibase/backend-core"
|
|
4
4
|
|
|
5
5
|
describe("/api/global/self", () => {
|
|
6
6
|
const config = new TestConfiguration()
|
|
7
|
-
const api = new API(config)
|
|
8
7
|
|
|
9
8
|
beforeAll(async () => {
|
|
10
9
|
await config.beforeAll()
|
|
@@ -24,7 +23,7 @@ describe("/api/global/self", () => {
|
|
|
24
23
|
await config.createSession(user)
|
|
25
24
|
|
|
26
25
|
delete user.password
|
|
27
|
-
const res = await api.self.updateSelf(user)
|
|
26
|
+
const res = await config.api.self.updateSelf(user)
|
|
28
27
|
|
|
29
28
|
const dbUser = await config.getUser(user.email)
|
|
30
29
|
user._rev = dbUser._rev
|
|
@@ -40,7 +39,7 @@ describe("/api/global/self", () => {
|
|
|
40
39
|
await config.createSession(user)
|
|
41
40
|
|
|
42
41
|
user.password = "newPassword"
|
|
43
|
-
const res = await api.self.updateSelf(user)
|
|
42
|
+
const res = await config.api.self.updateSelf(user)
|
|
44
43
|
|
|
45
44
|
const dbUser = await config.getUser(user.email)
|
|
46
45
|
user._rev = dbUser._rev
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
2
|
+
|
|
3
|
+
// TODO
|
|
4
|
+
|
|
5
|
+
describe("/api/global/template", () => {
|
|
6
|
+
const config = new TestConfiguration()
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await config.beforeAll()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterAll(async () => {
|
|
13
|
+
await config.afterAll()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("GET /api/global/template/definitions", () => {
|
|
21
|
+
it("retrieves definitions", () => {})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("POST /api/global/template", () => {})
|
|
25
|
+
|
|
26
|
+
describe("GET /api/global/template", () => {})
|
|
27
|
+
|
|
28
|
+
describe("GET /api/global/template/:type", () => {})
|
|
29
|
+
|
|
30
|
+
describe("GET /api/global/template/:ownerId", () => {})
|
|
31
|
+
|
|
32
|
+
describe("GET /api/global/template/:id", () => {})
|
|
33
|
+
|
|
34
|
+
describe("DELETE /api/global/template/:id/:rev", () => {})
|
|
35
|
+
})
|